Trisurf Monte Carlo simulator
Samo Penic
2016-07-06 250de4d124ea8dc4929a9c334d94fc51018fa53c
commit | author | age
bc14fb 1 #!/usr/bin/python3
7ca5ae 2 import sys, getopt
bc14fb 3 from trisurf import trisurf
9154b3 4 import tabulate
bc14fb 5
7ca5ae 6 # -- configuration of the multiple/single run --
bc14fb 7
bd6993 8 run1=trisurf.Runner(snapshot='snapshot.vtu')
c14bd6 9 run1.setMaindir(("N","k","V","Np","Nm"),("nshell","xk0","constvolswitch","npoly","nmono"))
7c45b1 10 run1.setSubdir("run0")
7ca5ae 11
b122c4 12 run2=trisurf.Runner(tape='tape', runArgs=['--force-from-tape'])
7ca5ae 13 run2.setMaindir(("N","k","V","Np","Nm"),("nshell","xk0","constvolswitch","npoly","nmono"))
SP 14 run2.setSubdir("run1")
15
16
17 #obligatory: combine all runs
9154b3 18 Runs=[run1,run2]
SP 19
20
21
22 #------------------ NO NEED TO TOUCH THE CODE BELOW ------------------------------
7ca5ae 23
SP 24 # -- reading command line switches and acting accordingly --
9154b3 25 argv=sys.argv[1:]
SP 26 processno=0
7ca5ae 27 try:
055489 28     opts, args = getopt.getopt(argv,"a:n:hrsc:")
7ca5ae 29 except getopt.GetoptError:
d16eea 30     print('tsmgr [-n process number] [-h] [-r] [-s] [-c comment text] [-a comment text]')
7ca5ae 31     sys.exit(2)
SP 32 for opt, arg in opts:
33     if opt == '-h':
d16eea 34         print ('tsmgr [-n process number] [-h] [-r] [-s] [-c comment text] [-a comment text]')
7ca5ae 35         sys.exit()
SP 36     elif opt == '-r':
9154b3 37         if processno:
SP 38             localRuns=[Runs[processno-1]]
39         else:
40             localRuns=Runs
41         for run in localRuns:
7ca5ae 42             run.start()
SP 43     elif opt == '-s':
9154b3 44         report=[]
SP 45         i=1
46         if processno:
47             localRuns=[Runs[processno-1]]
48         else:
49             localRuns=Runs
50         for run in localRuns:
51             line=run.getStatistics()
52             line.insert(0,i)
53             report.append(line)
54             i=i+1
55             #print(reportstr)
56         print ("\n\nTrisurf running processes report\n")
57         print (tabulate.tabulate(report,headers=["Run no.", "Run start time", "ETA", "Status", "PID", "Path", "Comment"], tablefmt='fancy_grid'))
58     elif opt == '-n':
59         processno=int(arg)
60         if processno<1 or processno>len(Runs) :
61             processno=0
62     elif opt == '-c':
63         comment = arg
64         if processno:
65             Runs[processno-1].writeComment(arg)
055489 66     elif opt == '-a':
SP 67         comment = arg
68         if processno:
69             Runs[processno-1].writeComment("\n"+arg, 'a')
9154b3 70
SP 71         
7ca5ae 72     else:
d16eea 73         print('tsmgr [-n process number] [-h] [-r] [-s] [-c comment text] [-a comment text]')
7ca5ae 74         sys.exit(2)
SP 75
76
77
78
79
80
81
82
83
84 # -- OBSOLETE and TESTING --
85
86
87
88
89
90 #    elif opt in ("-i", "--ifile"):
91 #        inputfile = arg
92 #    elif opt in ("-o", "--ofile"):
93 #        outputfile = arg
94 #    print ('Input file is "', inputfile)
95 #    print ('Output file is "', outputfile)
96
97
98
99 #run1.start()
c14bd6 100 #run
7ca5ae 101 #print(run1)
SP 102 #run1.getStatistics()
103 #print(run1.statistics)
c14bd6 104 #print(run1.tape)
SP 105 #print(run1.tape.getValue('nshell'))