def linearized_manufactured_solution(exact_solution, diffusion_function=None): if diffusion_function is None: diffusion_function = flux_functions.Polynomial(degree=0) # source_function could be computed with original diffusion function # or with linearized diffusion function # ? Would that make a difference? source_function = ExactOperator( exact_solution, flux_functions.Zero(), diffusion_function, flux_functions.Zero(), ) initial_condition = x_functions.FrozenT(exact_solution, 0.0) # linearize diffusion function new_diffusion_function = xt_functions.LinearizedAboutQ( diffusion_function, exact_solution ) problem = NonlinearDiffusion( new_diffusion_function, source_function, initial_condition ) problem.exact_solution = exact_solution return problem
def manufactured_solution(exact_solution): source_function = convection_diffusion.ExactOperator( exact_solution, default_flux_function, flux_functions.Zero(), flux_functions.Zero(), ) initial_condition = x_functions.FrozenT(exact_solution, 0.0) problem = ThinFilmConvection(source_function, initial_condition) problem.exact_solution = exact_solution return problem
def manufactured_solution(exact_solution, diffusion_function=None): if diffusion_function is None: diffusion_function = flux_functions.Polynomial(degree=0) source_function = ExactOperator( exact_solution, flux_functions.Zero(), diffusion_function, flux_functions.Zero(), ) initial_condition = x_functions.FrozenT(exact_solution, 0.0) problem = NonlinearDiffusion( diffusion_function, source_function, initial_condition ) problem.exact_solution = exact_solution return problem
def linearized_manufactured_solution( exact_solution, flux_function=None, diffusion_function=None, max_wavespeed=1.0 ): if flux_function is None: flux_function = flux_functions.Identity() if diffusion_function is None: diffusion_function = flux_functions.Polynomial(degree=0) # source_function could be computed with original diffusion function # or with linearized diffusion function # ? Would that make a difference? source_function = ExactOperator( exact_solution, flux_function, diffusion_function, flux_functions.Zero() ) initial_condition = x_functions.FrozenT(exact_solution, 0.0) linearized_diffusion_function = xt_functions.LinearizedAboutQ( diffusion_function, exact_solution ) problem = ConvectionDiffusion( flux_function, linearized_diffusion_function, source_function, initial_condition, max_wavespeed, ) problem.exact_solution = exact_solution return problem
def linearized_manufactured_solution( exact_solution, flux_function=None, diffusion_function=None, max_wavespeed=1.0 ): if flux_function is None: flux_function = flux_functions.Identity() if diffusion_function is None: diffusion_function = flux_functions.Polynomial(degree=0) source_function = ExactOperator( exact_solution, flux_function, diffusion_function, flux_functions.Zero() ) initial_condition = x_functions.FrozenT(exact_solution, 0.0) linearized_diffusion_function = flux_functions.LinearizedAboutQ( diffusion_function, exact_solution ) problem = ConvectionHyperDiffusion( flux_function, linearized_diffusion_function, source_function, initial_condition, max_wavespeed, ) problem.exact_solution = exact_solution return problem
def test_zero(): flux_function = flux_functions.Zero() utils.check_to_from_dict(flux_function, flux_functions) # should always give zero for q in range(-10, 10): assert flux_function(q) == 0.0 for x in range(-10, 10): assert flux_function(q, x) == 0.0 for t in range(-10, 10): assert flux_function(q, x, t) == 0.0
def __init__( self, diffusion_function=None, source_function=None, initial_condition=None ): flux_function = flux_functions.Zero() max_wavespeed = 0.0 ConvectionHyperDiffusion.__init__( self, flux_function, diffusion_function, source_function, initial_condition, max_wavespeed, )
def __init__( self, source_function=None, initial_condition=None, max_wavespeed=None ): if max_wavespeed is None: max_wavespeed = 1.0 / 3.0 diffusion_function = flux_functions.Zero() convection_hyper_diffusion.ConvectionHyperDiffusion.__init__( self, default_flux_function, diffusion_function, source_function, initial_condition, max_wavespeed, )
def test_neumann(): boundary_derivative_function = flux_functions.Zero() bc = boundary.Neumann(boundary_derivative_function) basis_ = basis.LegendreBasis1D(3) mesh_ = mesh.Mesh1DUniform(0.0, 1.0, 10) f = x_functions.Sine() dg_solution = basis_.project(f, mesh_) problem = smooth_scalar_example.SmoothScalarExample(1.0, f) riemann_solver = riemann_solvers.LocalLaxFriedrichs(problem) boundary_faces = mesh_.boundary_faces t = 0.0 flux = bc.evaluate_boundary(dg_solution, boundary_faces[0], riemann_solver, t) assert flux is not None
def __init__( self, q, flux_function=None, diffusion_function=None, source_function=None, default_t=None, ): self.q = q if flux_function is None: self.flux_function = flux_functions.Zero else: self.flux_function = flux_function if diffusion_function is None: self.diffusion_function = flux_functions.Polynomial(degree=0) else: self.diffusion_function = diffusion_function if source_function is None: self.source_function = flux_functions.Zero() else: self.source_function = source_function xt_functions.XTFunction.__init__(self)
def get_defaults( dg_solution, t, diffusion_function=None, source_function=None, q_boundary_condition=None, r_boundary_condition=None, q_numerical_flux=None, r_numerical_flux=None, quadrature_matrix_function=None, ): basis_ = dg_solution.basis mesh_ = dg_solution.mesh Q = dg_solution # default to linear diffusion with diffusion constant 1 if diffusion_function is None: diffusion_function = flux_functions.Polynomial(degree=0) # if is linear diffusion then diffusion_function will be constant is_linear = ( isinstance(diffusion_function, flux_functions.Polynomial) and diffusion_function.degree == 0 ) if is_linear: diffusion_constant = diffusion_function.coeffs[0] # default to 0 source if source_function is None: source_function = flux_functions.Zero() # default boundary conditions if q_boundary_condition is None: q_boundary_condition = boundary.Periodic() if r_boundary_condition is None: r_boundary_condition = boundary.Periodic() # Default numerical fluxes if q_numerical_flux is None: q_numerical_flux = riemann_solvers.RightSided( flux_functions.Polynomial([0.0, -1.0]) ) if r_numerical_flux is None: if is_linear: r_numerical_flux = riemann_solvers.LeftSided( flux_functions.Polynomial([0.0, -1.0 * diffusion_constant]) ) else: def wavespeed_function(x): # need to make sure q is evaluated on left side of interfaces if mesh_.is_interface(x): vertex_index = mesh_.get_vertex_index(x) left_elem_index = mesh_.faces_to_elems[vertex_index, 0] # if on left boundary if left_elem_index == -1: if isinstance(q_boundary_condition, boundary.Periodic): left_elem_index = mesh_.get_rightmost_elem_index() q = Q(mesh_.x_right, left_elem_index) else: left_elem_index = mesh_.get_leftmost_elem_index() q = Q(x, left_elem_index) else: q = Q(x, left_elem_index) else: q = Q(x) return -1.0 * diffusion_function(q, x, t) r_numerical_flux = riemann_solvers.LeftSided( flux_functions.VariableAdvection(wavespeed_function) ) # default quadrature function is to directly compute using dg_solution # and diffusion_function if quadrature_matrix_function is None: # if diffusion_function is a constant, # then quadrature_matrix_function will be constant, -e M^{-1}S^T # where e is diffusion constant if is_linear: quadrature_matrix_function = dg_utils.get_quadrature_matrix_function_matrix( -1.0 * diffusion_constant * basis_.mass_inverse_stiffness_transpose ) else: # M^{-1} \dintt{D_i}{-f(Q, x, t) R \Phi_x}{x} = B_i R_i quadrature_matrix_function = ldg_utils.get_quadrature_matrix_function( dg_solution, t, lambda q, x, t: -1.0 * diffusion_function(q, x, t) ) return ( diffusion_function, source_function, q_boundary_condition, r_boundary_condition, q_numerical_flux, r_numerical_flux, quadrature_matrix_function, )