1 | #------------------------------------------------------------------------------ |
---|
2 | # Import necessary modules |
---|
3 | #------------------------------------------------------------------------------ |
---|
4 | import anuga |
---|
5 | import time |
---|
6 | import sys |
---|
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 experiment data and the log file |
---|
12 | length = sys.argv[1] |
---|
13 | lower = sys.argv[2] |
---|
14 | |
---|
15 | home = os.getenv('INUNDATIONHOME') |
---|
16 | scenariodirV = add_directories(home, ["data","mem_time_test", "scenarios", |
---|
17 | "channelflow", "channelflow-" + str(lower) +"-"+ str(length)]) |
---|
18 | log.log_filename = os.path.join(scenariodirV, "anuga.log") |
---|
19 | log._setup = False |
---|
20 | |
---|
21 | log.resource_usage_timing(prefix = 'BeforeSimulation')#get memory usage |
---|
22 | #------------------------------------------------------------------------------ |
---|
23 | # Setup computational domain |
---|
24 | #------------------------------------------------------------------------------ |
---|
25 | points, vertices, boundary = anuga.rectangular_cross(50,150,len1=length, len2=length) # Mesh |
---|
26 | domain = anuga.Domain(points, vertices, boundary) # Create domain |
---|
27 | domain.set_datadir(scenariodirV) |
---|
28 | domain.set_name('channel1.sww') # Output name |
---|
29 | |
---|
30 | log.resource_usage_timing(prefix = 'AfterMesh') #get memory usage |
---|
31 | #-------------------------------------------------------------------------- |
---|
32 | # Setup Initial Conditions |
---|
33 | #-------------------------------------------------------------------------- |
---|
34 | def topography(x, y): |
---|
35 | z = -x/10 |
---|
36 | N = len(x) |
---|
37 | |
---|
38 | #makes a step |
---|
39 | for i in range(N): |
---|
40 | |
---|
41 | if y[i] > lower: |
---|
42 | z[i] += 1 |
---|
43 | |
---|
44 | return z |
---|
45 | |
---|
46 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
47 | domain.set_quantity('friction', 0.01) # Constant friction |
---|
48 | domain.set_quantity('stage', -10000000000000000000000.0) |
---|
49 | |
---|
50 | log.resource_usage_timing(prefix='afterinitialconditions')#get memory usage |
---|
51 | #------------------------------------------------------------------------------ |
---|
52 | # Setup boundary conditions |
---|
53 | #------------------------------------------------------------------------------ |
---|
54 | Bi = anuga.Dirichlet_boundary([0.5, 1, 0]) # Inflow |
---|
55 | Bo = anuga.Dirichlet_boundary([-100,0,0]) |
---|
56 | Br = anuga.Reflective_boundary(domain) # Solid reflective wall |
---|
57 | domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br}) |
---|
58 | |
---|
59 | log.resource_usage_timing(prefix='afterboundary')#get memory usage |
---|
60 | #------------------------------------------------------------------------------ |
---|
61 | # Evolve system through time |
---|
62 | #------------------------------------------------------------------------------ |
---|
63 | for t in domain.evolve(yieldstep=0.2, finaltime=40.0): |
---|
64 | domain.write_time() |
---|
65 | |
---|
66 | log.resource_usage_timing(prefix='aftersimulation') #get memory usage |
---|