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 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})
#------------------------------------------------------------------------------ # 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, 'west': Bs, 'onshore': Bw, 'east': Bs }) if project.scenario == 'slide': # Boundary conditions for slide scenario domain.set_boundary({ 'bottom_ocean': Bw, 'west': Bs, 'onshore': Bd,
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')
domain = distribute(domain) #------------------------------------------------------------------------------ # Setup Operators #------------------------------------------------------------------------------ Friction_operator(domain, friction=coulomb_friction) #----------------------------------------------------------------------------- # 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 BTimeR = anuga.Time_boundary(domain,f_right) BTimeL = anuga.Time_boundary(domain,f_left) # Associate boundary tags with boundary objects domain.set_boundary({'left': BTimeL, 'right': BTimeR, 'top': Br, 'bottom': Br}) #------------------------------------------------------------------------------ # Produce a documentation of parameters #------------------------------------------------------------------------------ if myid == 0: parameter_file=open('parameters.tex', 'w') parameter_file.write('\\begin{verbatim}\n')
def f_CG(t): timing = t*sqrt(g*h0)/L # dimensionless w, u = prescribe(0.0,timing) # dimensionless wO = w*h0 # dimensional uO = u*sqrt(g*h0) # dimensional zO = -h0 # dimensional hO = wO - zO # dimensional pO = uO * hO # dimensional #[ 'stage', 'Xmomentum', 'Ymomentum'] return [wO, pO, 0.0] # dimensional 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 BTime = anuga.Time_boundary(domain,f_CG) # Associate boundary tags with boundary objects domain.set_boundary({'left': BTime, 'right': Bt, '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() #------------------------------------------------------------------------------
#------------------------------------------------------------------------------ # Setup initial conditions #------------------------------------------------------------------------------ def topography(x, y): return -x / 2 # linear bed slope #return x*(-(2.0-x)*.5) # curved bed slope domain.set_quantity('elevation', topography) # Use function for elevation domain.set_quantity('friction', 0.1) # Constant friction domain.set_quantity('stage', -0.4) # Constant negative initial stage #------------------------------------------------------------------------------ # 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.2, 0., 0.]) # Constant boundary values Bw = anuga.Time_boundary( domain=domain, # Time dependent boundary function=lambda t: [(0.1 * sin(t * 2 * pi) - 0.3) * exp(-t), 0.0, 0.0]) # Associate boundary tags with boundary objects domain.set_boundary({'left': Br, 'right': Bw, 'top': Br, 'bottom': Br}) #------------------------------------------------------------------------------ # Evolve system through time #------------------------------------------------------------------------------ for t in domain.evolve(yieldstep=0.1, finaltime=10.0): print domain.timestepping_statistics()
# -------- 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 17.135m 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) * 17.135, 0, 0]) # Option 2: Set boundary stage from predefined TMS file output from EasyWave wave_f = anuga.file_function(TS_file, domain, quantities='Attribute0') Btms = anuga.Transmissive_momentum_set_stage_boundary( domain=domain, function=lambda t: [wave_f(t), 0, 0]) # Bt used if transmissive boundary raise too small timestep exception Bt = anuga.Time_boundary(domain=domain, function=lambda t: [wave_f(t), 0, 0]) domain.set_boundary({ 'onshore': Bd, 'west': Bs, 'bottom_ocean': Btms, 'east': Bs }) if project.scenario == 'slide': # Boundary conditions for slide scenario domain.set_boundary({ 'bottom_ocean': Bw, 'west': Bs, 'onshore': Bd, 'east': Bs
bounaryStartTime = time.time() #------------------------------------------------------------------------------ # Setup boundary conditions #------------------------------------------------------------------------------ print 'Available boundary tags', domain.get_boundary_tags() # Mean water level Bd = anuga.Dirichlet_boundary([tide, 0, 0]) # Neutral boundary Bs = anuga.Transmissive_stage_zero_momentum_boundary(domain) # Define tsunami wave (in metres and seconds). the_wave = lambda t: [(20*np.sin(t*np.pi/(60*10)))*np.exp(-t/600), 0, 0] Bw = anuga.Time_boundary(domain=domain, function=the_wave) domain.set_boundary({'land_sse': Bs, 'land_s': Bs, 'bottom': Bs, 'ocean_wsw': Bw, 'ocean_w': Bw, 'ocean_wnw': Bw, 'top': Bs, 'land_nne': Bs, 'land_ese': Bs, 'land_se': Bs}) #------------------------------------------------------------------------------ # Evolve system through time
#----------------------------------------------------------------------------- # Special implementation of Coulomb friction #----------------------------------------------------------------------------- domain.forcing_terms.append(Coulomb_forcing_term) #----------------------------------------------------------------------------- # 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 BTime = anuga.Time_boundary(domain,f_right) # Associate boundary tags with boundary objects domain.set_boundary({'left': Bt, 'right': BTime, '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')
# end_point0=[record[2], record[3]], # end_point1=[record[4], record[5]], # width=record[6], # height=record[7], # culvert_routine=boyd_generalised_culvert_model, # number_of_barrels=1, # verbose=verbose) # domain.forcing_terms.append(culvert) 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 Br = anuga.Reflective_boundary(domain) # Huge 50m wave starting after 60 seconds and lasting 1 hour. Bw = anuga.Time_boundary(domain=domain, function=lambda t: [(60 < t < 3660) * 11, 0, 0]) domain.set_boundary({'east': Br, 'bottom': Br, 'west': Br, 'top': Br}) #------------------------------------------------------------------------------ # Evolve system through time #------------------------------------------------------------------------------ import time t0 = time.time() tend = project_minecraft.tend from numpy import allclose scenario = 'fixed_wave_minecraft' name = project_minecraft.outpath + 'anuga_' + scenario which_var = 2 if which_var == 0: # Stage outname = name + '_stage' quantityname = 'stage' if which_var == 1: # Absolute Momentum
def run_chennai(sim_id): project_root = os.path.abspath(os.path.dirname(__file__)) if not os.path.exists(project_root): os.makedirs(project_root) print "project_root = " + project_root inputs_dir = '%s/inputs/' % project_root if not os.path.exists(inputs_dir): os.makedirs(inputs_dir) print "inputs_dir = " + inputs_dir working_dir = '%s/working/%s/' % (project_root, sim_id) if not os.path.exists(working_dir): os.makedirs(working_dir) print "working_dir = " + working_dir outputs_dir = '%s/outputs/%s' % (project_root, sim_id) if not os.path.exists(outputs_dir): os.makedirs(outputs_dir) print "outputs_dir = " + outputs_dir # get data print "downloading data..." urllib.urlretrieve( 'http://chennaifloodmanagement.org/uploaded/layers/utm44_1arc_v3.tif', inputs_dir + 'utm44_1arc_v3.tif' ) print os.listdir(inputs_dir) # configure logging TODO: get this working! log_location = project_root + '/' + sim_id + '.log' open(log_location, 'a').close() log.console_logging_level = log.INFO log.log_logging_level = log.DEBUG log.log_filename = log_location print "# log.log_filename is: " + log.log_filename print "# log_location is: " + log_location log.debug('A message at DEBUG level') log.info('Another message, INFO level') print "# starting" bounding_polygon_01 = [ [303382.14647903712, 1488780.8996663219], [351451.89152459265, 1499834.3704521982], [378957.03975921532, 1493150.8764886451], [422656.80798244767, 1504204.3472745214], [433196.16384805075, 1471300.9923770288], [421885.63560203766, 1413463.0638462803], [408261.59021479468, 1372590.9276845511], [371245.31595511554, 1427344.16669366], [316492.0769460068, 1417833.0406686035], [303382.14647903712, 1488780.8996663219] ] boundary_tags_01 = { 'inland': [0, 1, 2, 6, 7, 8], 'ocean': [3, 4, 5] } print "# Create domain:" print "# mesh_filename = " + working_dir + 'mesh_01.msh' domain = anuga.create_domain_from_regions(bounding_polygon=bounding_polygon_01, boundary_tags=boundary_tags_01, mesh_filename=working_dir + 'mesh_01.msh', maximum_triangle_area=100000, verbose=True) domain.set_name(sim_id) domain.set_datadir(outputs_dir) poly_fun_pairs = [ [ 'Extent', inputs_dir + 'utm44_1arc_v3.tif' ] ] print "# create topography_function" print "input raster = " + inputs_dir + 'utm44_1arc_v3.tif' topography_function = qs.composite_quantity_setting_function( poly_fun_pairs, domain, nan_treatment='exception', ) print topography_function print "# set_quantity elevation" domain.set_quantity('elevation', topography_function) # Use function for elevation domain.set_quantity('friction', 0.03) # Constant friction domain.set_quantity('stage', 1) # Constant initial stage print "# all quantities set" print "# 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([-20, 0., 0.]) # Constant boundary values Bi = anuga.Dirichlet_boundary([10.0, 0, 0]) # Inflow Bw = anuga.Time_boundary( domain=domain, # Time dependent boundary function=lambda t: [(10 * sin(t * 2 * pi) - 0.3) * exp(-t), 0.0, 0.0] ) print "# Associate boundary tags with boundary objects" domain.set_boundary({'inland': Br, 'ocean': Bd}) print domain.get_boundary_tags() catchmentrainfall = Rainfall( domain=domain, rate=0.2 ) # # Note need path to File in String. # # Else assumed in same directory domain.forcing_terms.append(catchmentrainfall) print "# Evolve system through time" counter_timestep = 0 for t in domain.evolve(yieldstep=300, finaltime=6000): counter_timestep += 1 print counter_timestep print domain.timestepping_statistics() asc_out_momentum = outputs_dir + '/' + sim_id + '_momentum.asc' asc_out_depth = outputs_dir + '/' + sim_id + '_depth.asc' anuga.sww2dem(outputs_dir + '/' + sim_id + '.sww', asc_out_momentum, quantity='momentum', number_of_decimal_places=3, cellsize=30, reduction=max, verbose=True) anuga.sww2dem(outputs_dir + '/' + sim_id + '.sww', asc_out_depth, quantity='depth', number_of_decimal_places=3, cellsize=30, reduction=max, verbose=True) outputs =[asc_out_depth, asc_out_momentum] for output in outputs: print "# Convert ASCII grid to GeoTiff so geonode can import it" src_ds = gdal.Open(output) dst_filename = (output[:-3] + 'tif') print "# Create gtif instance" driver = gdal.GetDriverByName("GTiff") print "# Output to geotiff" dst_ds = driver.CreateCopy(dst_filename, src_ds, 0) print "# Properly close the datasets to flush the disk" dst_filename = None src_ds = None print "Done. Nice work."