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