def generate_domain(): #-------------------------------------------------------------------------- # Setup computational domain #-------------------------------------------------------------------------- length = 10. width = 5. dx = dy = 1. # Resolution: Length of subdivisions on both axes points, vertices, boundary = anuga.rectangular_cross(int(length / dx), int(width / dy), len1=length, len2=width) domain = anuga.Domain(points, vertices, boundary) domain.set_name('channel2') # Output name #-------------------------------------------------------------------------- # Setup initial conditions #-------------------------------------------------------------------------- def topography(x, y): return -x / 10 # linear bed slope domain.set_quantity('elevation', topography) # Use function for elevation domain.set_quantity('friction', 0.01) # Constant friction domain.set_quantity('stage', expression='elevation') # Dry initial condition #-------------------------------------------------------------------------- # Setup boundary conditions #-------------------------------------------------------------------------- Bi = anuga.Dirichlet_boundary([0.4, 0, 0]) # Inflow Br = anuga.Reflective_boundary(domain) # Solid reflective wall Bo = anuga.Dirichlet_boundary([-5, 0, 0]) # Outflow domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br}) import sys if len(sys.argv) > 1 and "gpu" in sys.argv: domain.using_gpu = True else: domain.using_gpu = False print sys.argv, "gpu" in sys.argv return domain
def setup_boundaries(simulation): """ Setup boundary conditions """ domain = simulation.domain Bd = anuga.Dirichlet_boundary([0, 0, 0]) Bw = anuga.Time_boundary(domain=domain, function=wrapped_file_function) domain.set_boundary({'west': Bd, 'south': Bd, 'north': Bd, 'east': Bw})
def generate_channel1_domain(gpu=True): #-------------------------------------------------------------------------- # Setup computational domain #-------------------------------------------------------------------------- #points, vertices, boundary = anuga.rectangular_cross(10, 1, # len1=10.0, len2=5.0) # Mesh points, vertices, boundary = anuga.rectangular_cross(1, 4, len1=0.1, len2=0.1) # Mesh if gpu: domain = GPU_domain(points, vertices, boundary) # Create domain for i in range(len(sys.argv)): if sys.argv[i] == '-gpu': domain.using_gpu = True print " --> Enable GPU version" elif sys.argv[i] == '-fs': finaltime = float(sys.argv[i + 1]) print " --> Finaltime is reset as %f" % finaltime elif sys.argv[i] == '-test': domain.cotesting = True print " --> Enable Cotesting" elif sys.argv[i] == '-ustore': domain.store = True print " --> Disable storing" else: domain = anuga.Domain(points, vertices, boundary) # Create domain domain.set_name('channel1') # Output name #-------------------------------------------------------------------------- # Setup initial conditions #-------------------------------------------------------------------------- def topography(x, y): return -x / 10 # linear bed slope domain.set_quantity('elevation', topography) # Use function for elevation domain.set_quantity('friction', 0.01) # Constant friction domain.set_quantity( 'stage', # Dry bed expression='elevation') #-------------------------------------------------------------------------- # Setup boundary conditions #-------------------------------------------------------------------------- Bi = anuga.Dirichlet_boundary([0.4, 0, 0]) # Inflow Br = anuga.Reflective_boundary(domain) # Solid reflective wall domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br}) return domain
def test_boundary_conditions(self): a = [0.0, 0.0] b = [0.0, 2.0] c = [2.0, 0.0] d = [0.0, 4.0] e = [2.0, 2.0] f = [4.0, 0.0] points = [a, b, c, d, e, f] #bac, bce, ecf, dbe vertices = [[1, 0, 2], [1, 2, 4], [4, 2, 5], [3, 1, 4]] boundary = { (0, 0): 'First', (0, 2): 'First', (2, 0): 'Second', (2, 1): 'Second', (3, 1): 'Second', (3, 2): 'Second' } domain = Generic_Domain(points, vertices, boundary, conserved_quantities =\ ['stage', 'xmomentum', 'ymomentum']) domain.check_integrity() domain.set_quantity('stage', [[1, 2, 3], [5, 5, 5], [0, 0, 9], [-6, 3, 3]]) domain.set_boundary({ 'First': anuga.Dirichlet_boundary([5, 2, 1]), 'Second': anuga.Transmissive_boundary(domain) }) domain.update_boundary() assert domain.quantities['stage'].boundary_values[0] == 5. #Dirichlet assert domain.quantities['stage'].boundary_values[1] == 5. #Dirichlet assert domain.quantities['stage'].boundary_values[2] ==\ domain.get_conserved_quantities(2, edge=0)[0] #Transmissive (4.5) assert domain.quantities['stage'].boundary_values[3] ==\ domain.get_conserved_quantities(2, edge=1)[0] #Transmissive (4.5) assert domain.quantities['stage'].boundary_values[4] ==\ domain.get_conserved_quantities(3, edge=1)[0] #Transmissive (-1.5) assert domain.quantities['stage'].boundary_values[5] ==\ domain.get_conserved_quantities(3, edge=2)[0] #Transmissive (-1.5) #Check enumeration for k, ((vol_id, edge_id), _) in enumerate(domain.boundary_objects): assert domain.neighbours[vol_id, edge_id] == -k - 1
def create_sww_boundary(self, boundary_starttime): """ This creates a boundary file with ; time stage 0 5 10 2.15268 20 13.9773 """ tide = 5 boundary_filename = tempfile.mktemp(".sww") dir, base = os.path.split(boundary_filename) boundary_name = base[:-4] # Setup computational domain mesh = Mesh() mesh.add_region_from_polygon([[0, 0], [100, 0], [100, 100], [0, 100]]) mesh.generate_mesh(verbose=False) domain = pmesh_to_domain_instance(mesh, anuga.Domain) domain.set_name(boundary_name) domain.set_datadir(dir) domain.set_starttime(boundary_starttime) domain.set_low_froude(0) # Setup initial conditions domain.set_quantity('elevation', 0.0) domain.set_quantity('stage', tide) # Setup boundary conditions Bd = anuga.Dirichlet_boundary([tide, 0., 0.]) # Constant boundary values Bd = anuga.Time_boundary( domain=domain, # Time dependent boundary function=lambda t: [t, 0.0, 0.0]) domain.set_boundary({'exterior': Bd}) for t in domain.evolve(yieldstep=10, finaltime=20.0): pass #print domain.boundary_statistics('stage') q = Bd.evaluate() # FIXME (Ole): This test would not have passed in # changeset:5846. msg = 'Time boundary not evaluated correctly' assert num.allclose(t, q[0]), msg #print domain.get_quantity('stage').get_values() #domain.write_time() #print "domain.time", domain.time return boundary_filename
def setup_boundaries(simulation): """ Setup boundary conditions """ domain = simulation.domain Bd = anuga.Dirichlet_boundary([0, 0, 0]) #Bw = anuga.Time_boundary(domain=domain, function=wrapped_file_function) func = anuga.file_function(join('Forcing', 'Tide', 'Pioneer.tms'), quantities='rainfall') Bw = anuga.Time_boundary(domain=domain, function=lambda t: [func(t), 0.0, 0.0]) domain.set_boundary({'west': Bd, 'south': Bd, 'north': Bd, 'east': Bw})
def test_boundary_indices(self): from anuga.config import default_boundary_tag a = [0.0, 0.5] b = [0.0, 0.0] c = [0.5, 0.5] points = [a, b, c] vertices = [[0, 1, 2]] domain = Generic_Domain(points, vertices) domain.set_boundary( \ {default_boundary_tag: anuga.Dirichlet_boundary([5,2,1])} ) domain.check_integrity() assert num.allclose(domain.neighbours, [[-1, -2, -3]])
def create_domain(self, flowalg): # Riverwall = list of lists, each with a set of x,y,z (and optional QFactor) values # Make the domain domain = anuga.create_domain_from_regions( boundaryPolygon, boundary_tags={ 'left': [0], 'top': [1], 'right': [2], 'bottom': [3] }, mesh_filename='test_boundaryfluxintegral.msh', maximum_triangle_area=200., minimum_triangle_angle=28.0, use_cache=False, verbose=verbose) # 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
def test_conserved_evolved_boundary_conditions(self): a = [0.0, 0.0] b = [0.0, 2.0] c = [2.0, 0.0] d = [0.0, 4.0] e = [2.0, 2.0] f = [4.0, 0.0] points = [a, b, c, d, e, f] #bac, bce, ecf, dbe vertices = [[1, 0, 2], [1, 2, 4], [4, 2, 5], [3, 1, 4]] boundary = { (0, 0): 'First', (0, 2): 'First', (2, 0): 'Second', (2, 1): 'Second', (3, 1): 'Second', (3, 2): 'Second' } try: domain = Generic_Domain(points, vertices, boundary, conserved_quantities = ['stage', 'xmomentum', 'ymomentum'], evolved_quantities =\ ['stage', 'xmomentum', 'xvelocity', 'ymomentum', 'yvelocity']) except: pass else: msg = 'Should have caught the evolved quantities not being in order' raise Exception(msg) domain = Generic_Domain(points, vertices, boundary, conserved_quantities = ['stage', 'xmomentum', 'ymomentum'], evolved_quantities =\ ['stage', 'xmomentum', 'ymomentum', 'xvelocity', 'yvelocity']) domain.set_quantity('stage', [[1, 2, 3], [5, 5, 5], [0, 0, 9], [6, -3, 3]]) domain.set_boundary({ 'First': anuga.Dirichlet_boundary([5, 2, 1, 4, 6]), 'Second': anuga.Transmissive_boundary(domain) }) # try: # domain.update_boundary() # except: # pass # else: # msg = 'Should have caught the lack of conserved_values_to_evolved_values member function' # raise Exception, msg domain.update_boundary() def conserved_values_to_evolved_values(q_cons, q_evol): q_evol[0:3] = q_cons q_evol[3] = old_div(q_cons[1], q_cons[0]) q_evol[4] = old_div(q_cons[2], q_cons[0]) return q_evol domain.conserved_values_to_evolved_values = conserved_values_to_evolved_values domain.update_boundary() assert domain.quantities['stage'].boundary_values[0] == 5. #Dirichlet assert domain.quantities['stage'].boundary_values[1] == 5. #Dirichlet assert domain.quantities['xvelocity'].boundary_values[ 0] == 4. #Dirichlet assert domain.quantities['yvelocity'].boundary_values[ 1] == 6. #Dirichlet q_cons = domain.get_conserved_quantities(2, edge=0) #Transmissive assert domain.quantities['stage'].boundary_values[2] == q_cons[0] assert domain.quantities['xmomentum'].boundary_values[2] == q_cons[1] assert domain.quantities['ymomentum'].boundary_values[2] == q_cons[2] assert domain.quantities['xvelocity'].boundary_values[2] == old_div( q_cons[1], q_cons[0]) assert domain.quantities['yvelocity'].boundary_values[2] == old_div( q_cons[2], q_cons[0]) q_cons = domain.get_conserved_quantities(2, edge=1) #Transmissive assert domain.quantities['stage'].boundary_values[3] == q_cons[0] assert domain.quantities['xmomentum'].boundary_values[3] == q_cons[1] assert domain.quantities['ymomentum'].boundary_values[3] == q_cons[2] assert domain.quantities['xvelocity'].boundary_values[3] == old_div( q_cons[1], q_cons[0]) assert domain.quantities['yvelocity'].boundary_values[3] == old_div( q_cons[2], q_cons[0]) q_cons = domain.get_conserved_quantities(3, edge=1) #Transmissive assert domain.quantities['stage'].boundary_values[4] == q_cons[0] assert domain.quantities['xmomentum'].boundary_values[4] == q_cons[1] assert domain.quantities['ymomentum'].boundary_values[4] == q_cons[2] assert domain.quantities['xvelocity'].boundary_values[4] == old_div( q_cons[1], q_cons[0]) assert domain.quantities['yvelocity'].boundary_values[4] == old_div( q_cons[2], q_cons[0]) q_cons = domain.get_conserved_quantities(3, edge=2) #Transmissive assert domain.quantities['stage'].boundary_values[5] == q_cons[0] assert domain.quantities['xmomentum'].boundary_values[5] == q_cons[1] assert domain.quantities['ymomentum'].boundary_values[5] == q_cons[2] assert domain.quantities['xvelocity'].boundary_values[5] == old_div( q_cons[1], q_cons[0]) assert domain.quantities['yvelocity'].boundary_values[5] == old_div( q_cons[2], q_cons[0])
def generate_cairns_domain(gpu=False): #----------------------------------------------------------------------- # Preparation of topographic data # Convert ASC 2 DEM 2 PTS using source data # and store result in source data #----------------------------------------------------------------------- # Create DEM from asc data anuga.asc2dem(project.name_stem + '.asc', use_cache=True, verbose=True) # Create pts file for onshore DEM anuga.dem2pts(project.name_stem + '.dem', use_cache=True, verbose=True) #----------------------------------------------------------------------- # Create the triangular mesh and domain based on # overall clipping polygon with a tagged # boundary and interior regions as defined in project.py #----------------------------------------------------------------------- domain = anuga.create_domain_from_regions( project.bounding_polygon, boundary_tags={ 'top': [0], 'ocean_east': [1], 'bottom': [2], 'onshore': [3] }, maximum_triangle_area=project.default_res, mesh_filename=project.meshname, interior_regions=project.interior_regions, use_cache=True, verbose=True) if gpu: #domain.__class__ = GPU_domain domain = GPU_domain(domain=domain) # Print some stats about mesh and domain print 'Number of triangles = ', len(domain) #print 'The extent is ', domain.get_extent() #print domain.statistics() #----------------------------------------------------------------------- # Setup parameters of computational domain #----------------------------------------------------------------------- domain.set_name('cairns_' + project.scenario) # Name of sww file domain.set_datadir('.') # Store sww output here domain.set_minimum_storable_height(0.01) # Store only depth > 1cm domain.set_flow_algorithm('tsunami') #----------------------------------------------------------------------- # Setup initial conditions #----------------------------------------------------------------------- tide = 0.0 domain.set_quantity('stage', tide) domain.set_quantity('friction', 0.0) domain.set_quantity('elevation', filename=project.name_stem + '.pts', use_cache=True, verbose=True, alpha=0.1) #----------------------------------------------------------------------- # Setup information for slide scenario # (to be applied 1 min into simulation #----------------------------------------------------------------------- if project.scenario == 'slide': # Function for submarine slide tsunami_source = anuga.slide_tsunami(length=35000.0, depth=project.slide_depth, slope=6.0, thickness=500.0, x0=project.slide_origin[0], y0=project.slide_origin[1], alpha=0.0, domain=domain, verbose=True) #----------------------------------------------------------------------- # Setup boundary conditions #----------------------------------------------------------------------- print 'Available boundary tags', domain.get_boundary_tags() Bd = anuga.Dirichlet_boundary([tide, 0, 0]) # Mean water level Bs = anuga.Transmissive_stage_zero_momentum_boundary(domain) # Neutral boundary if project.scenario == 'fixed_wave': # Huge 50m wave starting after 60 seconds and lasting 1 hour. Bw = anuga.Transmissive_n_momentum_zero_t_momentum_set_stage_boundary( domain=domain, function=lambda t: [(60 < t < 3660) * 50, 0, 0]) domain.set_boundary({ 'ocean_east': Bw, 'bottom': Bs, 'onshore': Bd, 'top': Bs }) if project.scenario == 'slide': # Boundary conditions for slide scenario domain.set_boundary({ 'ocean_east': Bd, 'bottom': Bd, 'onshore': Bd, 'top': Bd }) if gpu: if '-gpu' in sys.argv: domain.using_gpu = True print " --> Enable GPU version" return domain
number_of_barrels=1, #update_interval=0.25, log_file=True, discharge_hydrograph=True, use_velocity_head=False, verbose=True) domain.forcing_terms.append(culvert_energy) """ #------------------------------------------------------------------------------ # Setup boundary conditions #------------------------------------------------------------------------------ print 'Setting Boundary Conditions' Br = anuga.Reflective_boundary(domain) # Solid reflective wall Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0]) # Inflow based on Flow Depth and Approaching Momentum !!! Bo = anuga.Dirichlet_boundary([-5.0, 0, 0]) # Outflow water at -5.0 Bd = anuga.Dirichlet_boundary([0,0,0]) # Outflow water at 0.0 #Btus = Time_boundary(domain, lambda t: [0.0+ 1.025*(1+num.sin(2*pi*(t-4)/10)), 0.0, 0.0]) #Btds = Time_boundary(domain, lambda t: [0.0+ 0.0075*(1+num.sin(2*pi*(t-4)/20)), 0.0, 0.0]) Btus = anuga.Dirichlet_boundary([18.0, 0, 0]) # Outflow water at 5.0 Btds = anuga.Dirichlet_boundary([0.0, 0, 0]) # Outflow water at 1.0 domain.set_boundary({'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br}) #------------------------------------------------------------------------------ # Evolve system through time #------------------------------------------------------------------------------
z = zeros(len(x), float) for i in range(len(x)): if x[i]<=0.0: z[i] = h0 else: z[i] = h1 return z domain.set_quantity('stage', height) #----------------------------------------------------------------------------- # Setup boundary conditions #------------------------------------------------------------------------------ from math import sin, pi, exp Br = anuga.Reflective_boundary(domain) # Solid reflective wall Bt = anuga.Transmissive_boundary(domain) # Continue all values on boundary Bd = anuga.Dirichlet_boundary([1,0.,0.]) # Constant boundary values # Associate boundary tags with boundary objects domain.set_boundary({'left': Bt, 'right': Bt, 'top': Br, 'bottom': Br}) #=============================================================================== vtk_visualiser = True if vtk_visualiser: from anuga.visualiser import RealtimeVisualiser vis = RealtimeVisualiser(domain) vis.render_quantity_height("height",dynamic=True) #vis.render_quantity_height("stage", zScale =1.0, dynamic=True) vis.colour_height_quantity('stage', (0.0, 0.0, 1.0)) vis.start() #===============================================================================
else: domain = None #------------------------ # Create parallel domain #------------------------ domain = distribute(domain) #-------------------------- # Setup boundary conditions #-------------------------- Br = anuga.Reflective_boundary(domain) # Solid reflective wall Bt = anuga.Transmissive_boundary( domain) # Continue all values of boundary -- not used in this example Bd = anuga.Dirichlet_boundary( [-0.1 * scale_me, 0., 0.]) # Constant boundary values -- not used in this example #---------------------------------------------- # Associate boundary tags with boundary objects #---------------------------------------------- domain.set_boundary({'left': Br, 'right': Bd, 'top': Br, 'bottom': Br}) #------------------------------------------------------------------------------ # Produce a documentation of parameters #------------------------------------------------------------------------------ if myid == 0: parameter_file = open('parameters.tex', 'w') parameter_file.write('\\begin{verbatim}\n') from pprint import pprint pprint(domain.get_algorithm_parameters(), parameter_file, indent=4)
#end_point1=[50.0, 62.5], #losses, #width=25.0, #depth=10.0, #apron=5.0, #manning=0.013, #verbose=False) #------------------------------------------------------------------------------ # Setup boundary conditions #------------------------------------------------------------------------------ print 'Setting Boundary Conditions' Br = anuga.Reflective_boundary(domain) # Solid reflective wall Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0]) # Inflow based on Flow Depth and Approaching Momentum !!! Btus = anuga.Dirichlet_boundary([20.0, 0, 0]) # Outflow water at 10.0 Btds = anuga.Dirichlet_boundary([19.0, 0, 0]) # Outflow water at 9.0 domain.set_boundary({'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br}) #------------------------------------------------------------------------------ # Evolve system through time #------------------------------------------------------------------------------ for t in domain.evolve(yieldstep = 1, finaltime = 100): print domain.timestepping_statistics() domain.print_operator_timestepping_statistics()
def test_that_culvert_runs_rating(self): """test_that_culvert_runs_rating This test exercises the culvert and checks values outside rating curve are dealt with """ path = get_pathname_from_package('anuga.culvert_flows') path = os.path.join(path, 'tests', 'data') length = 40. width = 5. dx = dy = 1 # Resolution: Length of subdivisions on both axes points, vertices, boundary = rectangular_cross(int(length / dx), int(width / dy), len1=length, len2=width) domain = anuga.Domain(points, vertices, boundary) domain.set_name('Test_culvert') # Output name domain.set_default_order(2) #---------------------------------------------------------------------- # Setup initial conditions #---------------------------------------------------------------------- def topography(x, y): """Set up a weir A culvert will connect either side """ # General Slope of Topography z = -x / 1000 N = len(x) for i in range(N): # Sloping Embankment Across Channel if 5.0 < x[i] < 10.1: # Cut Out Segment for Culvert face if 1.0 + (x[i] - 5.0) / 5.0 < y[i] < 4.0 - (x[i] - 5.0) / 5.0: z[i] = z[i] else: z[i] += 0.5 * (x[i] - 5.0) # Sloping Segment U/S Face if 10.0 < x[i] < 12.1: z[i] += 2.5 # Flat Crest of Embankment if 12.0 < x[i] < 14.5: # Cut Out Segment for Culvert face if 2.0 - (x[i] - 12.0) / 2.5 < y[i] < 3.0 + (x[i] - 12.0) / 2.5: z[i] = z[i] else: z[i] += 2.5 - 1.0 * (x[i] - 12.0) # Sloping D/S Face return z domain.set_quantity('elevation', topography) domain.set_quantity('friction', 0.01) # Constant friction domain.set_quantity('stage', expression='elevation') # Dry initial condition filename = os.path.join(path, 'example_rating_curve.csv') culvert = Culvert_flow(domain, culvert_description_filename=filename, end_point0=[9.0, 2.5], end_point1=[13.0, 2.5], width=1.00, use_velocity_head=True, verbose=False) domain.forcing_terms.append(culvert) #----------------------------------------------------------------------- # Setup boundary conditions #----------------------------------------------------------------------- # Inflow based on Flow Depth and Approaching Momentum Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0]) Br = anuga.Reflective_boundary(domain) # Solid reflective wall Bo = anuga.Dirichlet_boundary([-5, 0, 0]) # Outflow # Upstream and downstream conditions that will exceed the rating curve # I.e produce delta_h outside the range [0, 10] specified in the the # file example_rating_curve.csv Btus = anuga.Time_boundary( domain, lambda t: [100 * num.sin(2 * pi * (t - 4) / 10), 0.0, 0.0]) Btds = anuga.Time_boundary( domain, lambda t: [-5 * (num.cos(2 * pi * (t - 4) / 20)), 0.0, 0.0]) domain.set_boundary({ 'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br }) #----------------------------------------------------------------------- # Evolve system through time #----------------------------------------------------------------------- min_delta_w = sys.maxint max_delta_w = -min_delta_w for t in domain.evolve(yieldstep=1, finaltime=25): delta_w = culvert.inlet.stage - culvert.outlet.stage if delta_w > max_delta_w: max_delta_w = delta_w if delta_w < min_delta_w: min_delta_w = delta_w pass # Check that extreme values in rating curve have been exceeded # so that we know that condition has been exercised assert min_delta_w < 0 assert max_delta_w > 10 os.remove('Test_culvert.sww')
return 2.0*ones(len(x)) domain.set_quantity('stage', height) else: domain = None #--------------------------- # Create Parallel Domain #--------------------------- domain = distribute(domain) #----------------------------------------------------------------------------- # Setup boundary conditions #------------------------------------------------------------------------------ Br = anuga.Reflective_boundary(domain) # Solid reflective wall #Bt = anuga.Transmissive_boundary(domain) # Continue all values on boundary Bd = anuga.Dirichlet_boundary([0.5, 10.0, 0.]) # Constant boundary values # Associate boundary tags with boundary objects domain.set_boundary({'left': Bd, 'right': Bd, 'top': Br, 'bottom': Br}) #------------------------------------------------------------------------------ # Produce a documentation of parameters #------------------------------------------------------------------------------ if myid == 0: parameter_file=open('parameters.tex', 'w') parameter_file.write('\\begin{verbatim}\n') from pprint import pprint pprint(domain.get_algorithm_parameters(),parameter_file,indent=4)
domain.set_quantity('stage', 0) domain.set_quantity('elevation', filename=basename + '.csv', use_cache=False, verbose=True, alpha=0.99) #------------------------------------------------------------------------------ # SETUP BOUNDARY CONDITIONS #------------------------------------------------------------------------------ print('Available boundary tags', domain.get_boundary_tags()) Br = anuga.Reflective_boundary(domain) Bd = anuga.Dirichlet_boundary([0, 0, 0]) #Bt = anuga.Flather_external_stage_zero_velocity_boundary() domain.set_boundary({'inflow': Br, 'bottom': Br, 'outflow': Bd, 'top': Br}) #domain.set_boundary({'exterior' : Bd}) # ------------------------------------------------------------------------------ # Setup inject water # ------------------------------------------------------------------------------ input_rate = 0.05 # 0.102 # i made inflow exactly the same as in DRAINS example input1_anuga_region = Region(domain, radius=1.0, center=(305694.91, 6188013.94)) input1_anuga_inlet_op = Inlet_operator(domain, input1_anuga_region, Q=input_rate)
domain.set_quantity('elevation',0.0) # Use function for elevation domain.set_quantity('friction',0.0) # Constant friction domain.set_quantity('stage',1.) # Constant negative initial stage else: domain = None #-------------------------- # Create Parallel Domain #-------------------------- domain = distribute(domain) #-------------------------- # Setup boundary conditions #-------------------------- Br=anuga.Reflective_boundary(domain) # Solid reflective wall Bd=anuga.Dirichlet_boundary([1., 1., 0.]) # Constant boundary values -- not used in this example #---------------------------------------------- # Associate boundary tags with boundary objects #---------------------------------------------- domain.set_boundary({'left': Br, 'right': Br, 'top': Bd, 'bottom':Br}) #------------------------------------------------------------------------------ # Produce a documentation of parameters #------------------------------------------------------------------------------ if myid == 0: parameter_file=open('parameters.tex', 'w') parameter_file.write('\\begin{verbatim}\n') from pprint import pprint pprint(domain.get_algorithm_parameters(),parameter_file,indent=4)
else: domain = None #============================================================================ # Create Parallel Domain #============================================================================ domain = distribute(domain) #--------- # Boundary #R = anuga.Reflective_boundary(domain) #T = anuga.Transmissive_boundary(domain) D = anuga.Dirichlet_boundary([0.0, 0.0, 0.0]) domain.set_boundary({'left': D, 'right': D, 'top': D, 'bottom': D}) #------------------------------------------------------------------------------ # Produce a documentation of parameters #------------------------------------------------------------------------------ if myid == 0: parameter_file=open('parameters.tex', 'w') parameter_file.write('\\begin{verbatim}\n') from pprint import pprint pprint(domain.get_algorithm_parameters(),parameter_file,indent=4) parameter_file.write('\\end{verbatim}\n') parameter_file.close() import time
domain.set_quantity('ymomentum', 0.0) else: domain = None #--------------------------- # Create Parallel Domain #--------------------------- domain = distribute(domain) #----------------------------------------------------------------------------- # Setup boundary conditions #------------------------------------------------------------------------------ Br = anuga.Reflective_boundary(domain) # Solid reflective wall #Bt = anuga.Transmissive_boundary(domain) # Continue all values on boundary Bd = anuga.Dirichlet_boundary([2., 4.42, 0.]) # Constant boundary values # Associate boundary tags with boundary objects domain.set_boundary({'left': Bd, 'right': Bd, 'top': Br, 'bottom': Br}) #------------------------------------------------------------------------------ # Produce a documentation of parameters #------------------------------------------------------------------------------ if myid == 0: parameter_file=open('parameters.tex', 'w') parameter_file.write('\\begin{verbatim}\n') from pprint import pprint pprint(domain.get_algorithm_parameters(),parameter_file,indent=4)
use_velocity_head=False, smoothing_timescale=30.0, logging=verbose) #------------------------------------------------------------------------------ # # Setup boundary conditions # #------------------------------------------------------------------------------ Br = anuga.Reflective_boundary(domain) # Solid reflective wall Bt = anuga.Transmissive_boundary(domain) # Transmissive boundary Bout_sub = anuga.Dirichlet_boundary( \ [-floodplain_length*floodplain_slope - chan_bankfull_depth + \ chan_initial_depth, 0., 0.]) #An outflow boundary for subcritical steady flow def outflow_stage_boundary(t): return -floodplain_length*floodplain_slope \ + chan_initial_depth - chan_bankfull_depth Bout_tmss = anuga.shallow_water.boundaries.Transmissive_momentum_set_stage_boundary( domain, function=outflow_stage_boundary) domain.set_boundary({ 'left': Br, 'right': Br, 'top1': Bout_tmss,
domain.set_quantity('stage', stage) else: domain = None #----------------------------------------------------------------------------- # create Parallel Domain #------------------------------------------------------------------------------ domain = distribute(domain) #----------------------------------------------------------------------------- # Setup boundary conditions #------------------------------------------------------------------------------ from math import sin, pi, exp Br = anuga.Reflective_boundary(domain) # Solid reflective wall Bt = anuga.Transmissive_boundary(domain) # Continue all values on boundary BdL = anuga.Dirichlet_boundary([1.0144468506259066, 1.53, 0.]) # Constant boundary values BdR = anuga.Dirichlet_boundary([0.4057809296474606, 1.53, 0.]) # Constant boundary values # Associate boundary tags with boundary objects domain.set_boundary({'left': BdL, 'right': BdR, 'top': Br, 'bottom': Br}) # w_uh_vhL= [1.0144468506259066, 1.53, 0.] # w_uh_vhR= [0.4057809296474606, 1.53, 0.] # Polygonal_set_w_uh_vh_operator(domain,w_uh_vhL,BC_polygonL) # Polygonal_set_w_uh_vh_operator(domain,w_uh_vhR,BC_polygonR) #------------------------------------------------------------------------------ # Produce a documentation of parameters #------------------------------------------------------------------------------ if myid == 0:
tsunami_source = anuga.slide_tsunami(length=35000.0, depth=project.slide_depth, slope=6.0, thickness=500.0, x0=project.slide_origin[0], y0=project.slide_origin[1], alpha=0.0, domain=domain, verbose=project.verbose) #------------------------------------------------------------------------------ # Setup boundary condition #------------------------------------------------------------------------------ print 'Available boundary tags', domain.get_boundary_tags() Bd = anuga.Dirichlet_boundary([tide, 0, 0]) # Mean water level Bs = anuga.Transmissive_stage_zero_momentum_boundary( domain) # Neutral boundary if project.scenario == 'fixed_wave': # Huge 10.94m wave starting after 60 seconds and lasting 60 minutes. Bw = anuga.Transmissive_n_momentum_zero_t_momentum_set_stage_boundary( domain=domain, function=lambda t: [(60 < t < 3660) * 10.94, 0, 0]) Bt = anuga.Time_boundary(domain=domain, function=lambda t: [(60 < t < 3660) * 11, 0, 0], default_boundary=None, verbose=False) domain.set_boundary({ 'bottom_ocean': Bd,
#apron=5.0, #use_momentum_jet=True, #use_velocity_head=False, #logging=True, #manning=0.013, #verbose=False) line = [[0.0, 5.0], [0.0, 10.0]] Q = 5.0 Inlet_operator(domain, line, Q) ##----------------------------------------------------------------------- ## Setup boundary conditions ##----------------------------------------------------------------------- ## Inflow based on Flow Depth and Approaching Momentum Bi = anuga.Dirichlet_boundary([2.0, 0.0, 0.0]) Br = anuga.Reflective_boundary(domain) # Solid reflective wall #Bo = anuga.Dirichlet_boundary([-5, 0, 0]) # Outflow ## Upstream and downstream conditions that will exceed the rating curve ## I.e produce delta_h outside the range [0, 10] specified in the the ## file example_rating_curve.csv #Btus = anuga.Time_boundary(domain, \ #lambda t: [100*num.sin(2*pi*(t-4)/10), 0.0, 0.0]) #Btds = anuga.Time_boundary(domain, \ #lambda t: [-5*(num.cos(2*pi*(t-4)/20)), 0.0, 0.0]) #domain.set_boundary({'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br}) domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br}) ##----------------------------------------------------------------------- ## Evolve system through time
domain.set_quantity('stage', stage) else: domain = None #----------------------------------------------------------------------------- # Create Parallel Domain #------------------------------------------------------------------------------ domain = distribute(domain) #----------------------------------------------------------------------------- # Setup boundary conditions #------------------------------------------------------------------------------ from math import sin, pi, exp Br = anuga.Reflective_boundary(domain) # Solid reflective wall Bt = anuga.Transmissive_boundary(domain) # Continue all values on boundary BdL = anuga.Dirichlet_boundary([0.41373588752426715, 0.18, 0.]) # Constant boundary values BdR = anuga.Dirichlet_boundary([0.33, 0.18, 0.]) # Constant boundary values # Associate boundary tags with boundary objects domain.set_boundary({'left': BdL, 'right': BdR, 'top': Br, 'bottom': Br}) #------------------------------------------------------------------------------ # Produce a documentation of parameters #------------------------------------------------------------------------------ if myid == 0: parameter_file = open('parameters.tex', 'w') parameter_file.write('\\begin{verbatim}\n') from pprint import pprint pprint(domain.get_algorithm_parameters(), parameter_file, indent=4) parameter_file.write('\\end{verbatim}\n') parameter_file.close()
def run_simulation(parallel=False, control_data=None, test_points=None, verbose=False): success = True ##----------------------------------------------------------------------- ## Setup domain ##----------------------------------------------------------------------- points, vertices, boundary = rectangular_cross(int(old_div(length, dx)), int(old_div(width, dy)), len1=length, len2=width) domain = anuga.Domain(points, vertices, boundary) #domain.set_name() # Output name domain.set_store(False) domain.set_default_order(2) ##----------------------------------------------------------------------- ## Distribute domain ##----------------------------------------------------------------------- if parallel: domain = distribute(domain) #domain.dump_triangulation("frac_op_domain.png") ##----------------------------------------------------------------------- ## Setup boundary conditions ##----------------------------------------------------------------------- domain.set_quantity('elevation', topography) domain.set_quantity('friction', 0.01) # Constant friction domain.set_quantity('stage', expression='elevation') # Dry initial condition Bi = anuga.Dirichlet_boundary([5.0, 0.0, 0.0]) Br = anuga.Reflective_boundary(domain) # Solid reflective wall domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br}) ##----------------------------------------------------------------------- ## Determine triangle index coinciding with test points ##----------------------------------------------------------------------- assert (test_points is not None) assert (len(test_points) == samples) tri_ids = [] for point in test_points: try: k = domain.get_triangle_containing_point(point) if domain.tri_full_flag[k] == 1: tri_ids.append(k) else: tri_ids.append(-1) except: tri_ids.append(-2) if verbose: print('P%d has points = %s' % (myid, tri_ids)) if not parallel: control_data = [] ################ Define Fractional Operators ########################## inlet0 = None inlet1 = None boyd_box0 = None inlet0 = Inlet_operator(domain, line0, Q0, verbose=False, label='Inlet_0') inlet1 = Inlet_operator(domain, line1, Q1, verbose=False, label='Inlet_1') # Enquiry point [ 19. 2.5] is contained in two domains in 4 proc case boyd_box0 = Boyd_box_operator(domain, end_points=[[9.0, 2.5], [19.0, 2.5]], losses=1.5, width=5.0, apron=5.0, use_momentum_jet=True, use_velocity_head=False, manning=0.013, label='Boyd_Box_0', verbose=False) #if inlet0 is not None and verbose: inlet0.print_statistics() #if inlet1 is not None and verbose: inlet1.print_statistics() if boyd_box0 is not None and verbose: print("++++", myid) boyd_box0.print_statistics() # if parallel: # factory = Parallel_operator_factory(domain, verbose = True) # # inlet0 = factory.inlet_operator_factory(line0, Q0) # inlet1 = factory.inlet_operator_factory(line1, Q1) # # boyd_box0 = factory.boyd_box_operator_factory(end_points=[[9.0, 2.5],[19.0, 2.5]], # losses=1.5, # width=1.5, # apron=5.0, # use_momentum_jet=True, # use_velocity_head=False, # manning=0.013, # verbose=False) # # else: # inlet0 = Inlet_operator(domain, line0, Q0) # inlet1 = Inlet_operator(domain, line1, Q1) # # # Enquiry point [ 19. 2.5] is contained in two domains in 4 proc case # boyd_box0 = Boyd_box_operator(domain, # end_points=[[9.0, 2.5],[19.0, 2.5]], # losses=1.5, # width=1.5, # apron=5.0, # use_momentum_jet=True, # use_velocity_head=False, # manning=0.013, # verbose=False) ####################################################################### ##----------------------------------------------------------------------- ## Evolve system through time ##----------------------------------------------------------------------- for t in domain.evolve(yieldstep=2.0, finaltime=20.0): if myid == 0 and verbose: domain.write_time() #print domain.volumetric_balance_statistics() stage = domain.get_quantity('stage') if boyd_box0 is not None and verbose: if myid == boyd_box0.master_proc: print('master_proc ', myid) boyd_box0.print_timestepping_statistics() #for i in range(samples): # if tri_ids[i] >= 0: # if verbose: print 'P%d tri %d, value = %s' %(myid, i, stage.centroid_values[tri_ids[i]]) sys.stdout.flush() pass domain.sww_merge(delete_old=True) success = True ##----------------------------------------------------------------------- ## Assign/Test Control data ##----------------------------------------------------------------------- if not parallel: stage = domain.get_quantity('stage') for i in range(samples): assert (tri_ids[i] >= 0) control_data.append(stage.centroid_values[tri_ids[i]]) if inlet0 is not None: control_data.append(inlet0.inlet.get_average_stage()) control_data.append(inlet0.inlet.get_average_xmom()) control_data.append(inlet0.inlet.get_average_ymom()) control_data.append(inlet0.inlet.get_total_water_volume()) control_data.append(inlet0.inlet.get_average_depth()) if verbose: print('P%d control_data = %s' % (myid, control_data)) else: stage = domain.get_quantity('stage') for i in range(samples): if tri_ids[i] >= 0: local_success = num.allclose(control_data[i], stage.centroid_values[tri_ids[i]]) success = success and local_success if verbose: print( 'P%d tri %d, control = %s, actual = %s, Success = %s' % (myid, i, control_data[i], stage.centroid_values[tri_ids[i]], local_success)) if inlet0 is not None: inlet_master_proc = inlet0.inlet.get_master_proc() average_stage = inlet0.inlet.get_global_average_stage() average_xmom = inlet0.inlet.get_global_average_xmom() average_ymom = inlet0.inlet.get_global_average_ymom() average_volume = inlet0.inlet.get_global_total_water_volume() average_depth = inlet0.inlet.get_global_average_depth() if myid == inlet_master_proc: if verbose: print('P%d average stage, control = %s, actual = %s' % (myid, control_data[samples], average_stage)) print('P%d average xmom, control = %s, actual = %s' % (myid, control_data[samples + 1], average_xmom)) print('P%d average ymom, control = %s, actual = %s' % (myid, control_data[samples + 2], average_ymom)) print('P%d average volume, control = %s, actual = %s' % (myid, control_data[samples + 3], average_volume)) print('P%d average depth, control = %s, actual = %s' % (myid, control_data[samples + 4], average_depth)) return control_data, success
def test_runup_sinusoid(self): """ Run a version of the validation test runup_sinusoid to ensure limiting solution has small velocity """ points, vertices, boundary = anuga.rectangular_cross(20,20, len1=1., len2=1.) domain=Domain(points,vertices,boundary) # Create Domain domain.set_flow_algorithm('DE0') domain.set_name('runup_sinusoid_v2') # Output to file runup.sww domain.set_datadir('.') # Use current folder domain.set_quantities_to_be_stored({'stage': 2, 'xmomentum': 2, 'ymomentum': 2, 'elevation': 1}) #domain.set_store_vertices_uniquely(True) #------------------ # Define topography #------------------ scale_me=1.0 def topography(x,y): return (-x/2.0 +0.05*num.sin((x+y)*50.0))*scale_me def stagefun(x,y): stge=-0.2*scale_me #+0.01*(x>0.9) return stge domain.set_quantity('elevation',topography) # Use function for elevation domain.get_quantity('elevation').smooth_vertex_values() domain.set_quantity('friction',0.03) # Constant friction domain.set_quantity('stage', stagefun) # Constant negative initial stage domain.get_quantity('stage').smooth_vertex_values() #-------------------------- # Setup boundary conditions #-------------------------- Br=anuga.Reflective_boundary(domain) # Solid reflective wall Bd=anuga.Dirichlet_boundary([-0.1*scale_me,0.,0.]) # Constant boundary values -- not used in this example #---------------------------------------------- # Associate boundary tags with boundary objects #---------------------------------------------- domain.set_boundary({'left': Br, 'right': Bd, 'top': Br, 'bottom':Br}) #------------------------------ #Evolve the system through time #------------------------------ for t in domain.evolve(yieldstep=7.0,finaltime=7.0): #print domain.timestepping_statistics() xx = domain.quantities['xmomentum'].centroid_values yy = domain.quantities['ymomentum'].centroid_values dd = domain.quantities['stage'].centroid_values - domain.quantities['elevation'].centroid_values #dd_raw=1.0*dd dd = (dd)*(dd>1.0e-03)+1.0e-03 vv = ( (xx/dd)**2 + (yy/dd)**2)**0.5 vv = vv*(dd>1.0e-03) #print 'Peak velocity is: ', vv.max(), vv.argmax() #print 'Volume is', sum(dd_raw*domain.areas) #print vv.max() assert num.all(vv<1.01e-01)
#------------------------------------------------------------------------------ # Setup initial conditions #------------------------------------------------------------------------------ def topography(x,y): return -x/15 # gentle linear bed slope domain.set_quantity('elevation', topography) # Use function for elevation domain.set_quantity('friction', 0.03) # Constant friction domain.set_quantity('stage', expression='elevation') # Dry initial condition #------------------------------------------------------------------------------ # Setup boundary conditions #------------------------------------------------------------------------------ Bi = anuga.Dirichlet_boundary([1.0, 0, 0]) # Inflow Br = anuga.Reflective_boundary(domain) # Solid reflective wall Bo = anuga.Dirichlet_boundary([-5, 0, 0]) # Outflow print domain.get_boundary_tags() domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br, 'interior': Br ,# default interior boundary tag 'downstream': Br ,# downstream building 'upstream' : Br # upstream building boundary }) #------------------------------------------------------------------------------ # Evolve system through time #------------------------------------------------------------------------------
#------------------------------------------------------------------------------ domain = distribute(domain) domain.set_store_vertices_uniquely(True) domain.set_quantities_to_be_stored({ 'elevation': 2, 'stage': 2, 'xmomentum': 2, 'ymomentum': 2 }) #------------------------------------------------------------------------------ # Setup boundary conditions on the distributed domain #------------------------------------------------------------------------------ Bi = anuga.Dirichlet_boundary([1.2, 0, 0]) # Inflow at depth Br = anuga.Reflective_boundary(domain) # Solid reflective side walls Bo = anuga.Dirichlet_boundary([-5, 0, 0]) # uncontrolled outflow domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br}) #------------------------------------------------------------------------------ # Setup sanddune erosion operator #------------------------------------------------------------------------------ if myid == 0: print '>>>>> Setting up Erosion Area(s) to test...' # power up the erosion operator from anuga import Sanddune_erosion_operator
#Initiate Vegetation operator op1 = Vegetation_operator(domain, use_diffusivity=False) #Read in vegetation rasters VegCreate('Veg_D', 'veg_diameter') VegCreate('Veg_S', 'veg_spacing') # Set Quantities op1.set_veg_quantity('Veg_S', quantity_name='veg_spacing', convert_file=False, save_file=False, load_interp=True) op1.set_veg_quantity('Veg_D', quantity_name='veg_diameter', convert_file=False, save_file=False, load_interp=True) # Define and set boundaries # Define transmissive boundary for downstream outlet Bt = anuga.Transmissive_boundary(domain) # Continue all values on boundary #Define reflective boundary for channel edges Br = anuga.Reflective_boundary(domain) # Define Dirichlet boundary for upstream inlet flow Bi = anuga.Dirichlet_boundary([inlet_elev + inlet_stage, 0, 0]) domain.set_boundary({'inlet': Bi, 'exterior': Br, 'outlet': Bt}) for t in domain.evolve(yieldstep=t_to_print, finaltime=duration): print domain.timestepping_statistics()