Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
vulpes::assemble::dg Namespace Reference

Classes

class  FeExpressionUpwindFromFunctionWrapper
 Q-point based upwind flux expression built from a velocity callable. More...

Functions

double sqrtNonNegative (double x, double tol=1e-12)
 Square root of a quantity that is non-negative in exact arithmetic (squared norms, quadratic forms).
double computeDGError (double errH1int, double errJump)
 compute the total DG error by combining the H1 semi-norm error and the jump error.
template<typename MeshType, typename FeSpaceType, typename ExprType>
double integrateFeExpression (const MeshType &mesh, assemble::CellManager< MeshType, FeSpaceType > &cell_manager, const ExprType &expression, std::optional< uint32_t > quad_degree=std::nullopt)
 Integrate a scalar finite element expression over the entire domain.
template<typename MeshType, typename FeSpaceType, typename DofHandlerType, typename ExprType>
double computeL2Error (const MeshType &mesh, assemble::CellManager< MeshType, FeSpaceType > &cell_manager, const DofHandlerType &dof_handler, const la::Vector &u_h, const ExprType &u_exact_expr, std::optional< uint32_t > quad_degree=std::nullopt)
 Compute the L2 error integral between a numerical solution and an exact expression.
template<typename MeshType, typename FeSpaceType, typename DofHandlerType, typename ExprType>
double computeH1SemiError (const MeshType &mesh, assemble::CellManager< MeshType, FeSpaceType > &cell_manager, const DofHandlerType &dof_handler, const la::Vector &u_h, const ExprType &grad_u_exact_expr, std::optional< uint32_t > quad_degree=std::nullopt)
 Compute the H1 semi-norm error integral between a numerical solution and an exact gradient.
template<typename MeshType>
double computeJumpError (const dofs::DofHandler< MeshType > &dof_handler, const la::Vector &u_h, const la::SparseMatrix &matrix)
 Compute the total Jump error that is: sqrt(u_h^T matrix u_h). This is used only when the provided problem has homogeneous Dirichlet boundary conditions.
template<std::size_t Dim>
auto createPenaltyExpression (std::size_t order, double gamma)
 Create a penalty expression for DG methods.
template<std::size_t Dim, typename CellType>
double faceMeasureForPenalty (const CellType &cell, std::size_t face_id)
 Measure |F| of a face of a cell, as used by the Kb penalties: the face diameter in 2D (equal to its length) and the face area in 3D.
template<std::size_t Dim>
auto createPenaltyExpressionKb (std::size_t order, double gamma)
 Create a penalty expression for DG methods using the face's Kb.
template<std::size_t Dim>
auto createPenaltyExpressionHarmonic (std::size_t order, double gamma)
 Create a penalty expression for DG methods using the harmonic mean between the two cells.
template<std::size_t Dim, typename VelocityFunc>
auto createUpwindFlux (VelocityFunc velocity_func)
 Create an upwind flux expression from a velocity callable.
template<typename MeshType>
double computeError (const dofs::DofHandler< MeshType > &dof_handler, const la::Vector &u_h, const la::Vector &u_exact, const la::SparseMatrix &matrix)
 Compute the error between a discrete solution and an exact one.
double computeAverage (const la::Vector &u, const la::Vector &rhs_const, double domain_measure)
 Compute the spatial average of a function in modal/DG space.
template<typename MeshType>
la::Vector projectConstantOntoModalSpace (const dofs::DofHandler< MeshType > &dof_handler, double constant_value, const la::SparseMatrix &mass_matrix, const la::Vector &rhs_const)
 Project a constant value onto modal DG space using L2 projection.
template<typename MeshType>
double forceEqualMean (const dofs::DofHandler< MeshType > &dof_handler, la::Vector &u, const la::Vector &u_reference, const la::SparseMatrix &mass_matrix, const la::Vector &rhs_const, double domain_measure)
 Adjust a solution to match the average of a reference solution.
