1 | #------------------------------------------------------------------------------ |
---|
2 | # Import necessary modules |
---|
3 | #------------------------------------------------------------------------------ |
---|
4 | import os |
---|
5 | import time |
---|
6 | import sys |
---|
7 | import anuga |
---|
8 | from anuga_parallel import distribute, myid, numprocs |
---|
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 output data and the log files |
---|
13 | length = float(sys.argv[2]) |
---|
14 | area = sys.argv[1] |
---|
15 | |
---|
16 | scenariodirV = add_directories(home, ["data","mem_time_test", "triangles", |
---|
17 | "area", "triangles-" + str(area) +"-"+ str(length)]) |
---|
18 | h = 'CAIRNS.msh' |
---|
19 | file_pathh = os.path.join(scenariodirV, h) |
---|
20 | log.log_filename = os.path.join(scenariodirV, "anuga.log") |
---|
21 | log._setup = False |
---|
22 | |
---|
23 | log.timingInfo(msg=('extent,'+str(length**2))) #write the variable to be measured to file |
---|
24 | log.timingInfo(msg=('trianglearea,'+str(area))) #write the variable to be measured to file |
---|
25 | log.timingInfo(msg=('myid,'+str(myid))) #write the variable to be measured to file |
---|
26 | log.timingInfo(msg=('numberofcpus,'+str(numprocs))) #write the variable to be measured to file |
---|
27 | log.timingInfo(msg=('beforetime,'+str(log.TimeStamp()))) #get the time at the beginning of the simulation |
---|
28 | |
---|
29 | log.resource_usage_timing(prefix = 'beforesimulation') #get memory usage |
---|
30 | #------------------------------------------------------------------------------ |
---|
31 | # Create the triangular mesh and domain on one processor |
---|
32 | #------------------------------------------------------------------------------ |
---|
33 | if myid == 0: |
---|
34 | domain = anuga.create_domain_from_regions([(0.0,0.0),(length,length),(0.0,length),(length,0.0)], |
---|
35 | boundary_tags={'top': [0], |
---|
36 | 'right': [1], |
---|
37 | 'bottom': [2], |
---|
38 | 'left': [3]}, |
---|
39 | maximum_triangle_area=area, |
---|
40 | mesh_filename=file_pathh |
---|
41 | ) |
---|
42 | #get the number of triangles |
---|
43 | n = len(domain) |
---|
44 | |
---|
45 | else: |
---|
46 | domain = None |
---|
47 | log.timingInfo(msg=('numberoftriangles,'+str(n))) #write the variable to be measured to file |
---|
48 | log.timingInfo(msg=('aftermeshtime,'+str(log.TimeStamp()))) #get the time at the beginning of the simulation |
---|
49 | |
---|
50 | #parallel |
---|
51 | domain = distribute(domain) |
---|
52 | |
---|
53 | domain.set_name('CAIRNS.sww') # Name of sww file |
---|
54 | domain.set_datadir(scenariodirV)# Store sww output here |
---|
55 | |
---|
56 | log.resource_usage_timing(prefix = 'aftermesh') #get memory usage |
---|
57 | #------------------------------------------------------------------------------ |
---|
58 | # Setup initial conditions |
---|
59 | #------------------------------------------------------------------------------ |
---|
60 | |
---|
61 | def topography(x,y): |
---|
62 | return 0.0 |
---|
63 | |
---|
64 | tide = 100.0 |
---|
65 | friction = 0.0 |
---|
66 | domain.set_quantity('stage', tide) |
---|
67 | domain.set_quantity('friction', friction) |
---|
68 | domain.set_quantity('elevation',topography,alpha=0.1) |
---|
69 | |
---|
70 | log.resource_usage_timing(prefix='afterinitialconditions')#get memory usage |
---|
71 | |
---|
72 | #------------------------------------------------------------------------------ |
---|
73 | # Setup boundary conditions |
---|
74 | #------------------------------------------------------------------------------ |
---|
75 | |
---|
76 | Bi = anuga.Dirichlet_boundary([tide, 223.52, 0]) # inflow |
---|
77 | Bo = anuga.Dirichlet_boundary([-tide, 223.52, 0]) # outflow |
---|
78 | Br = anuga.Reflective_boundary(domain) |
---|
79 | domain.set_boundary({'right': Bo,'bottom': Br,'left': Bi,'top': Br}) |
---|
80 | |
---|
81 | log.resource_usage_timing(prefix='afterboundary')#get memory usage |
---|
82 | #------------------------------------------------------------------------------ |
---|
83 | # Evolve system through time |
---|
84 | #------------------------------------------------------------------------------ |
---|
85 | for t in domain.evolve(yieldstep=120, finaltime=2000): |
---|
86 | print domain.timestepping_statistics() |
---|
87 | |
---|
88 | log.resource_usage_timing(prefix='aftersimulation') #get memory usage |
---|
89 | log.timingInfo(msg=('aftertime,'+str(log.TimeStamp()))) #get the time at the end of the simulation |
---|
90 | |
---|