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", "triangles", |
---|
17 | "fromregions"]) |
---|
18 | storea ='storea.txt' |
---|
19 | file_path_storea = os.path.join(scenariodir, storea) |
---|
20 | meta = 'metalog.csv' |
---|
21 | meta_path = os.path.join(scenariodir, meta) |
---|
22 | final = 'final.csv' |
---|
23 | final_path = os.path.join(scenariodir, final) |
---|
24 | file = 'ex1.csv' |
---|
25 | file_path = os.path.join(scenariodir, file) |
---|
26 | |
---|
27 | #create and set up the files |
---|
28 | firstex1 = open(file_path, 'wb') |
---|
29 | spamWriter = csv.writer(firstex1) |
---|
30 | spamWriter.writerow(['Number Of Triangles','Maximum Area(m^2)','Extent(m^2)' , 'Time Taken(s)','Space Used']) |
---|
31 | e = open(file_path_storea,'a') |
---|
32 | e.close() |
---|
33 | |
---|
34 | #these are the main loops that determine the maximum triangle area (m) and the map side length(n) |
---|
35 | for m in range(20,1000,50): |
---|
36 | for n in range(1,100000,10000): |
---|
37 | |
---|
38 | z = time.time() #time it |
---|
39 | subprocess.call(['python2.5', 'runcairns.py',str(m),str(n)])#run simulation |
---|
40 | y = time.time() #time it |
---|
41 | |
---|
42 | #read the number of triangles from this text file |
---|
43 | f = open(file_path_storea,'r+') |
---|
44 | h = float(f.readline()) |
---|
45 | f.close() |
---|
46 | |
---|
47 | spamWriter.writerow([h,m,(n*n),'x' ,(y-z)]) #record it |
---|
48 | print 'DONE' |
---|
49 | |
---|
50 | analyse_log(scenariodir, os.path.join(scenariodir,'metalog.csv')) #get the memory usage from the log files |
---|
51 | |
---|
52 | #close ex1.csv so we can read from it for a different csv reader object |
---|
53 | firstex1.close() |
---|
54 | |
---|
55 | #merge the metalog useful memory info and the ex1 recorded info into one csv file named final |
---|
56 | ex1 = csv.reader(open(file_path,'rb')) |
---|
57 | metalog = csv.reader(open(meta_path,'rb')) |
---|
58 | final = csv.writer(open(final_path,'wb')) |
---|
59 | |
---|
60 | |
---|
61 | for row in ex1: |
---|
62 | d = metalog.next() |
---|
63 | final.writerow([row[0],row[1],d[0],d[3],d[6],d[9],d[12]])#,d[15],d[18]]) |
---|