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