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 | file = 'ex1.csv' |
---|
19 | file_path = os.path.join(scenariodir, file) |
---|
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 | store = 'store.txt' |
---|
25 | store_path = os.path.join(scenariodir, store) |
---|
26 | |
---|
27 | #set up needed files |
---|
28 | firstex1 = open(file_path, 'wb') |
---|
29 | spamWriter = csv.writer(firstex1) |
---|
30 | spamWriter.writerow(['Velocity(m/s)','Number Of Triangles','Extent(m^2)' , 'Time Taken(s)','Space Used']) |
---|
31 | storeopen = open(store_path,'a') |
---|
32 | storeopen.close |
---|
33 | |
---|
34 | # these are the main loops that give the velocity of inflow (m) and the map side length(n) |
---|
35 | for m in range(0,250,10): |
---|
36 | for n in range(1,2000,300): |
---|
37 | |
---|
38 | z = time.time() #time it |
---|
39 | subprocess.call(['python2.5', 'ex1.py', str(m), str(n)])#run simulation script |
---|
40 | y = time.time() #time it |
---|
41 | |
---|
42 | # read the number of triangles from this text file |
---|
43 | f = open(store_path,'r+') |
---|
44 | h = float(f.readline()) |
---|
45 | f.close() |
---|
46 | |
---|
47 | spamWriter.writerow([m,h,(n*n),(y-z), 'b'])# 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]]) |
---|