1 | #------------------------------------------------------------------------------ |
---|
2 | # Import necessary modules |
---|
3 | #------------------------------------------------------------------------------ |
---|
4 | import anuga |
---|
5 | import time |
---|
6 | import random |
---|
7 | import os |
---|
8 | from anuga.abstract_2d_finite_volumes.util import add_directories |
---|
9 | from anuga.utilities import log |
---|
10 | |
---|
11 | #set up variables to store the temporary data |
---|
12 | home = os.getenv('INUNDATIONHOME') |
---|
13 | scenariodir = add_directories(home, ["data","mem_time_test", "parameters", |
---|
14 | "timelen-over-timestep"]) |
---|
15 | store ='store.txt' |
---|
16 | file_path_store = os.path.join(scenariodir, store) |
---|
17 | storen ='storen.txt' |
---|
18 | file_path_storen = os.path.join(scenariodir, storen) |
---|
19 | |
---|
20 | #get the time length and time step from the text files |
---|
21 | f = open(file_path_store,'r+') |
---|
22 | g = float(f.readline()) |
---|
23 | f.close() |
---|
24 | f = open(file_path_storen,'r+') |
---|
25 | h = float(f.readline()) |
---|
26 | f.close() |
---|
27 | |
---|
28 | #set up variables to store the data and the log files |
---|
29 | scenariodirV = add_directories(home, ["data","mem_time_test", "parameters", |
---|
30 | "timelen-over-timestep", "TT-" + str(g) +"-"+ str(h)]) |
---|
31 | log.log_filename = os.path.join(scenariodirV, "anuga.log") |
---|
32 | log._setup = False |
---|
33 | |
---|
34 | |
---|
35 | log.resource_usage_timing(prefix = 'BeforeSimulation') #get memory usage here |
---|
36 | |
---|
37 | #------------------------------------------------------------------------------ |
---|
38 | #Create Domain and Mesh |
---|
39 | #------------------------------------------------------------------------------ |
---|
40 | points, vertices, boundary = anuga.rectangular_cross(100,300,len1=1000.0, len2=500.0) # Mesh |
---|
41 | domain = anuga.Domain(points, vertices, boundary) # Create domain |
---|
42 | domain.set_name('channel1') # Output name |
---|
43 | domain.set_datadir(scenariodirV) |
---|
44 | |
---|
45 | log.resource_usage_timing(prefix = 'AfterMesh') #get memory usage here |
---|
46 | |
---|
47 | #------------------------------------------------------------------------------ |
---|
48 | # Setup initial conditions |
---|
49 | #------------------------------------------------------------------------------ |
---|
50 | def topography(x, y): |
---|
51 | return -x/10 # linear bed slope |
---|
52 | |
---|
53 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
54 | domain.set_quantity('friction', 0.01) # Constant friction |
---|
55 | domain.set_quantity('stage', expression='elevation') |
---|
56 | log.resource_usage_timing(prefix='afterinitialconditions') #get memory usage here |
---|
57 | |
---|
58 | #------------------------------------------------------------------------------ |
---|
59 | # Setup boundary conditions |
---|
60 | #------------------------------------------------------------------------------ |
---|
61 | Bi = anuga.Dirichlet_boundary([0.4, 0, 0]) # Inflow |
---|
62 | Br = anuga.Reflective_boundary(domain) # Solid reflective wall |
---|
63 | domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
64 | log.resource_usage_timing(prefix='afterboundary') #get memory usage here |
---|
65 | #------------------------------------------------------------------------------ |
---|
66 | # Evolve system through time |
---|
67 | #------------------------------------------------------------------------------ |
---|
68 | for t in domain.evolve(yieldstep=h, finaltime=g): |
---|
69 | print domain.timestepping_statistics() |
---|
70 | |
---|
71 | log.resource_usage_timing(prefix='aftersimulation') #get memory usage here |
---|