"""Simple water flow example using ANUGA Water flowing down a channel with more complex topography """ #------------------------------------------------------------------------------ # Import necessary modules #------------------------------------------------------------------------------ from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross from anuga.abstract_2d_finite_volumes.util import file_function from anuga.shallow_water import Domain from anuga.shallow_water import Reflective_boundary from anuga.shallow_water import Dirichlet_boundary from anuga.shallow_water import Time_boundary from anuga.shallow_water import Field_boundary from anuga.shallow_water.shallow_water_domain import Inflow #------------------------------------------------------------------------------ # Setup computational domain #------------------------------------------------------------------------------ length = 40. width = 5. dx = dy = .1 # Resolution: Length of subdivisions on both axes #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 = Domain(points, vertices, boundary) domain.set_name('hydro_example') # Output name domain.set_minimum_storable_height(0.0001) domain.beta_h = 0.0 domain.limit2007 = 1 #------------------------------------------------------------------------------ # Setup initial conditions #------------------------------------------------------------------------------ def topography(x,y): """Complex topography defined by a function of vectors x and y """ z = -x/10 #z = x*0.0 N = len(x) for i in range(N): #Step if 10 < x[i] < 12: z[i] += 0.4 - 0.05*y[i] #Constriction if 27 < x[i] < 29 and y[i] > 3: z[i] += 2 # Pole if (x[i] - 34)**2 + (y[i] - 2)**2 < 0.4**2: z[i] += 2 return z 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 specialised forcing terms #------------------------------------------------------------------------------ #hydrograph = Inflow(center=(1.0, 0.5*width), radius=1.0, # flow=lambda t: min(0.01*t, 0.0142)) # Tap turning up hydrograph = Inflow(center=(1.0, 0.5*width), radius=1.0, flow=file_function('Island_Pt_Rd_Meta.tms')) domain.forcing_terms.append(hydrograph) #------------------------------------------------------------------------------ # Setup boundary conditions #------------------------------------------------------------------------------ #Hydrograph = Field_boundary('Island_Pt_Rd_Meta.tms', domain, # mean_stage=0.01) Bi = Dirichlet_boundary([0.4, 0, 0]) # Inflow Br = Reflective_boundary(domain) # Solid reflective wall Bo = Dirichlet_boundary([-5, 0, 0]) # Outflow domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br}) #------------------------------------------------------------------------------ # Evolve system through time #------------------------------------------------------------------------------ domain.start_time = 2800 for t in domain.evolve(yieldstep = 1, finaltime = 32700): domain.write_time() #if domain.get_quantity('stage').\ # get_values(interpolation_points=[[10, 2.5]]) > 0: # print 'Stage > 0: Changing to outflow boundary' # domain.set_boundary({'right': Bo})