template<typename MeshType, typename CellManagerType, typename DofHandlerType, typename FeSpaceType, typename Expression>
la::Vector l2ProjectExpressionScalar (const MeshType &mesh, CellManagerType &cell_manager, const DofHandlerType &dof_handler, const FeSpaceType &fe_space, const Expression &expr, const la::SparseMatrix &mass_scalar)
 L2-project a scalar expression using a precomputed scalar mass matrix.
template<typename MeshType, typename CellManagerType, typename DofHandlerType, typename FeSpaceType, typename Expression>
la::Vector l2ProjectExpressionScalar (const MeshType &mesh, CellManagerType &cell_manager, const DofHandlerType &dof_handler, const FeSpaceType &fe_space, const Expression &expr, const la::SparseMatrix &mass_blocked, std::size_t component)
 L2-project a scalar expression using one component extracted from a blocked mass matrix.
template<std::size_t VecSize, std::size_t NFields, typename MeshType, typename CellManagerType, typename DofHandlerType, typename FeSpaceType, typename Expression>
la::Vector l2ProjectExpressionBlockedSubset (const MeshType &mesh, CellManagerType &cell_manager, const DofHandlerType &dof_handler, const FeSpaceType &fe_space, const Expression &expr, std::size_t component_offset, const la::SparseMatrix &mass_blocked)
 L2-project a vector expression into a subset of components of a blocked vector.

Function Documentation

◆ computeAverage()

double vulpes::assemble::dg::computeAverage ( const la::Vector & u,
const la::Vector & rhs_const,
double domain_measure )
inline

Compute the spatial average of a function in modal/DG space.

Parameters
uThe solution vector in modal coefficients
rhs_constThe RHS vector from assembling constant*v dx
domain_measureThe measure (volume/area) of the domain
Returns
The spatial average: (1/|Domain|) * integral of u over domain
Note
This requires rhs_const assembled from integrating the constant function 1.0 with test functions: rhs_const_i = int_K 1 * v_i dx

◆ computeDGError()

double vulpes::assemble::dg::computeDGError ( double errH1int,
double errJump )
inline

compute the total DG error by combining the H1 semi-norm error and the jump error.

Parameters
errH1intthe H1 semi-norm error
errJumpthe jump error
Returns
sqrt(errH1int^2 + errJump^2)

◆ computeError()

template<typename MeshType>
double vulpes::assemble::dg::computeError ( const dofs::DofHandler< MeshType > & dof_handler,
const la::Vector & u_h,
const la::Vector & u_exact,
const la::SparseMatrix & matrix )

Compute the error between a discrete solution and an exact one.

Template Parameters
MeshTypeType of the mesh
Parameters
dof_handlerThe dof handler associated to the discrete solution
u_hThe discrete solution vector
u_exactThe exact solution vector
matrixThe matrix used to compute the error norm, if the provided matrix is the mass matrix the computed error is the L2 error, if it is the stiffness matrix the computed error is the H1 error
Returns
The error norm

◆ computeH1SemiError()

template<typename MeshType, typename FeSpaceType, typename DofHandlerType, typename ExprType>
double vulpes::assemble::dg::computeH1SemiError ( const MeshType & mesh,
assemble::CellManager< MeshType, FeSpaceType > & cell_manager,
const DofHandlerType & dof_handler,
const la::Vector & u_h,
const ExprType & grad_u_exact_expr,
std::optional< uint32_t > quad_degree = std::nullopt )

Compute the H1 semi-norm error integral between a numerical solution and an exact gradient.

Template Parameters
MeshTypeType of the mesh
FeSpaceTypeType of the finite element space
DofHandlerTypeType of the DOF handler
ExprTypeType of the FE expression (exact gradient solution)
Parameters
meshThe computational mesh
cell_managerThe cell manager
dof_handlerThe DOF handler for the numerical solution
u_hThe numerical solution vector (DOF coefficients)
grad_u_exact_exprThe exact solution gradient as an FE expression
quad_degreePolynomial degree integrated exactly by the simplex rule; defaults to 1 + the order of the integrand, at least 2p + 7 (exact solution declared of order p + 3)
Returns
The H1 semi-norm error: sqrt(integral_Omega |grad(u_h) - grad(u_exact)|^2 dx)

