source: trunk/anuga_work/development/mem_time_tests/parameters/timelen/main.py

Last change on this file was 8427, checked in by davies, 13 years ago

Adding the trapezoidal channel validation test, and editing the ANUGA manual

File size: 3.1 KB
Line 
1#------------------------------------------------------------------------------
2# Import necessary modules
3#------------------------------------------------------------------------------
4import anuga
5import time
6import subprocess
7import csv
8import os
9from anuga.utilities import system_tools, log
10from anuga.abstract_2d_finite_volumes.util import add_directories
11from anuga.utilities.log_analyser import analyse_log
12
13
14#------------------------------------------------------------------------------
15# Set up variables for the correct directories to store the output
16#------------------------------------------------------------------------------
17home = os.getenv('INUNDATIONHOME')
18scenariodir = add_directories(home, ["data","mem_time_test", "parameters",
19                                     "timelength"])
20meta = 'metalog.csv'
21meta_path = os.path.join(scenariodir, meta)
22final = 'final.csv'
23final_path = os.path.join(scenariodir, final)
24
25#main loop that does the same experiment with different time lengths
26for n in range(1,1000,20):
27    subprocess.call(['python2.5', 'ex1.py', str(n)]) #run script
28print 'Done'
29
30#get the important data for the experiments from the anuga experiments
31analyse_log(scenariodir, os.path.join(scenariodir,'metalog.csv')) 
32
33#open files to read from and write to
34metalog = csv.reader(open(meta_path,'rb'))
35final = csv.writer(open(final_path,'wb'))
36
37#list stores the index of the values requird
38indexlist = []
39
40#read in the first row
41firstrow = metalog.next()
42
43#get the indices of the values we want, so that the data can be condensed
44indexlist.append(firstrow.index("beforetime"))
45indexlist.append(firstrow.index("aftertime"))
46indexlist.append(firstrow.index("aftermeshtime"))
47indexlist.append(firstrow.index("beforesimulationmemory"))
48indexlist.append(firstrow.index("aftermeshmemory"))
49indexlist.append(firstrow.index("afterinitialconditionsmemory"))
50indexlist.append(firstrow.index("afterboundarymemory"))
51indexlist.append(firstrow.index("aftersimulationmemory"))
52indexlist.append(firstrow.index("timelength"))
53indexlist.append(firstrow.index("timestep"))
54
55
56#write the header for the final csv
57final.writerow(["TimeTaken(s)",'MeshTime(s)',
58                firstrow[(indexlist[3])],firstrow[(indexlist[4])],
59                firstrow[(indexlist[5])],firstrow[(indexlist[6])],
60                firstrow[(indexlist[7])],firstrow[(indexlist[8])],
61                firstrow[(indexlist[9])]])
62
63#write the data for each column in the final csv
64for row in metalog:
65
66    #manipulate the beginning and end time to get the time taken
67    begin = time.strptime(row[(indexlist[0])],'%Y%m%d_%H%M%S')
68    end = time.strptime(row[(indexlist[1])],'%Y%m%d_%H%M%S')
69    mesh = time.strptime(row[(indexlist[2])],'%Y%m%d_%H%M%S')
70    taken = time.mktime(end) - time.mktime(begin)
71    meshtime = time.mktime(mesh) - time.mktime(begin)
72
73    #write to file
74    final.writerow([str(taken),str(meshtime),
75                    row[(indexlist[3])],row[(indexlist[4])],
76                    row[(indexlist[5])],row[(indexlist[6])],
77                    row[(indexlist[7])],row[(indexlist[8])],
78                    row[(indexlist[9])]])
Note: See TracBrowser for help on using the repository browser.