def create_equations(self): """ Creates shallow water equations """ if not hasattr(self, 'U_2d'): self.create_function_spaces() self._isfrozen = False # ----- fields self.fields.solution_2d = Function(self.function_spaces.V_2d, name='solution_2d') self.fields.h_elem_size_2d = Function(self.function_spaces.P1_2d) get_horizontal_elem_size_2d(self.fields.h_elem_size_2d) # ----- Equations self.eq_sw = shallowwater_eq.ShallowWaterEquations( self.fields.solution_2d.function_space(), self.fields.bathymetry_2d, self.options) self.eq_sw.bnd_functions = self.bnd_functions['shallow_water'] if self.options.solve_tracer: self.fields.tracer_2d = Function(self.function_spaces.Q_2d, name='tracer_2d') self.eq_tracer = tracer_eq_2d.TracerEquation2D( self.function_spaces.Q_2d, bathymetry=self.fields.bathymetry_2d, use_lax_friedrichs=self.options.use_lax_friedrichs_tracer) if self.options.use_limiter_for_tracers and self.options.polynomial_degree > 0: self.tracer_limiter = limiter.VertexBasedP1DGLimiter( self.function_spaces.Q_2d) else: self.tracer_limiter = None self._isfrozen = True # disallow creating new attributes
def create_equations(self): """ Creates shallow water equations """ if not hasattr(self, 'U_2d'): self.create_function_spaces() self._isfrozen = False # ----- fields self.fields.solution_2d = Function(self.function_spaces.V_2d, name='solution_2d') self.fields.h_elem_size_2d = Function(self.function_spaces.P1_2d) get_horizontal_elem_size_2d(self.fields.h_elem_size_2d) self.set_sipg_parameter() self.depth = DepthExpression(self.fields.bathymetry_2d, use_nonlinear_equations=self.options.use_nonlinear_equations, use_wetting_and_drying=self.options.use_wetting_and_drying, wetting_and_drying_alpha=self.options.wetting_and_drying_alpha) # ----- Equations self.eq_sw = shallowwater_eq.ShallowWaterEquations( self.fields.solution_2d.function_space(), self.depth, self.options ) self.eq_sw.bnd_functions = self.bnd_functions['shallow_water'] if self.options.solve_tracer: self.fields.tracer_2d = Function(self.function_spaces.Q_2d, name='tracer_2d') if self.options.timestepper_type == 'CrankNicolson': if self.options.use_tracer_conservative_form: self.eq_tracer = conservative_tracer_eq_2d.ConservativeTracerEquation2D( self.function_spaces.Q_2d, self.depth, use_lax_friedrichs=self.options.use_lax_friedrichs_tracer, sipg_parameter=self.options.sipg_parameter_tracer) else: self.eq_tracer = tracer_eq_2d.TracerEquation2D( self.function_spaces.Q_2d, self.depth, use_lax_friedrichs=self.options.use_lax_friedrichs_tracer, sipg_parameter=self.options.sipg_parameter_tracer) if self.options.use_limiter_for_tracers and self.options.polynomial_degree > 0: self.tracer_limiter = limiter.VertexBasedP1DGLimiter(self.function_spaces.Q_2d) else: self.tracer_limiter = None else: raise NotImplementedError("Tracer equation is currently only implemented for the CrankNicolson timestepper scheme") self._isfrozen = True # disallow creating new attributes
def create_equations(self): """ Creates shallow water equations """ if not hasattr(self, 'U_2d'): self.create_function_spaces() self._isfrozen = False # ----- fields self.fields.solution_2d = Function(self.function_spaces.V_2d, name='solution_2d') self.fields.h_elem_size_2d = Function(self.function_spaces.P1_2d) get_horizontal_elem_size_2d(self.fields.h_elem_size_2d) self.set_wetting_and_drying_alpha() self.depth = DepthExpression( self.fields.bathymetry_2d, use_nonlinear_equations=self.options.use_nonlinear_equations, use_wetting_and_drying=self.options.use_wetting_and_drying, wetting_and_drying_alpha=self.options.wetting_and_drying_alpha) # ----- Equations self.eq_sw = shallowwater_eq.ShallowWaterEquations( self.fields.solution_2d.function_space(), self.depth, self.options, ) self.eq_sw.bnd_functions = self.bnd_functions['shallow_water'] if self.options.solve_tracer: self.fields.tracer_2d = Function(self.function_spaces.Q_2d, name='tracer_2d') if self.options.use_tracer_conservative_form: self.eq_tracer = conservative_tracer_eq_2d.ConservativeTracerEquation2D( self.function_spaces.Q_2d, self.depth, use_lax_friedrichs=self.options.use_lax_friedrichs_tracer, sipg_factor=self.options.sipg_factor_tracer) else: self.eq_tracer = tracer_eq_2d.TracerEquation2D( self.function_spaces.Q_2d, self.depth, use_lax_friedrichs=self.options.use_lax_friedrichs_tracer, sipg_factor=self.options.sipg_factor_tracer) if self.options.use_limiter_for_tracers and self.options.polynomial_degree > 0: self.tracer_limiter = limiter.VertexBasedP1DGLimiter( self.function_spaces.Q_2d) else: self.tracer_limiter = None sediment_options = self.options.sediment_model_options if sediment_options.solve_suspended_sediment or sediment_options.solve_exner: uv_2d, elev_2d = self.fields.solution_2d.split() sediment_model_class = self.options.sediment_model_options.sediment_model_class self.sediment_model = sediment_model_class(self.options, self.mesh2d, uv_2d, elev_2d, self.depth) if sediment_options.solve_suspended_sediment: self.fields.sediment_2d = Function(self.function_spaces.Q_2d, name='sediment_2d') self.eq_sediment = sediment_eq_2d.SedimentEquation2D( self.function_spaces.Q_2d, self.depth, self.sediment_model, use_lax_friedrichs=self.options.use_lax_friedrichs_tracer, sipg_factor=self.options.sipg_factor_tracer, conservative=sediment_options.use_sediment_conservative_form) if self.options.use_limiter_for_tracers and self.options.polynomial_degree > 0: self.tracer_limiter = limiter.VertexBasedP1DGLimiter( self.function_spaces.Q_2d) else: self.tracer_limiter = None if sediment_options.solve_exner: self.eq_exner = exner_eq.ExnerEquation( self.fields.bathymetry_2d.function_space(), self.depth, depth_integrated_sediment=sediment_options. use_sediment_conservative_form, sediment_model=self.sediment_model) self._isfrozen = True # disallow creating new attributes
def create_equations(self): """ Creates shallow water equations """ if not hasattr(self, 'U_2d'): self.create_function_spaces() self._isfrozen = False # ----- fields self.fields.solution_2d = Function(self.function_spaces.V_2d, name='solution_2d') self.fields.h_elem_size_2d = Function(self.function_spaces.P1_2d) get_horizontal_elem_size_2d(self.fields.h_elem_size_2d) self.set_sipg_parameter() self.depth = DepthExpression( self.fields.bathymetry_2d, use_nonlinear_equations=self.options.use_nonlinear_equations, use_wetting_and_drying=self.options.use_wetting_and_drying, wetting_and_drying_alpha=self.options.wetting_and_drying_alpha) # ---- tidal farms, if any if len(self.options.tidal_turbine_farms) + len( self.options.discrete_tidal_turbine_farms) > 0: self.tidal_farms = [] p = self.function_spaces.U_2d.ufl_element().degree() quad_degree = 2 * p + 1 for subdomain, farm_options in self.options.tidal_turbine_farms.items( ): fdx = dx(subdomain, degree=quad_degree) self.tidal_farms.append( TidalTurbineFarm(farm_options.turbine_density, fdx, farm_options)) for subdomain, farm_options in self.options.discrete_tidal_turbine_farms.items( ): fdx = dx(subdomain, degree=farm_options.quadrature_degree) self.tidal_farms.append( DiscreteTidalTurbineFarm(self.mesh2d, fdx, farm_options)) else: self.tidal_farms = None # ----- Equations self.eq_sw = shallowwater_eq.ShallowWaterEquations( self.fields.solution_2d.function_space(), self.depth, self.options, tidal_farms=self.tidal_farms) self.eq_sw.bnd_functions = self.bnd_functions['shallow_water'] if self.options.solve_tracer: self.fields.tracer_2d = Function(self.function_spaces.Q_2d, name='tracer_2d') if self.options.use_tracer_conservative_form: self.eq_tracer = conservative_tracer_eq_2d.ConservativeTracerEquation2D( self.function_spaces.Q_2d, self.depth, use_lax_friedrichs=self.options.use_lax_friedrichs_tracer, sipg_parameter=self.options.sipg_parameter_tracer) else: self.eq_tracer = tracer_eq_2d.TracerEquation2D( self.function_spaces.Q_2d, self.depth, use_lax_friedrichs=self.options.use_lax_friedrichs_tracer, sipg_parameter=self.options.sipg_parameter_tracer) if self.options.use_limiter_for_tracers and self.options.polynomial_degree > 0: self.tracer_limiter = limiter.VertexBasedP1DGLimiter( self.function_spaces.Q_2d) else: self.tracer_limiter = None sediment_options = self.options.sediment_model_options if sediment_options.solve_suspended_sediment or sediment_options.solve_exner: uv_2d, elev_2d = self.fields.solution_2d.split() sediment_model_class = self.options.sediment_model_options.sediment_model_class self.sediment_model = sediment_model_class(self.options, self.mesh2d, uv_2d, elev_2d, self.depth) if sediment_options.solve_suspended_sediment: self.fields.sediment_2d = Function(self.function_spaces.Q_2d, name='sediment_2d') self.eq_sediment = sediment_eq_2d.SedimentEquation2D( self.function_spaces.Q_2d, self.depth, self.sediment_model, use_lax_friedrichs=self.options.use_lax_friedrichs_tracer, sipg_parameter=self.options.sipg_parameter_tracer, conservative=sediment_options.use_sediment_conservative_form) if self.options.use_limiter_for_tracers and self.options.polynomial_degree > 0: self.tracer_limiter = limiter.VertexBasedP1DGLimiter( self.function_spaces.Q_2d) else: self.tracer_limiter = None if sediment_options.solve_exner: self.eq_exner = exner_eq.ExnerEquation( self.fields.bathymetry_2d.function_space(), self.depth, depth_integrated_sediment=sediment_options. use_sediment_conservative_form, sediment_model=self.sediment_model) self._isfrozen = True # disallow creating new attributes