◆ computeJumpError()

template<typename MeshType>
double vulpes::assemble::dg::computeJumpError ( const dofs::DofHandler< MeshType > & dof_handler,
const la::Vector & u_h,
const la::SparseMatrix & matrix )

Compute the total Jump error that is: sqrt(u_h^T matrix u_h). This is used only when the provided problem has homogeneous Dirichlet boundary conditions.

Template Parameters
MeshTypeType of the mesh
Parameters
dof_handlerThe dof handler associated to the discrete solution
u_hThe discrete solution vector
matrixThe matrix used to compute the error norm
Returns
The jump error

◆ computeL2Error()

template<typename MeshType, typename FeSpaceType, typename DofHandlerType, typename ExprType>
double vulpes::assemble::dg::computeL2Error ( const MeshType & mesh,
assemble::CellManager< MeshType, FeSpaceType > & cell_manager,
const DofHandlerType & dof_handler,
const la::Vector & u_h,
const ExprType & u_exact_expr,
std::optional< uint32_t > quad_degree = std::nullopt )

Compute the L2 error integral between a numerical solution and an exact expression.

Template Parameters
MeshTypeType of the mesh
FeSpaceTypeType of the finite element space
DofHandlerTypeType of the DOF handler
ExprTypeType of the FE expression (exact solution)
Parameters
meshThe computational mesh
cell_managerThe cell manager
dof_handlerThe DOF handler for the numerical solution
u_hThe numerical solution vector (DOF coefficients)
u_exact_exprThe exact solution as an FE expression
quad_degreePolynomial degree integrated exactly by the simplex rule; defaults to 1 + the order of the integrand, at least 2p + 7 (exact solution declared of order p + 3)
Returns
The L2 error: sqrt(integral_Omega (u_h - u_exact)^2 dx)
Note
This integrates the squared difference between the numerical solution and the exact expression, then returns the square root to get the L2 norm.

◆ createPenaltyExpression()

template<std::size_t Dim>
auto vulpes::assemble::dg::createPenaltyExpression ( std::size_t order,
double gamma )

Create a penalty expression for DG methods.

Template Parameters
DimDimension of the problem
Parameters
orderOrder of the polynomial basis
gammaPenalty parameter
Returns
Finite element expression containing the penalty value
Note
The penalty is computed as gamma * order^2 / h, where h is the cell diameter. It vanishes for order 0.

◆ createPenaltyExpressionHarmonic()

template<std::size_t Dim>
auto vulpes::assemble::dg::createPenaltyExpressionHarmonic ( std::size_t order,
double gamma )

Create a penalty expression for DG methods using the harmonic mean between the two cells.

Template Parameters
DimDimension of the problem
Parameters
orderOrder of the polynomial basis
gammaPenalty parameter
Returns
Finite element expression containing the penalty value
Note
The penalty is computed as gamma * order^2 * Cinv * (|F| / |K|), where Cinv = |K| / Kb, |F| is the face measure (length in 2D, area in 3D), |K| is the cell measure and Kb is the K flat introduced in Cangiani, Dong, H. Georgoulis, Houston (2017). The final penalty is the harmonic mean between the two cells sharing the face.

◆ createPenaltyExpressionKb()

template<std::size_t Dim>
auto vulpes::assemble::dg::createPenaltyExpressionKb ( std::size_t order,
double gamma )

Create a penalty expression for DG methods using the face's Kb.

Template Parameters
DimDimension of the problem
Parameters
orderOrder of the polynomial basis
gammaPenalty parameter
Returns
Finite element expression containing the penalty value
Note
The penalty is computed as gamma * order^2 * Cinv * (|F| / |K|), where Cinv = |K| / Kb, |F| is the face measure (length in 2D, area in 3D), |K| is the cell measure and Kb is the K flat introduced in Cangiani, Dong, H. Georgoulis, Houston (2017). It vanishes for order 0.

