1 | #------------------------------------------------------------------------------ |
---|
2 | # Import necessary modules |
---|
3 | #------------------------------------------------------------------------------ |
---|
4 | import anuga |
---|
5 | import subprocess |
---|
6 | import csv |
---|
7 | import os |
---|
8 | import time |
---|
9 | from anuga.abstract_2d_finite_volumes.util import add_directories |
---|
10 | from anuga.utilities.log_analyser import analyse_log |
---|
11 | |
---|
12 | #------------------------------------------------------------------------------ |
---|
13 | # Set up variables for the correct directories to store the output |
---|
14 | #------------------------------------------------------------------------------ |
---|
15 | home = os.getenv('INUNDATIONHOME') |
---|
16 | scenariodir = add_directories(home, ["data","mem_time_test", "scenarios", |
---|
17 | "velocity"]) |
---|
18 | meta = 'metalog.csv' |
---|
19 | meta_path = os.path.join(scenariodir, meta) |
---|
20 | final = 'final.csv' |
---|
21 | final_path = os.path.join(scenariodir, final) |
---|
22 | |
---|
23 | # these are the main loops that give the velocity of inflow (m) and the map side length(n) |
---|
24 | for m in range(0,250,10): |
---|
25 | for n in range(1,2000,300): |
---|
26 | subprocess.call(['python2.5', 'ex1.py', str(m), str(n)])#run simulation script |
---|
27 | print 'DONE' |
---|
28 | |
---|
29 | #get the important data for the experiments from the anuga experiments |
---|
30 | analyse_log(scenariodir, os.path.join(scenariodir,'metalog.csv')) |
---|
31 | |
---|
32 | #open files to read from and write to |
---|
33 | metalog = csv.reader(open(meta_path,'rb')) |
---|
34 | final = csv.writer(open(final_path,'wb')) |
---|
35 | |
---|
36 | #list stores the index of the values requird |
---|
37 | indexlist = [] |
---|
38 | |
---|
39 | #read in the first row |
---|
40 | firstrow = metalog.next() |
---|
41 | |
---|
42 | #get the indices of the values we want, so that the data can be condensed |
---|
43 | indexlist.append(firstrow.index("beforetime")) |
---|
44 | indexlist.append(firstrow.index("aftertime")) |
---|
45 | indexlist.append(firstrow.index("beforesimulationmemory")) |
---|
46 | indexlist.append(firstrow.index("aftermeshmemory")) |
---|
47 | indexlist.append(firstrow.index("afterinitialconditionsmemory")) |
---|
48 | indexlist.append(firstrow.index("afterboundarymemory")) |
---|
49 | indexlist.append(firstrow.index("aftersimulationmemory")) |
---|
50 | indexlist.append(firstrow.index("variable1")) |
---|
51 | |
---|
52 | #not all experiments have 3 variables, but some do |
---|
53 | try: |
---|
54 | indexlist.append(firstrow.index("variable2")) |
---|
55 | except ValueError: |
---|
56 | indexlist.append(firstrow.index("beforetime")) |
---|
57 | try: |
---|
58 | indexlist.append(firstrow.index("variable3")) |
---|
59 | except ValueError: |
---|
60 | indexlist.append(firstrow.index("aftertime")) |
---|
61 | |
---|
62 | #write the header for the final csv |
---|
63 | final.writerow(["TimeTaken(s)",firstrow[(indexlist[2])], |
---|
64 | firstrow[(indexlist[3])],firstrow[(indexlist[4])], |
---|
65 | firstrow[(indexlist[5])],firstrow[(indexlist[6])], |
---|
66 | firstrow[(indexlist[7])],firstrow[(indexlist[8])], |
---|
67 | firstrow[(indexlist[9])]]) |
---|
68 | |
---|
69 | #write the data for each column in the final csv |
---|
70 | for row in metalog: |
---|
71 | |
---|
72 | #manipulate the beginning and end time to get the time taken |
---|
73 | begin = time.strptime(row[(indexlist[0])],'%Y%m%d_%H%M%S') |
---|
74 | end = time.strptime(row[(indexlist[1])],'%Y%m%d_%H%M%S') |
---|
75 | taken = time.mktime(end) - time.mktime(begin) |
---|
76 | |
---|
77 | #write to file |
---|
78 | final.writerow([str(taken),row[(indexlist[2])], |
---|
79 | row[(indexlist[3])],row[(indexlist[4])], |
---|
80 | row[(indexlist[5])],row[(indexlist[6])], |
---|
81 | row[(indexlist[7])],row[(indexlist[8])], |
---|
82 | row[(indexlist[9])]]) |
---|
83 | |
---|
84 | |
---|