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.timingInfo(msg=('length,'+str(length))) #write the variable to be measured to file |
---|
22 | log.timingInfo(msg=('stepplace,'+str(lower))) #write the variable to be measured to file |
---|
23 | log.timingInfo(msg=('beforetime,'+str(log.TimeStamp()))) #get the time at the beginning of the simulation |
---|
24 | |
---|
25 | log.resource_usage_timing(prefix = 'beforesimulation')#get memory usage |
---|
26 | #------------------------------------------------------------------------------ |
---|
27 | # Setup computational domain |
---|
28 | #------------------------------------------------------------------------------ |
---|
29 | points, vertices, boundary = anuga.rectangular_cross(100,300,len1=length, len2=length) # Mesh |
---|
30 | domain = anuga.Domain(points, vertices, boundary) # Create domain |
---|
31 | domain.set_datadir(scenariodirV) |
---|
32 | domain.set_name('channel1.sww') # Output name |
---|
33 | |
---|
34 | log.timingInfo(msg=('aftermeshtime,'+str(log.TimeStamp()))) #get the time at the beginning of the simulation |
---|
35 | log.resource_usage_timing(prefix = 'aftermesh') #get memory usage |
---|
36 | #-------------------------------------------------------------------------- |
---|
37 | # Setup Initial Conditions |
---|
38 | #-------------------------------------------------------------------------- |
---|
39 | def topography(x, y): |
---|
40 | z = 0 |
---|
41 | N = len(x) |
---|
42 | |
---|
43 | #makes a step |
---|
44 | for i in range(N): |
---|
45 | |
---|
46 | if y[i] > lower: |
---|
47 | z[i] += 1 |
---|
48 | |
---|
49 | return z |
---|
50 | |
---|
51 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
52 | domain.set_quantity('friction', 0.01) # Constant friction |
---|
53 | domain.set_quantity('stage', -10000000000000000000000.0) |
---|
54 | |
---|
55 | log.resource_usage_timing(prefix='afterinitialconditions')#get memory usage |
---|
56 | #------------------------------------------------------------------------------ |
---|
57 | # Setup boundary conditions |
---|
58 | #------------------------------------------------------------------------------ |
---|
59 | Bi = anuga.Dirichlet_boundary([0.5, 10, 0]) # Inflow |
---|
60 | Bo = anuga.Dirichlet_boundary([-0.5,0,0]) #outflow |
---|
61 | Br = anuga.Reflective_boundary(domain) # Solid reflective wall |
---|
62 | domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br}) |
---|
63 | |
---|
64 | log.resource_usage_timing(prefix='afterboundary')#get memory usage |
---|
65 | #------------------------------------------------------------------------------ |
---|
66 | # Evolve system through time |
---|
67 | #------------------------------------------------------------------------------ |
---|
68 | for t in domain.evolve(yieldstep=120, finaltime=3600): |
---|
69 | domain.write_time() |
---|
70 | |
---|
71 | log.resource_usage_timing(prefix='aftersimulation') #get memory usage |
---|
72 | log.timingInfo(msg=('aftertime,'+str(log.TimeStamp()))) #get the time at the end of the simulation |
---|