◆ createUpwindFlux()

template<std::size_t Dim, typename VelocityFunc>
auto vulpes::assemble::dg::createUpwindFlux ( VelocityFunc velocity_func)

Create an upwind flux expression from a velocity callable.

Template Parameters
DimDimension of the problem
VelocityFuncCallable returning Eigen::Vector<double,Dim> given a physical point Eigen::Vector<double,Dim>.
Parameters
velocity_funcCallable that takes a physical point and returns velocity vector.
Returns
Finite element expression containing the upwind flux coefficient

◆ faceMeasureForPenalty()

template<std::size_t Dim, typename CellType>
double vulpes::assemble::dg::faceMeasureForPenalty ( const CellType & cell,
std::size_t face_id )

Measure |F| of a face of a cell, as used by the Kb penalties: the face diameter in 2D (equal to its length) and the face area in 3D.

◆ forceEqualMean()

template<typename MeshType>
double vulpes::assemble::dg::forceEqualMean ( const dofs::DofHandler< MeshType > & dof_handler,
la::Vector & u,
const la::Vector & u_reference,
const la::SparseMatrix & mass_matrix,
const la::Vector & rhs_const,
double domain_measure )

Adjust a solution to match the average of a reference solution.

Template Parameters
MeshTypeType of the mesh
Parameters
dof_handlerThe DOF handler
uThe solution vector to modify (modified in place)
u_referenceThe reference solution
mass_matrixThe L2 mass matrix
rhs_constThe RHS from assembling constant*v dx
domain_measureThe measure (volume/area) of the domain
Returns
The shift value applied in physical space
Note
Use this to remove arbitrary constants from periodic/Neumann problems by forcing numerical solution to match reference solution's average.

◆ integrateFeExpression()

template<typename MeshType, typename FeSpaceType, typename ExprType>
double vulpes::assemble::dg::integrateFeExpression ( const MeshType & mesh,
assemble::CellManager< MeshType, FeSpaceType > & cell_manager,
const ExprType & expression,
std::optional< uint32_t > quad_degree = std::nullopt )

Integrate a scalar finite element expression over the entire domain.

Template Parameters
MeshTypeType of the mesh
FeSpaceTypeType of the finite element space
ExprTypeType of the FE expression to integrate
Parameters
meshThe computational mesh
cell_managerThe cell manager containing mesh and FE space information
expressionThe scalar FE expression to integrate (e.g., f(x), (u_h - u_exact)^2)
quad_degreePolynomial degree integrated exactly by the simplex rule; defaults to 1 + expression.computeOrder(). Warns above the tabled rules, where Grundmann-Moeller rules amplify roundoff.
Returns
The integral of the expression over the domain
Note
Uses ScalarExpressionIntegrator which mirrors WeakFormIntegratorSimplexify's simplification and quadrature infrastructure but evaluates expressions directly as scalars.

◆ l2ProjectExpressionBlockedSubset()

template<std::size_t VecSize, std::size_t NFields, typename MeshType, typename CellManagerType, typename DofHandlerType, typename FeSpaceType, typename Expression>
la::Vector vulpes::assemble::dg::l2ProjectExpressionBlockedSubset ( const MeshType & mesh,
CellManagerType & cell_manager,
const DofHandlerType & dof_handler,
const FeSpaceType & fe_space,
const Expression & expr,
std::size_t component_offset,
const la::SparseMatrix & mass_blocked )

L2-project a vector expression into a subset of components of a blocked vector.

Template Parameters
VecSizeNumber of projected components in the expression
NFieldsTotal number of fields in the blocked vector
MeshTypeType of the mesh
CellManagerTypeType of the cell manager
DofHandlerTypeType of the DOF handler
FeSpaceTypeType of the FE space
ExpressionType of the vector FE expression
Parameters
meshThe computational mesh
cell_managerCell manager used by the integrator
dof_handlerDOF handler for assembly and output vector
fe_spaceFE space used to build test functions
exprVector expression to project
component_offsetStart component in the blocked vector where projected values are inserted
mass_blockedBlocked mass matrix used in the L2 solve
Returns
Blocked vector with projected components written in the selected subset

