def run_simulation(parallel=False): domain = create_domain_from_file(mesh_filename) domain.set_quantity('stage', Set_Stage(756000.0, 756500.0, 2.0)) #-------------------------------------------------------------------------- # Create parallel domain if requested #-------------------------------------------------------------------------- if parallel: if myid == 0 and verbose: print 'DISTRIBUTING PARALLEL DOMAIN' domain = distribute(domain) #------------------------------------------------------------------------------ # Setup boundary conditions # This must currently happen *after* domain has been distributed #------------------------------------------------------------------------------ domain.store = False Br = Reflective_boundary(domain) # Solid reflective wall domain.set_boundary({'outflow' :Br, 'inflow' :Br, 'inner' :Br, 'exterior' :Br, 'open' :Br}) #------------------------------------------------------------------------------ # Evolution #------------------------------------------------------------------------------ if parallel: if myid == 0 and verbose: print 'PARALLEL EVOLVE' else: if verbose: print 'SEQUENTIAL EVOLVE' for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): pass
def create_domain(self, InitialOceanStage, InitialLandStage, flowAlg, verbose): """ Make the domain and set the flow algorithm for a test. Produces an sww that we can use for testing """ boundaryPolygon = [[0., 0.], [0., 100.], [100.0, 100.0], [100.0, 0.0]] anuga.create_mesh_from_regions(boundaryPolygon, boundary_tags={ 'left': [0], 'top': [1], 'right': [2], 'bottom': [3] }, maximum_triangle_area=20., minimum_triangle_angle=28.0, filename='test_plot_utils.msh', interior_regions=[], verbose=False) domain = anuga.create_domain_from_file('test_plot_utils.msh') os.remove('test_plot_utils.msh') # 05/05/2014 -- riverwalls only work with DE0 and DE1 domain.set_flow_algorithm(flowAlg) domain.set_name('test_plot_utils') domain.set_store_vertices_uniquely() def topography(x, y): return -x / 150. def stagefun(x, y): stg = InitialOceanStage * (x >= 50.) + InitialLandStage * (x < 50.) return stg domain.set_flow_algorithm(flowAlg) #domain.set_quantity('elevation',topography,location='centroids') domain.set_quantity('elevation', topography) domain.set_quantity('friction', 0.03) #domain.set_quantity('stage', stagefun,location='centroids') domain.set_quantity('stage', stagefun) if (verbose): if (domain.store_centroids): print ' Centroids stored' else: print ' Centroids estimated from vertices' # Boundary conditions Br = anuga.Reflective_boundary(domain) domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br}) for t in domain.evolve(yieldstep=0.2, finaltime=1.0): pass return
def create_domain_DE1(self, wallHeight, InitialOceanStage, InitialLandStage): # Riverwall = list of lists, each with a set of x,y,z (and optional QFactor) values riverWall = { 'centralWall': [[wallLoc, 0.0, wallHeight], [wallLoc, 100.0, wallHeight]] } riverWall_Par = {'centralWall': {'Qfactor': 1.0}} # Make the domain anuga.create_mesh_from_regions( boundaryPolygon, boundary_tags={ 'left': [0], 'top': [1], 'right': [2], 'bottom': [3] }, maximum_triangle_area=200., minimum_triangle_angle=28.0, filename='testRiverwall.msh', interior_regions=[], #[ [higherResPolygon, 1.*1.*0.5], # [midResPolygon, 3.0*3.0*0.5]], breaklines=list(riverWall.values()), use_cache=False, verbose=verbose, regionPtArea=regionPtAreas) domain = anuga.create_domain_from_file('testRiverwall.msh') # 05/05/2014 -- riverwalls only work with DE0 and DE1 domain.set_flow_algorithm('DE1') domain.set_name('test_riverwall') domain.set_store_vertices_uniquely() def topography(x, y): return -x / 150. def stagefun(x, y): stg = InitialOceanStage * (x >= 50.) + InitialLandStage * (x < 50.) return stg # NOTE: Setting quantities at centroids is important for exactness of tests domain.set_quantity('elevation', topography, location='centroids') domain.set_quantity('friction', 0.03) domain.set_quantity('stage', stagefun, location='centroids') domain.riverwallData.create_riverwalls(riverWall, riverWall_Par, verbose=verbose) # Boundary conditions Br = anuga.Reflective_boundary(domain) domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br}) return domain
def create_domain(self, InitialOceanStage, InitialLandStage, flowAlg, verbose): """ Make the domain and set the flow algorithm for a test. Produces an sww that we can use for testing """ boundaryPolygon=[ [0., 0.], [0., 100.], [100.0, 100.0], [100.0, 0.0]] anuga.create_mesh_from_regions(boundaryPolygon, boundary_tags={'left': [0], 'top': [1], 'right': [2], 'bottom': [3]}, maximum_triangle_area = 20., minimum_triangle_angle = 28.0, filename = 'test_plot_utils.msh', interior_regions =[ ], verbose=False) domain=anuga.create_domain_from_file('test_plot_utils.msh') os.remove('test_plot_utils.msh') # 05/05/2014 -- riverwalls only work with DE0 and DE1 domain.set_flow_algorithm(flowAlg) domain.set_name('test_plot_utils') domain.set_store_vertices_uniquely() def topography(x,y): return -x/150. def stagefun(x,y): stg=InitialOceanStage*(x>=50.) + InitialLandStage*(x<50.) return stg domain.set_flow_algorithm(flowAlg) #domain.set_quantity('elevation',topography,location='centroids') domain.set_quantity('elevation',topography) domain.set_quantity('friction',0.03) #domain.set_quantity('stage', stagefun,location='centroids') domain.set_quantity('stage', stagefun) if(verbose): if(domain.store_centroids): print ' Centroids stored' else: print ' Centroids estimated from vertices' # Boundary conditions Br=anuga.Reflective_boundary(domain) domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom':Br}) for t in domain.evolve(yieldstep=0.2,finaltime=1.0): pass return
def build_mesh(project): """ This is executed by processor 0 to build the mesh. """ # Ensure mesh_breaklines include riverwalls and breaklines mesh_breaklines = \ su.combine_breakLines_and_riverWalls_for_mesh(project.breaklines, project.riverwalls) # Make the mesh anuga.create_mesh_from_regions( project.bounding_polygon, boundary_tags=project.boundary_tags, maximum_triangle_area=project.default_res, filename=project.meshname, interior_regions=project.interior_regions, use_cache=False, verbose=verbose, breaklines=mesh_breaklines, regionPtArea=project.region_point_areas, ) # Make the domain using the mesh domain = anuga.create_domain_from_file(project.meshname) # Print some stats about mesh and domain print 'Number of triangles = ', len(domain) print 'The extent is ', domain.get_extent() print domain.statistics() # Print info on the smallest triangles small_areas = domain.areas.argsort() print '' print 'LOCATIONS OF TRIANGLES WITH SMALLEST AREAS' for i in range(10): j = small_areas[i] x = domain.centroid_coordinates[j, 0] \ + domain.geo_reference.xllcorner y = domain.centroid_coordinates[j, 1] \ + domain.geo_reference.yllcorner print ' Area ' + str(domain.areas[j]) + ' location: ' \ + str(round(x, 1)) + ',' + str(round(y, 1)) print '' return domain
def create_domain_DE0(self, wallHeight, InitialOceanStage, InitialLandStage, riverWall=None, riverWall_Par=None): # Riverwall = list of lists, each with a set of x,y,z (and optional QFactor) values if(riverWall is None): riverWall={ 'centralWall': [ [wallLoc, 0.0, wallHeight], [wallLoc, 100.0, wallHeight]] } if(riverWall_Par is None): riverWall_Par={'centralWall':{'Qfactor':1.0}} # Make the domain anuga.create_mesh_from_regions(boundaryPolygon, boundary_tags={'left': [0], 'top': [1], 'right': [2], 'bottom': [3]}, maximum_triangle_area = 200., minimum_triangle_angle = 28.0, filename = 'testRiverwall.msh', interior_regions =[ ], #[ [higherResPolygon, 1.*1.*0.5], # [midResPolygon, 3.0*3.0*0.5]], breaklines=riverWall.values(), use_cache=False, verbose=verbose, regionPtArea=regionPtAreas) domain=anuga.create_domain_from_file('testRiverwall.msh') # 05/05/2014 -- riverwalls only work with DE0 and DE1 domain.set_flow_algorithm('DE0') domain.set_name('test_riverwall') domain.set_store_vertices_uniquely() def topography(x,y): return -x/150. def stagefun(x,y): stg=InitialOceanStage*(x>=50.) + InitialLandStage*(x<50.) return stg # NOTE: Setting quantities at centroids is important for exactness of tests domain.set_quantity('elevation',topography,location='centroids') domain.set_quantity('friction',0.03) domain.set_quantity('stage', stagefun,location='centroids') domain.riverwallData.create_riverwalls(riverWall,riverWall_Par,verbose=verbose) # Boundary conditions Br=anuga.Reflective_boundary(domain) domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom':Br}) return domain
def build_mesh(project): """ This is executed by processor 0 to build the mesh. """ # Ensure mesh_breaklines include riverwalls and breaklines mesh_breaklines = su.combine_breakLines_and_riverWalls_for_mesh(project.breaklines, project.riverwalls) # Make the mesh anuga.create_mesh_from_regions( project.bounding_polygon, boundary_tags=project.boundary_tags, maximum_triangle_area=project.default_res, filename=project.meshname, interior_regions=project.interior_regions, use_cache=False, verbose=verbose, breaklines=mesh_breaklines, regionPtArea=project.region_point_areas, ) # Make the domain using the mesh domain = anuga.create_domain_from_file(project.meshname) # Print some stats about mesh and domain print "Number of triangles = ", len(domain) print "The extent is ", domain.get_extent() print domain.statistics() # Print info on the smallest triangles small_areas = domain.areas.argsort() print "" print "LOCATIONS OF TRIANGLES WITH SMALLEST AREAS" for i in range(10): j = small_areas[i] x = domain.centroid_coordinates[j, 0] + domain.geo_reference.xllcorner y = domain.centroid_coordinates[j, 1] + domain.geo_reference.yllcorner print " Area " + str(domain.areas[j]) + " location: " + str(round(x, 1)) + "," + str(round(y, 1)) print "" return domain
def run_simulation(parallel=False): domain = create_domain_from_file(mesh_filename) domain.set_quantity('stage', Set_Stage(756000.0, 756500.0, 2.0)) #-------------------------------------------------------------------------- # Create parallel domain if requested #-------------------------------------------------------------------------- if parallel: if myid == 0 and verbose: print('DISTRIBUTING PARALLEL DOMAIN') domain = distribute(domain) #------------------------------------------------------------------------------ # Setup boundary conditions # This must currently happen *after* domain has been distributed #------------------------------------------------------------------------------ domain.store = False Br = Reflective_boundary(domain) # Solid reflective wall domain.set_boundary({ 'outflow': Br, 'inflow': Br, 'inner': Br, 'exterior': Br, 'open': Br }) #------------------------------------------------------------------------------ # Evolution #------------------------------------------------------------------------------ if parallel: if myid == 0 and verbose: print('PARALLEL EVOLVE') else: if verbose: print('SEQUENTIAL EVOLVE') for t in domain.evolve(yieldstep=yieldstep, finaltime=finaltime): pass
def time_evolve(self): import anuga mesh_filename = "benchmarks/merimbula_10785_1.tsh" x0 = 756000.0 ; x1 = 756500.0; yieldstep = 10.0; finaltime = 50.0 domain = anuga.create_domain_from_file(mesh_filename) domain.set_quantity('stage', Set_Stage(x0, x1, 1.0)) domain.set_name() domain.set_store(False) domain.set_flow_algorithm('DE0') Br = anuga.Reflective_boundary(domain) # Solid reflective wall from math import sin Bts = anuga.Transmissive_n_momentum_zero_t_momentum_set_stage_boundary(domain, lambda t: 10*sin(t/200)) domain.set_boundary({'outflow' :Br, 'inflow' :Br, 'inner' :Br, 'exterior' :Br, 'open' :Bts}) for t in domain.evolve(yieldstep= yieldstep, finaltime=finaltime): #domain.write_time() pass
def create_domain(self, flowalg): # Riverwall = list of lists, each with a set of x,y,z (and optional QFactor) values # Make the domain anuga.create_mesh_from_regions(boundaryPolygon, boundary_tags={'left': [0], 'top': [1], 'right': [2], 'bottom': [3]}, maximum_triangle_area = 200., minimum_triangle_angle = 28.0, filename = 'test_boundaryfluxintegral.msh', use_cache=False, verbose=verbose) domain=anuga.create_domain_from_file('test_boundaryfluxintegral.msh') # 05/05/2014 -- riverwalls only work with DE0 and DE1 domain.set_flow_algorithm(flowalg) domain.set_name('test_boundaryfluxintegral') domain.set_store_vertices_uniquely() def topography(x,y): return -x/150. # NOTE: Setting quantities at centroids is important for exactness of tests domain.set_quantity('elevation',topography,location='centroids') domain.set_quantity('friction',0.03) domain.set_quantity('stage', topography,location='centroids') # Boundary conditions Br=anuga.Reflective_boundary(domain) Bd=anuga.Dirichlet_boundary([0., 0., 0.]) domain.set_boundary({'left': Br, 'right': Bd, 'top': Br, 'bottom':Br}) return domain
if myid == 0: mesh = anuga.create_mesh_from_regions( project.bounding_polygon, boundary_tags={'bottom': [0], 'right': [1], 'top': [2], 'left': [3]}, maximum_triangle_area=remainder_res, interior_holes=holes, breaklines=breaklines, filename=meshname, interior_regions=interior_regions, use_cache=use_cache, verbose=verbose) domain = anuga.create_domain_from_file(meshname) domain.set_flow_algorithm(alg) if verbose: print domain.get_extent(absolute=True) #------------------------------------------------------------------------------ # Setup initial conditions #------------------------------------------------------------------------------ domain.set_quantity('stage', 0.0) # Friction -- 2 options variable_friction = True if not variable_friction: # Constant friction domain.set_quantity('friction', 0.02)
def run_simulation(parallel=False, verbose=False): #-------------------------------------------------------------------------- # Setup computational domain and quantities #-------------------------------------------------------------------------- if myid == 0: anuga.create_mesh_from_regions(boundaryPolygon, boundary_tags={'left': [0], 'top': [1], 'right': [2], 'bottom': [3]}, maximum_triangle_area = 1.0e+20, minimum_triangle_angle = 28.0, filename = 'runup.msh', interior_regions = [ [higherResPolygon, 1.*1.*0.5], [midResPolygon, 3.0*3.0*0.5]], breaklines=riverWall.values(), use_cache=False, verbose=verbose, regionPtArea=regionPtAreas) sdomain=anuga.create_domain_from_file('runup.msh') sdomain.set_flow_algorithm(alg) sdomain.set_name('s_riverwall') sdomain.set_datadir('.') sdomain.set_store_vertices_uniquely() #------------------ # Define topography #------------------ def topography(x,y): return -x/150.*scale_me def stagefun(x,y): stg=-0.5*scale_me return stg sdomain.set_quantity('elevation',topography) # Use function for elevation sdomain.set_quantity('friction',0.03) # Constant friction sdomain.set_quantity('stage', stagefun) # Constant negative initial stage else: sdomain = None #-------------------------------------------------------------------------- # Create the parallel domains #-------------------------------------------------------------------------- if parallel: if myid == 0 and verbose : print 'DISTRIBUTING TO PARALLEL DOMAIN' pdomain = distribute(sdomain, verbose=verbose) pdomain.set_name('p_riverwall') pdomain.set_store_vertices_uniquely() if myid == 0 and verbose: print 60*'=' print 'EVOLVING pdomain' print 60*'=' setup_and_evolve(pdomain, verbose=verbose) barrier() if myid == 0: if verbose: print 60*'=' print 'EVOLVING sdomain' print 60*'=' setup_and_evolve(sdomain, verbose=verbose) barrier() #--------------------------------- # Now compare the merged sww files #--------------------------------- if myid == 0: if verbose: print 'COMPARING SWW FILES' sdomain_v = util.get_output('s_riverwall.sww') sdomain_c = util.get_centroids(sdomain_v) pdomain_v = util.get_output('p_riverwall.sww') pdomain_c = util.get_centroids(pdomain_v) # Test some values against the original ordering if verbose: order = 0 print 'PDOMAIN CENTROID VALUES' print num.linalg.norm(sdomain_c.x-pdomain_c.x,ord=order) print num.linalg.norm(sdomain_c.y-pdomain_c.y,ord=order) print num.linalg.norm(sdomain_c.stage[-1]-pdomain_c.stage[-1],ord=order) print num.linalg.norm(sdomain_c.xmom[-1]-pdomain_c.xmom[-1],ord=order) print num.linalg.norm(sdomain_c.ymom[-1]-pdomain_c.ymom[-1],ord=order) print num.linalg.norm(sdomain_c.xvel[-1]-pdomain_c.xvel[-1],ord=order) print num.linalg.norm(sdomain_c.yvel[-1]-pdomain_c.yvel[-1],ord=order) assert num.allclose(sdomain_c.stage,pdomain_c.stage) assert num.allclose(sdomain_c.xmom,pdomain_c.xmom) assert num.allclose(sdomain_c.ymom,pdomain_c.ymom) assert num.allclose(sdomain_c.xvel,pdomain_c.xvel) assert num.allclose(sdomain_c.yvel,pdomain_c.yvel) assert num.allclose(sdomain_v.x,pdomain_v.x) assert num.allclose(sdomain_v.y,pdomain_v.y) import os os.remove('s_riverwall.sww') os.remove('p_riverwall.sww') os.remove('runup.msh')
mesh = anuga.create_mesh_from_regions(project.bounding_polygon, boundary_tags={ 'bottom': [0], 'right': [1], 'top': [2], 'left': [3] }, maximum_triangle_area=remainder_res, interior_holes=holes, breaklines=breaklines, filename=meshname, interior_regions=interior_regions, use_cache=use_cache, verbose=verbose) domain = anuga.create_domain_from_file(meshname) domain.set_flow_algorithm(alg) if verbose: print(domain.get_extent(absolute=True)) #------------------------------------------------------------------------------ # Setup initial conditions #------------------------------------------------------------------------------ domain.set_quantity('stage', 0.0) # Friction -- 2 options variable_friction = True if not variable_friction: # Constant friction domain.set_quantity('friction', 0.02)
def run_simulation(parallel=False, verbose=False): #-------------------------------------------------------------------------- # Setup computational domain and quantities #-------------------------------------------------------------------------- if myid == 0: anuga.create_mesh_from_regions( boundaryPolygon, boundary_tags={ 'left': [0], 'top': [1], 'right': [2], 'bottom': [3] }, maximum_triangle_area=1.0e+20, minimum_triangle_angle=28.0, filename='runup.msh', interior_regions=[[higherResPolygon, 1. * 1. * 0.5], [midResPolygon, 3.0 * 3.0 * 0.5]], breaklines=list(riverWall.values()), use_cache=False, verbose=verbose, regionPtArea=regionPtAreas) sdomain = anuga.create_domain_from_file('runup.msh') sdomain.set_flow_algorithm(alg) sdomain.set_name('s_riverwall') sdomain.set_datadir('.') sdomain.set_store_vertices_uniquely() #------------------ # Define topography #------------------ def topography(x, y): return -x / 150. * scale_me def stagefun(x, y): stg = -0.5 * scale_me return stg sdomain.set_quantity('elevation', topography) # Use function for elevation sdomain.set_quantity('friction', 0.03) # Constant friction sdomain.set_quantity('stage', stagefun) # Constant negative initial stage else: sdomain = None #-------------------------------------------------------------------------- # Create the parallel domains #-------------------------------------------------------------------------- if parallel: if myid == 0 and verbose: print('DISTRIBUTING TO PARALLEL DOMAIN') pdomain = distribute(sdomain, verbose=verbose) pdomain.set_name('p_riverwall') pdomain.set_store_vertices_uniquely() if myid == 0 and verbose: print(60 * '=') print('EVOLVING pdomain') print(60 * '=') setup_and_evolve(pdomain, verbose=verbose) barrier() if myid == 0: if verbose: print(60 * '=') print('EVOLVING sdomain') print(60 * '=') setup_and_evolve(sdomain, verbose=verbose) barrier() #--------------------------------- # Now compare the merged sww files #--------------------------------- if myid == 0: if verbose: print('COMPARING SWW FILES') sdomain_v = util.get_output('s_riverwall.sww') sdomain_c = util.get_centroids(sdomain_v) pdomain_v = util.get_output('p_riverwall.sww') pdomain_c = util.get_centroids(pdomain_v) # Test some values against the original ordering if verbose: order = 0 print('PDOMAIN CENTROID VALUES') print(num.linalg.norm(sdomain_c.x - pdomain_c.x, ord=order)) print(num.linalg.norm(sdomain_c.y - pdomain_c.y, ord=order)) print( num.linalg.norm(sdomain_c.stage[-1] - pdomain_c.stage[-1], ord=order)) print( num.linalg.norm(sdomain_c.xmom[-1] - pdomain_c.xmom[-1], ord=order)) print( num.linalg.norm(sdomain_c.ymom[-1] - pdomain_c.ymom[-1], ord=order)) print( num.linalg.norm(sdomain_c.xvel[-1] - pdomain_c.xvel[-1], ord=order)) print( num.linalg.norm(sdomain_c.yvel[-1] - pdomain_c.yvel[-1], ord=order)) assert num.allclose(sdomain_c.stage, pdomain_c.stage) assert num.allclose(sdomain_c.xmom, pdomain_c.xmom) assert num.allclose(sdomain_c.ymom, pdomain_c.ymom) assert num.allclose(sdomain_c.xvel, pdomain_c.xvel) assert num.allclose(sdomain_c.yvel, pdomain_c.yvel) assert num.allclose(sdomain_v.x, pdomain_v.x) assert num.allclose(sdomain_v.y, pdomain_v.y) import os os.remove('s_riverwall.sww') os.remove('p_riverwall.sww') os.remove('runup.msh')
anuga.create_mesh_from_regions(boundaryPolygon, boundary_tags={'left': [0], 'top': [1], 'right': [2], 'bottom': [3]}, maximum_triangle_area = 1.0e+20, minimum_triangle_angle = 28.0, filename = 'runup.msh', interior_regions = [ [higherResPolygon, 1.*1.*0.5], [midResPolygon, 3.0*3.0*0.5]], breaklines=riverWall.values(), use_cache=False, verbose=True, regionPtArea=regionPtAreas) domain=anuga.create_domain_from_file('runup.msh') domain.set_flow_algorithm(alg) domain.set_name('runup_riverwall') domain.set_datadir('.') domain.set_store_vertices_uniquely() #------------------ # Define topography #------------------ def topography(x,y): return -x/150.*scale_me
# overall clipping polygon with a tagged # boundary and interior regions as defined in project.py #------------------------------------------------------------------------------ anuga.create_mesh_from_regions(project.bounding_polygon, boundary_tags={'top': [0], 'ocean_east': [1], 'bottom': [2], 'onshore': [3]}, maximum_triangle_area=project.low_res_0, filename=project.meshname, interior_regions=[], #project.interior_regions, breaklines=project.breakLines, regionPtArea=project.regionPtAreas, use_cache=False, verbose=True) domain=anuga.create_domain_from_file(project.meshname) # Print some stats about mesh and domain print 'Number of triangles = ', len(domain) print 'The extent is ', domain.get_extent() print domain.statistics() domain.set_flow_algorithm('tsunami') domain.verbose=True #------------------------------------------------------------------------------ # Setup parameters of computational domain #------------------------------------------------------------------------------ domainName=project.name_stem + '_' + project.scenario domain.set_name(domainName) # Name of sww file domain.set_datadir(project.output_run) # Store sww output here
'top1': [1], 'chan_out': [2], 'top2': [3], 'right': [4], 'bottom1': [5], 'chan_in': [6], 'bottom2': [7] }, maximum_triangle_area=1.0e+06, #0.5*l0*l0, minimum_triangle_angle=28.0, filename='channel_floodplain1.msh', interior_regions=[], breaklines=breakLines.values(), regionPtArea=regionPtAreas, verbose=True) domain = anuga.create_domain_from_file('channel_floodplain1.msh') domain.set_name('channel_floodplain1') # Output name domain.set_flow_algorithm(alg) else: domain = None barrier() domain = distribute(domain) barrier() domain.set_store_vertices_uniquely(True) #------------------------------------------------------------------------------ # # Setup initial conditions #
"""Set an initial condition with constant water height, for x0<x<x1 """ def __init__(self, x0=0.25, x1=0.5, h=1.0): self.x0 = x0 self.x1 = x1 self.h = h def __call__(self, x, y): return self.h*((x>self.x0)&(x<self.x1)) + 1.0 #-------------------------------------------------------------------------- # Setup Domain only on processor 0 #-------------------------------------------------------------------------- if myid == 0: domain = create_domain_from_file(mesh_filename) domain.set_quantity('stage', Set_Stage(x0, x1, 2.0)) else: domain = None #-------------------------------------------------------------------------- # Distribute sequential domain on processor 0 to other processors #-------------------------------------------------------------------------- if myid == 0 and verbose: print 'DISTRIBUTING DOMAIN' domain = distribute(domain) #domain.smooth = False barrier() for p in range(numprocs): if myid == p:
"""Set an elevation """ def __init__(self, h=1.0): self.x0 = x0 self.x1 = x1 self.h = h def __call__(self, x, y): return x/self.h #-------------------------------------------------------------------------- # Setup Domain only on processor 0 #-------------------------------------------------------------------------- domain = create_domain_from_file(mesh_filename, HMPP_domain) domain.set_quantity('stage', Set_Stage(x0, x1, 2.0)) domain.set_datadir('Data') domain.set_name('merimbula_new') domain.set_store(True) #domain.set_quantity('elevation', Set_Elevation(500.0)) #print domain.statistics() #print domain.get_extent() #print domain.get_extent(absolute=True) #print domain.geo_reference #-------------------------------------------------------------------------- # Distribute sequential domain on processor 0 to other processors
def create_domain(self, InitialOceanStage, InitialLandStage, flowAlg='DE0', verbose=False): """ Make the domain and set the flow algorithm for a test. Produces an sww that we can use for testing """ boundaryPolygon = [[minX, minY], [minX, minY + 100.], [minX + 100., minY + 100.], [minX + 100., minY]] anuga.create_mesh_from_regions( boundaryPolygon, boundary_tags={ 'left': [0], 'top': [1], 'right': [2], 'bottom': [3] }, maximum_triangle_area=1., minimum_triangle_angle=28.0, filename='test_quantity_setting_functions.msh', interior_regions=[], verbose=False) domain = anuga.create_domain_from_file( 'test_quantity_setting_functions.msh') os.remove('test_quantity_setting_functions.msh') domain.set_flow_algorithm(flowAlg) domain.set_name('test_quantity_setting_functions') domain.set_store_vertices_uniquely() def topography(x, y): return -x / 150. def stagefun(x, y): stg = InitialOceanStage * (x >= 50.) + InitialLandStage * (x < 50.) return stg domain.set_flow_algorithm(flowAlg) # domain.set_quantity('elevation',topography,location='centroids') domain.set_quantity('elevation', topography) domain.set_quantity('friction', 0.03) #domain.set_quantity('stage', stagefun,location='centroids') domain.set_quantity('stage', stagefun) if (verbose): if (domain.store_centroids): print(' Centroids stored') else: print(' Centroids estimated from vertices') # Boundary conditions Br = anuga.Reflective_boundary(domain) domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br}) return domain
def generate_merimbula_domain(gpu=True): #----------------------------------------------------------------------- # Import necessary modules #----------------------------------------------------------------------- import os import sys import time import numpy as num #------------------------ # ANUGA Modules #------------------------ from anuga import Domain from anuga import Reflective_boundary from anuga import Dirichlet_boundary from anuga import Time_boundary from anuga import Transmissive_boundary from anuga import rectangular_cross from anuga import create_domain_from_file from anuga_cuda import GPU_domain, merimbula_dir #----------------------------------------------------------------------- # Setup parameters #----------------------------------------------------------------------- #mesh_filename = "merimbula_10785.tsh" ; x0 = 756000.0 ; x1 = 756500.0 mesh_filename = "merimbula_43200.tsh" ; x0 = 756000.0 ; x1 = 756500.0 #mesh_filename = "test-100.tsh" ; x0 = 0.25 ; x1 = 0.5 #mesh_filename = "test-20.tsh" ; x0 = 250.0 ; x1 = 350.0 mesh_filename = merimbula_dir + mesh_filename yieldstep = 50 finaltime = 500 verbose = True #----------------------------------------------------------------------- # Setup procedures #----------------------------------------------------------------------- class Set_Stage: """Set an initial condition with constant water height, for x0<x<x1 """ def __init__(self, x0=0.25, x1=0.5, h=1.0): self.x0 = x0 self.x1 = x1 self.h = h def __call__(self, x, y): return self.h*((x>self.x0)&(x<self.x1))+1.0 class Set_Elevation: """Set an elevation """ def __init__(self, h=1.0): self.x0 = x0 self.x1 = x1 self.h = h def __call__(self, x, y): return x/self.h #-------------------------------------------------------------------------- # Setup Domain only on processor 0 #-------------------------------------------------------------------------- if not gpu: domain = create_domain_from_file(mesh_filename) else: domain = create_domain_from_file(mesh_filename, GPU_domain) domain.using_gpu = False domain.set_quantity('stage', Set_Stage(x0, x1, 2.0)) domain.set_datadir('Data') domain.set_name('merimbula_new') domain.set_store(True) #domain.set_quantity('elevation', Set_Elevation(500.0)) #print domain.statistics() #print domain.get_extent() #print domain.get_extent(absolute=True) #print domain.geo_reference #-------------------------------------------------------------------------- # Distribute sequential domain on processor 0 to other processors #-------------------------------------------------------------------------- #if myid == 0 and verbose: print 'DISTRIBUTING DOMAIN' #domain = distribute(domain) #-------------------------------------------------------------------------- # On all processors, setup evolve parameters for domains on all processors # (all called "domain" #-------------------------------------------------------------------------- #domain.set_flow_algorithm('2_0') #domain.smooth = False #domain.set_default_order(2) #domain.set_timestepping_method('rk2') #domain.set_CFL(0.7) #domain.set_beta(1.5) #for p in range(numprocs): # if myid == p: # print 'P%d'%p # print domain.get_extent() # print domain.get_extent(absolute=True) # print domain.geo_reference # print domain.s2p_map # print domain.p2s_map # print domain.tri_l2g # print domain.node_l2g # else: # pass # # barrier() #------------------------------------------------------------------------------ # Setup boundary conditions # This must currently happen *after* domain has been distributed #------------------------------------------------------------------------------ Br = Reflective_boundary(domain) # Solid reflective wall domain.set_boundary({'outflow' :Br, 'inflow' :Br, 'inner' :Br, 'exterior' :Br, 'open' :Br}) return domain
"""Set an elevation """ def __init__(self, h=1.0): self.x0 = x0 self.x1 = x1 self.h = h def __call__(self, x, y): return x / self.h #-------------------------------------------------------------------------- # Setup Sequential Domain #-------------------------------------------------------------------------- if myid == 0: domain = create_domain_from_file(mesh_filename) domain.set_quantity('stage', Set_Stage(x0, x1, 2.0)) #domain.set_datadir('.') domain.set_name('merimbula_new') domain.set_store(True) else: domain = None #-------------------------------------------------------------------------- # Distribute sequential domain on processor 0 to other processors #-------------------------------------------------------------------------- if verbose: print 'DISTRIBUTING DOMAIN' domain = distribute(domain) #-------------------------------------------------------------------------- # On all processors, setup evolve parameters for domains on all processors
def run_simulation(parallel=False): domain = create_domain_from_file(mesh_filename) domain.set_quantity('stage', Set_Stage(756000.0, 756500.0, 2.0)) #-------------------------------------------------------------------------- # Create parallel domain if requested #-------------------------------------------------------------------------- if parallel: if myid == 0 and verbose: print 'DISTRIBUTING PARALLEL DOMAIN' domain = distribute(domain) #------------------------------------------------------------------------------ # Setup boundary conditions # This must currently happen *after* domain has been distributed #------------------------------------------------------------------------------ domain.store = False Br = Reflective_boundary(domain) # Solid reflective wall domain.set_boundary({'outflow' :Br, 'inflow' :Br, 'inner' :Br, 'exterior' :Br, 'open' :Br}) #------------------------------------------------------------------------------ # Setup diagnostic arrays #------------------------------------------------------------------------------ l1list = [] l2list = [] linflist = [] l1norm = num.zeros(3, num.float) l2norm = num.zeros(3, num.float) linfnorm = num.zeros(3, num.float) recv_norm = num.zeros(3, num.float) #------------------------------------------------------------------------------ # Evolution #------------------------------------------------------------------------------ if parallel: if myid == 0 and verbose: print 'PARALLEL EVOLVE' else: if verbose: print 'SEQUENTIAL EVOLVE' for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): edges = domain.quantities[quantity].edge_values.take(num.flatnonzero(domain.tri_full_flag),axis=0) l1norm[0] = l1_norm(edges[:,0]) l1norm[1] = l1_norm(edges[:,1]) l1norm[2] = l1_norm(edges[:,2]) l2norm[0] = l2_norm(edges[:,0]) l2norm[1] = l2_norm(edges[:,1]) l2norm[2] = l2_norm(edges[:,2]) linfnorm[0] = linf_norm(edges[:,0]) linfnorm[1] = linf_norm(edges[:,1]) linfnorm[2] = linf_norm(edges[:,2]) if parallel: l2norm[0] = pow(l2norm[0], 2) l2norm[1] = pow(l2norm[1], 2) l2norm[2] = pow(l2norm[2], 2) if myid == 0: #domain.write_time() #print edges[:,1] for p in range(1, numprocs): recv_norm = pypar.receive(p) l1norm += recv_norm recv_norm = pypar.receive(p) l2norm += recv_norm recv_norm = pypar.receive(p) linfnorm[0] = max(linfnorm[0], recv_norm[0]) linfnorm[1] = max(linfnorm[1], recv_norm[1]) linfnorm[2] = max(linfnorm[2], recv_norm[2]) l2norm[0] = pow(l2norm[0], 0.5) l2norm[1] = pow(l2norm[1], 0.5) l2norm[2] = pow(l2norm[2], 0.5) l1list.append(l1norm) l2list.append(l2norm) linflist.append(linfnorm) else: pypar.send(l1norm, 0) pypar.send(l2norm, 0) pypar.send(linfnorm, 0) else: #domain.write_time() l1list.append(l1norm) l2list.append(l2norm) linflist.append(linfnorm) return (l1list, l2list, linflist)
def generate_merimbula_domain(gpu=True): #----------------------------------------------------------------------- # Import necessary modules #----------------------------------------------------------------------- import os import sys import time import numpy as num #------------------------ # ANUGA Modules #------------------------ from anuga import Domain from anuga import Reflective_boundary from anuga import Dirichlet_boundary from anuga import Time_boundary from anuga import Transmissive_boundary from anuga import rectangular_cross from anuga import create_domain_from_file from anuga_cuda import GPU_domain, merimbula_dir #----------------------------------------------------------------------- # Setup parameters #----------------------------------------------------------------------- #mesh_filename = "merimbula_10785.tsh" ; x0 = 756000.0 ; x1 = 756500.0 mesh_filename = "merimbula_43200.tsh" x0 = 756000.0 x1 = 756500.0 #mesh_filename = "test-100.tsh" ; x0 = 0.25 ; x1 = 0.5 #mesh_filename = "test-20.tsh" ; x0 = 250.0 ; x1 = 350.0 mesh_filename = merimbula_dir + mesh_filename yieldstep = 50 finaltime = 500 verbose = True #----------------------------------------------------------------------- # Setup procedures #----------------------------------------------------------------------- class Set_Stage: """Set an initial condition with constant water height, for x0<x<x1 """ def __init__(self, x0=0.25, x1=0.5, h=1.0): self.x0 = x0 self.x1 = x1 self.h = h def __call__(self, x, y): return self.h * ((x > self.x0) & (x < self.x1)) + 1.0 class Set_Elevation: """Set an elevation """ def __init__(self, h=1.0): self.x0 = x0 self.x1 = x1 self.h = h def __call__(self, x, y): return x / self.h #-------------------------------------------------------------------------- # Setup Domain only on processor 0 #-------------------------------------------------------------------------- if not gpu: domain = create_domain_from_file(mesh_filename) else: domain = create_domain_from_file(mesh_filename, GPU_domain) domain.using_gpu = False domain.set_quantity('stage', Set_Stage(x0, x1, 2.0)) domain.set_datadir('Data') domain.set_name('merimbula_new') domain.set_store(True) #domain.set_quantity('elevation', Set_Elevation(500.0)) #print domain.statistics() #print domain.get_extent() #print domain.get_extent(absolute=True) #print domain.geo_reference #-------------------------------------------------------------------------- # Distribute sequential domain on processor 0 to other processors #-------------------------------------------------------------------------- #if myid == 0 and verbose: print 'DISTRIBUTING DOMAIN' #domain = distribute(domain) #-------------------------------------------------------------------------- # On all processors, setup evolve parameters for domains on all processors # (all called "domain" #-------------------------------------------------------------------------- #domain.set_flow_algorithm('2_0') #domain.smooth = False #domain.set_default_order(2) #domain.set_timestepping_method('rk2') #domain.set_CFL(0.7) #domain.set_beta(1.5) #for p in range(numprocs): # if myid == p: # print 'P%d'%p # print domain.get_extent() # print domain.get_extent(absolute=True) # print domain.geo_reference # print domain.s2p_map # print domain.p2s_map # print domain.tri_l2g # print domain.node_l2g # else: # pass # # barrier() #------------------------------------------------------------------------------ # Setup boundary conditions # This must currently happen *after* domain has been distributed #------------------------------------------------------------------------------ Br = Reflective_boundary(domain) # Solid reflective wall domain.set_boundary({ 'outflow': Br, 'inflow': Br, 'inner': Br, 'exterior': Br, 'open': Br }) return domain
def evolution_test(parallel=False): domain = create_domain_from_file(mesh_filename) domain.set_quantity('stage', Set_Stage(756000.0, 756500.0, 2.0)) #-------------------------------------------------------------------------- # Create parallel domain if requested #-------------------------------------------------------------------------- if parallel: if par.myid == 0 and verbose: print 'DISTRIBUTING PARALLEL DOMAIN' domain = distribute(domain) #------------------------------------------------------------------------------ # Setup boundary conditions # This must currently happen *after* domain has been distributed #------------------------------------------------------------------------------ domain.store = False Br = Reflective_boundary(domain) # Solid reflective wall domain.set_boundary({ 'outflow': Br, 'inflow': Br, 'inner': Br, 'exterior': Br, 'open': Br }) #------------------------------------------------------------------------------ # Setup diagnostic arrays #------------------------------------------------------------------------------ l1list = [] l2list = [] linflist = [] l1norm = num.zeros(3, num.float) l2norm = num.zeros(3, num.float) linfnorm = num.zeros(3, num.float) recv_norm = num.zeros(3, num.float) #------------------------------------------------------------------------------ # Evolution #------------------------------------------------------------------------------ if parallel: if par.myid == 0 and verbose: print 'PARALLEL EVOLVE' else: if verbose: print 'SEQUENTIAL EVOLVE' for t in domain.evolve(yieldstep=yieldstep, finaltime=finaltime): edges = domain.quantities[quantity].edge_values.take(num.flatnonzero( domain.tri_full_flag), axis=0) l1norm[0] = l1_norm(edges[:, 0]) l1norm[1] = l1_norm(edges[:, 1]) l1norm[2] = l1_norm(edges[:, 2]) l2norm[0] = l2_norm(edges[:, 0]) l2norm[1] = l2_norm(edges[:, 1]) l2norm[2] = l2_norm(edges[:, 2]) linfnorm[0] = linf_norm(edges[:, 0]) linfnorm[1] = linf_norm(edges[:, 1]) linfnorm[2] = linf_norm(edges[:, 2]) if parallel: l2norm[0] = pow(l2norm[0], 2) l2norm[1] = pow(l2norm[1], 2) l2norm[2] = pow(l2norm[2], 2) if par.myid == 0: #domain.write_time() #print edges[:,1] for p in range(1, par.numprocs): recv_norm = par.receive(p) l1norm += recv_norm recv_norm = par.receive(p) l2norm += recv_norm recv_norm = par.receive(p) linfnorm[0] = max(linfnorm[0], recv_norm[0]) linfnorm[1] = max(linfnorm[1], recv_norm[1]) linfnorm[2] = max(linfnorm[2], recv_norm[2]) l2norm[0] = pow(l2norm[0], 0.5) l2norm[1] = pow(l2norm[1], 0.5) l2norm[2] = pow(l2norm[2], 0.5) l1list.append(l1norm) l2list.append(l2norm) linflist.append(linfnorm) else: par.send(l1norm, 0) par.send(l2norm, 0) par.send(linfnorm, 0) else: #domain.write_time() l1list.append(l1norm) l2list.append(l2norm) linflist.append(linfnorm) return (l1list, l2list, linflist)
boundary_tags={'left': [0], 'top1': [1], 'chan_out': [2], 'top2': [3], 'right': [4], 'bottom1': [5], 'chan_in': [6], 'bottom2': [7] }, maximum_triangle_area = 1.0e+06, #0.5*l0*l0, minimum_triangle_angle = 28.0, filename = 'channel_floodplain1.msh', interior_regions = [ ], breaklines=breakLines.values(), regionPtArea=regionPtAreas, verbose=True) domain=anuga.create_domain_from_file('channel_floodplain1.msh') domain.set_name('channel_floodplain1') # Output name domain.set_flow_algorithm(alg) else: domain=None barrier() domain=distribute(domain) barrier() domain.set_store_vertices_uniquely(True) #------------------------------------------------------------------------------ # # Setup initial conditions #
default_man_n = project.default_man_n verbose = project.verbose minimum_storable_height = project.min_storable_h store_unique_vertices = project.store_unique_vertices is_varying_manning = project.is_varying_manning # ----------------------------------------------------------------------------- # SET UP DOMAIN AND INITIAL CONDITION # ----------------------------------------------------------------------------- zelv = helper.data.get_elevation(f_elv) xmom = helper.data.get_xmomentum(f_elv) ymom = helper.data.get_ymomentum(f_elv) inistage = helper.data.get_stage(f_elv) man_n = helper.data.get_manning(f_man, is_varying_manning, default_man_n) domain = anuga.create_domain_from_file(f_mesh, GPU_domain) domain.using_gpu = True domain.cotesting = False print domain.statistics() domain.set_quantity('elevation', zelv) domain.set_quantity('stage', inistage) domain.set_quantity('xmomentum', xmom) domain.set_quantity('ymomentum', ymom) domain.set_quantity('friction', man_n) # additional domain setup domain.set_name(name_out) domain.set_datadir(dir_out) domain.set_minimum_storable_height(minimum_storable_height)