- Timestamp:
- Jan 31, 2012, 10:54:12 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_work/development/mem_time_tests/scenarios/vel2/ex1.py
r8304 r8326 1 """Simple water flow example using ANUGA2 Water flowing down a channel3 """4 1 #------------------------------------------------------------------------------ 5 2 # Import necessary modules 6 3 #------------------------------------------------------------------------------ 7 # Import standard shallow water domain and standard boundaries.8 4 import anuga 9 5 import time … … 11 7 import os 12 8 from anuga.abstract_2d_finite_volumes.util import add_directories 9 from anuga.utilities import log 13 10 11 # set up the variables for the temporary files 14 12 home = os.getenv('INUNDATIONHOME') 15 scenariodir = add_directories(home, ["data","mem_time_test", "triangles", 16 "serial"]) 13 scenariodir = add_directories(home, ["data","mem_time_test", "scenarios", 14 "velocity"]) 15 store ='store.txt' 16 file_path_store = os.path.join(scenariodir, store) 17 storen = 'storen.txt' 18 file_path_storen = os.path.join(scenariodir, storen) 19 storea = 'storea.txt' 20 file_path_storea = os.path.join(scenariodir, storea) 17 21 22 # read the velocity and the map side length from the text files 23 f = open(file_path_store,'r+') 24 k = float(f.readline()) 25 f.close() 26 f = open(file_path_storen,'r+') 27 l = float(f.readline()) 28 f.close() 29 30 #set up variables for the simulation output and the log files 31 scenariodirV = add_directories(home, ["data","mem_time_test", "scenarios", 32 "velocity", "velocity-" + str(k) +"-"+ str(l)]) 33 log.log_filename = os.path.join(scenariodirV, "anuga.log") 34 log._setup = False 35 36 log.resource_usage_timing(prefix = 'BeforeSimulation') #get memory usage 18 37 #------------------------------------------------------------------------------ 19 38 # Setup computational domain 20 39 #------------------------------------------------------------------------------ 21 def runex(k,l): 40 points, vertices, boundary = anuga.rectangular_cross(100,300, len1=1000, len2=500) # Mesh 41 domain = anuga.Domain(points, vertices, boundary) # Create domain 42 domain.set_name('channel1') # Output name 43 domain.set_datadir(scenariodirV) 22 44 23 points, vertices, boundary = anuga.rectangular_cross(100,100, 24 len1=l, len2=l) # Mesh 45 log.resource_usage_timing(prefix = 'AfterMesh') #get memory usage 46 47 #get the number of triangles 48 number = len(domain) 25 49 26 50 #-------------------------------------------------------------------------- 27 # Setup Domain only on processor 051 # Setup initial conditions 28 52 #-------------------------------------------------------------------------- 29 domain = anuga.Domain(points, vertices, boundary) # Create domain 30 domain.set_name('channel1') # Output name31 domain.set_datadir(scenariodir) 32 33 number = len(domain)53 def topography(x, y): 54 return 0.0 55 domain.set_quantity('elevation', topography) # Use function for elevation 56 domain.set_quantity('friction', 0.01) # Constant friction 57 domain.set_quantity('stage', -1000.0) 34 58 35 def topography(x, y): 36 return 0.0 37 38 domain.set_quantity('elevation', topography) # Use function for elevation 39 domain.set_quantity('friction', 0.01) # Constant friction 40 domain.set_quantity('stage', -1000.0) 59 log.resource_usage_timing(prefix='afterinitialconditions')#get memory usage 41 60 42 61 #------------------------------------------------------------------------------ 43 62 # Setup boundary conditions 44 63 #------------------------------------------------------------------------------ 45 Bi = anuga.Dirichlet_boundary([0.5, k, 0]) # Inflow 46 Br = anuga.Reflective_boundary(domain) # Solid reflective wall 47 Bo = anuga.Dirichlet_boundary([-0.5, 0, 0]) # Outflow 48 domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br}) 64 Bi = anuga.Dirichlet_boundary([0.5, k, 0]) # Inflow 65 Br = anuga.Reflective_boundary(domain) # Solid reflective wall 66 Bo = anuga.Dirichlet_boundary([-0.5, 0, 0]) # Outflow 67 domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br}) 68 69 log.resource_usage_timing(prefix='afterboundary')#get memory usage 49 70 50 71 #------------------------------------------------------------------------------ 51 72 # Evolve system through time 52 73 #------------------------------------------------------------------------------ 53 54 74 for t in domain.evolve(yieldstep=0.2, finaltime=40.0): 75 domain.write_time() 55 76 56 return number 77 log.resource_usage_timing(prefix='aftersimulation') #get memory usage 57 78 79 #write the number of triangles to the file 80 c = open(file_path_storea,'r+') 81 c.write(str(number))
Note: See TracChangeset
for help on using the changeset viewer.