◆ l2ProjectExpressionScalar() [1/2]

template<typename MeshType, typename CellManagerType, typename DofHandlerType, typename FeSpaceType, typename Expression>
la::Vector vulpes::assemble::dg::l2ProjectExpressionScalar ( const MeshType & mesh,
CellManagerType & cell_manager,
const DofHandlerType & dof_handler,
const FeSpaceType & fe_space,
const Expression & expr,
const la::SparseMatrix & mass_blocked,
std::size_t component )

L2-project a scalar expression using one component extracted from a blocked mass matrix.

Template Parameters
MeshTypeType of the mesh
CellManagerTypeType of the cell manager
DofHandlerTypeType of the DOF handler
FeSpaceTypeType of the FE space
ExpressionType of the scalar FE expression
Parameters
meshThe computational mesh
cell_managerCell manager used by the integrator
dof_handlerDOF handler for assembly and output vector
fe_spaceFE space used to build test functions
exprExpression to project
mass_blockedBlocked mass matrix containing all components
componentComponent index to extract from the blocked mass matrix
Returns
Vector of modal coefficients of the projected scalar field
Note
The component is extracted by la::extractDiagonalBlockComponent, which aborts above la::kMaxDenseExtractSize scalar rows. For larger meshes use l2ProjectExpressionBlockedSubset, or the overload above with a scalar mass matrix.

◆ l2ProjectExpressionScalar() [2/2]

template<typename MeshType, typename CellManagerType, typename DofHandlerType, typename FeSpaceType, typename Expression>
la::Vector vulpes::assemble::dg::l2ProjectExpressionScalar ( const MeshType & mesh,
CellManagerType & cell_manager,
const DofHandlerType & dof_handler,
const FeSpaceType & fe_space,
const Expression & expr,
const la::SparseMatrix & mass_scalar )

L2-project a scalar expression using a precomputed scalar mass matrix.

Template Parameters
MeshTypeType of the mesh
CellManagerTypeType of the cell manager
DofHandlerTypeType of the DOF handler
FeSpaceTypeType of the FE space
ExpressionType of the scalar FE expression
Parameters
meshThe computational mesh
cell_managerCell manager used by the integrator
dof_handlerDOF handler for assembly and output vector
fe_spaceFE space used to build test functions
exprExpression to project
mass_scalarScalar mass matrix used in the L2 solve
Returns
Vector of modal coefficients of the projected scalar field

◆ projectConstantOntoModalSpace()

template<typename MeshType>
la::Vector vulpes::assemble::dg::projectConstantOntoModalSpace ( const dofs::DofHandler< MeshType > & dof_handler,
double constant_value,
const la::SparseMatrix & mass_matrix,
const la::Vector & rhs_const )

Project a constant value onto modal DG space using L2 projection.

Template Parameters
MeshTypeType of the mesh
Parameters
dof_handlerThe DOF handler
constant_valueThe constant value to project
mass_matrixThe L2 mass matrix
rhs_constThe RHS from assembling constant*v dx
Returns
Modal coefficients representing the projected constant
Note
Solves the linear system: M * c_proj = constant_value * rhs_const. This properly projects a constant function into finite element space.

◆ sqrtNonNegative()

double vulpes::assemble::dg::sqrtNonNegative ( double x,
double tol = 1e-12 )
inline

Square root of a quantity that is non-negative in exact arithmetic (squared norms, quadratic forms).

Parameters
xThe value whose square root is taken
tolNegative values above -tol are treated as roundoff and clamped to zero; below -tol a warning is printed
Returns
sqrt(max(x, 0)), or NaN if x is NaN
Note
NaN is propagated on purpose: std::max(0.0, NaN) would return 0 and hide a diverged solution behind a zero error.