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 for the simulation output and the log files |
---|
12 | k= sys.argv[1] |
---|
13 | l= float(sys.argv[2]) |
---|
14 | |
---|
15 | home = os.getenv('INUNDATIONHOME') |
---|
16 | scenariodirV = add_directories(home, ["data","mem_time_test", "scenarios", |
---|
17 | "velocity", "velocity-" + str(k) +"-"+ str(l)]) |
---|
18 | |
---|
19 | log.timingInfo(msg=('velocity,'+str(k))) #write the variable to be measured to file |
---|
20 | log.timingInfo(msg=('extent,'+str(l**2))) #write the variable to be measured to file |
---|
21 | log.timingInfo(msg=('beforetime,'+str(log.TimeStamp()))) #get the time at the beginning of the simulation |
---|
22 | |
---|
23 | log.log_filename = os.path.join(scenariodirV, "anuga.log") |
---|
24 | log._setup = False |
---|
25 | |
---|
26 | log.resource_usage_timing(prefix = 'beforesimulation') #get memory usage |
---|
27 | #------------------------------------------------------------------------------ |
---|
28 | # Setup computational domain |
---|
29 | #------------------------------------------------------------------------------ |
---|
30 | points, vertices, boundary = anuga.rectangular_cross(100,300, len1=1000, len2=500) # Mesh |
---|
31 | domain = anuga.Domain(points, vertices, boundary) # Create domain |
---|
32 | domain.set_name('channel1') # Output name |
---|
33 | domain.set_datadir(scenariodirV) |
---|
34 | |
---|
35 | log.resource_usage_timing(prefix = 'aftermesh') #get memory usage |
---|
36 | log.timingInfo(msg=('aftermeshtime,'+str(log.TimeStamp()))) #get the time at the beginning of the simulation |
---|
37 | |
---|
38 | #get the number of triangles |
---|
39 | number = len(domain) |
---|
40 | log.timingInfo(msg=('numberoftriangles'+str(number))) #write the variable to be measured to file |
---|
41 | |
---|
42 | #-------------------------------------------------------------------------- |
---|
43 | # Setup initial conditions |
---|
44 | #-------------------------------------------------------------------------- |
---|
45 | def topography(x, y): |
---|
46 | return 0.0 |
---|
47 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
48 | domain.set_quantity('friction', 0.01) # Constant friction |
---|
49 | domain.set_quantity('stage', -1000.0) |
---|
50 | |
---|
51 | log.resource_usage_timing(prefix='afterinitialconditions')#get memory usage |
---|
52 | |
---|
53 | #------------------------------------------------------------------------------ |
---|
54 | # Setup boundary conditions |
---|
55 | #------------------------------------------------------------------------------ |
---|
56 | Bi = anuga.Dirichlet_boundary([0.5, k, 0]) # Inflow |
---|
57 | Br = anuga.Reflective_boundary(domain) # Solid reflective wall |
---|
58 | Bo = anuga.Dirichlet_boundary([-0.5, 0, 0]) # Outflow |
---|
59 | domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br}) |
---|
60 | |
---|
61 | log.resource_usage_timing(prefix='afterboundary')#get memory usage |
---|
62 | |
---|
63 | #------------------------------------------------------------------------------ |
---|
64 | # Evolve system through time |
---|
65 | #------------------------------------------------------------------------------ |
---|
66 | for t in domain.evolve(yieldstep=0.2, finaltime=40.0): |
---|
67 | domain.write_time() |
---|
68 | |
---|
69 | log.resource_usage_timing(prefix='aftersimulation') #get memory usage |
---|
70 | log.timingInfo(msg=('aftertime,'+str(log.TimeStamp()))) #get the time at the end of the simulation |
---|