TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
BasisFunction Class Reference

Manages the local polynomial basis functions for Discontinuous Galerkin elements. More...

#include <BasisFunction.h>

Collaboration diagram for BasisFunction:
[legend]

Public Member Functions

 BasisFunction ()=default
virtual ~BasisFunction ()
void initialize (const Domaine_DG &dom, const int &order, const bool &gram_schmidt)
 Initializes the basis function object for a given DG domain and polynomial order.
const int & get_order () const
const int & get_default_quadrature_order () const
const IntTab & indices_glob_elem (const int dim=1) const
const int & nb_bfunc () const
void eval_bfunc (const Quadrature_base &quad, const int &nelem, DoubleTab &fbasis) const
 Evaluates all basis functions at the element quadrature points.
void eval_bfunc_on_facets (const Quadrature_base &quad, const int &nelem, const int &num_face, DoubleTab &grad_fbasis) const
 Evaluates all basis functions of element nelem at the quadrature points of face num_face.
void eval_bfunc (const DoubleTab &coord, const int &nelem, DoubleTab &fbasis) const
 Evaluates all basis functions at a set of arbitrary coordinates.
void eval_grad_bfunc (const Quadrature_base &quad, const int &nelem, DoubleTab &fbasis) const
 Evaluates the gradients of all basis functions at the element quadrature points.
void eval_grad_bfunc_on_facets (const Quadrature_base &quad, const int &nelem, const int &num_face, DoubleTab &grad_fbasis) const
 Evaluates the gradients of all basis functions of element nelem at the quadrature points of face num_face.
void eval_div_bfunc_on_facets (const Quadrature_base &quad, const int &nelem, const int &num_face, DoubleTab &div_fbasis) const
 Evaluates the divergence of the basis functions at the quadrature points of face num_face.
void eval_div_bfunc (const Quadrature_base &quad, const int &nelem, DoubleTab &div_fbasis) const
const Matrice_Dense eval_invMassMatrix (const Quadrature_base &quad, const int &nelem) const
 Computes the inverse of the local L2 mass matrix for element nelem.
const DoubleTab & get_eta_elem () const
const DoubleTab & get_eta_facet () const

Protected Member Functions

void allocate_transition_matrix ()
 Allocates the sparsity pattern of the block-diagonal transition matrix.
void compute_stab_param ()
 Computes the SIP penalty stabilization parameters eta_elem and eta_facet.
const Matrice_Dense build_local_mass_matrix (const Quadrature_base &quad, const int nelem) const
 Computes the local L2 mass matrix M_ij = integral of phi_i * phi_j on element nelem.
void build_mass_matrix ()
void build_transition_matrix ()
 Computes and stores the Gram-Schmidt orthonormalization coefficients.
void orthonormalize (const int &nelem, const int &nb_pts_integ, DoubleTab &fbasis) const
 Applies the pre-computed Gram-Schmidt transition matrix to a raw basis evaluation.
void gramSchmidt (DoubleTab &fbase, const Quadrature_base &quad, const int &num_elem, const int &current_indice, const int &nb_pts_integ, const double &volume, int index)
 Recursively orthonormalizes the local basis using the modified Gram-Schmidt process.
 OBS_PTR (Domaine_DG) dom_

Protected Attributes

int order_ = 1
bool is_orthonormalized_ = true
bool is_diagonal_ = true
int nb_bfunc_ = -1
int default_quad_order_ = -1
IntTab indices_glob_elem_
IntTab indices_glob_elem_2D_
IntTab indices_glob_elem_3D_
Matrice_Morse transition_matrix_
DoubleTab eta_elem
DoubleTab eta_facet

Detailed Description

Manages the local polynomial basis functions for Discontinuous Galerkin elements.

This class builds, stores, and evaluates the local polynomial basis {phi_i} used in the DG discretization on each element. It supports orders 0, 1, and 2 in 2D (3D is not yet implemented and throws at runtime).

Basis definition The raw (non-orthonormalized) basis is defined on each element T as scaled monomials centered at the element barycenter xp and normalized by the characteristic length h_T:

  • order 0: { 1 }
  • order 1: { 1, (x-xp)/h, (y-yp)/h }
  • order 2: { 1, (x-xp)/h, (y-yp)/h, xy/h^2, x^2/h^2, y^2/h^2 }

Gram-Schmidt orthonormalization If orthonormalization is requested (gram_schmidt flag in initialize()), the raw basis is transformed into an L2-orthonormal basis on each element via the modified Gram-Schmidt process (gramSchmidt()). The change-of-basis coefficients are stored in a sparse transition_matrix_ (block-diagonal, one nb_bfunc x nb_bfunc block per element), which is then applied on-the-fly by orthonormalize() whenever a basis or gradient is evaluated.

Global DOF indexing indices_glob_elem_(e) gives the first global DOF index for element e. For scalar fields (dim=1) this maps directly; for vector fields (dim=2 or 3) the index is scaled accordingly via the indices_glob_elem(dim) accessor.

Stabilization parameters compute_stab_param() fills two arrays used by the SIP penalty term:

  • eta_elem(e): element-local penalty coefficient, computed from the polynomial order and element geometry (sharp formula for triangles, conservative estimate otherwise).
  • eta_facet(f): face-local penalty, equal to eta_elem for boundary faces and to the harmonic mean of the two adjacent element values for internal faces.

Evaluation methods All eval_* methods fill a pre-allocated output DoubleTab with values at the quadrature points provided by a Quadrature_base object. If the basis is orthonormalized, the transition matrix is applied automatically after the raw evaluation.

Note
3D support is declared but not yet implemented; calling any eval_* method in 3D will throw at runtime.

Definition at line 67 of file BasisFunction.h.

Constructor & Destructor Documentation

◆ BasisFunction()

BasisFunction::BasisFunction ( )
default

◆ ~BasisFunction()

virtual BasisFunction::~BasisFunction ( )
inlinevirtual

Definition at line 71 of file BasisFunction.h.

Member Function Documentation

◆ allocate_transition_matrix()

void BasisFunction::allocate_transition_matrix ( )
protected

Allocates the sparsity pattern of the block-diagonal transition matrix.

Builds a stencil with a full nb_bfunc x nb_bfunc dense block for each element, then calls Matrix_tools::allocate_morse_matrix() to size transition_matrix_. The transition matrix is later filled by build_transition_matrix() with the Gram-Schmidt change-of-basis coefficients.

Definition at line 69 of file BasisFunction.cpp.

◆ build_local_mass_matrix()

const Matrice_Dense BasisFunction::build_local_mass_matrix ( const Quadrature_base & quad,
const int nelem ) const
protected

Computes the local L2 mass matrix M_ij = integral of phi_i * phi_j on element nelem.

Parameters
quadQuadrature rule used for integration.
nelemIndex of the element.
Returns
A nb_bfunc x nb_bfunc dense matrix containing the local mass matrix.

Definition at line 189 of file BasisFunction.cpp.

◆ build_mass_matrix()

void BasisFunction::build_mass_matrix ( )
protected

◆ build_transition_matrix()

void BasisFunction::build_transition_matrix ( )
protected

Computes and stores the Gram-Schmidt orthonormalization coefficients.

Iterates over all elements, evaluates the raw monomial basis at the element quadrature points, then calls gramSchmidt() to orthonormalize the basis in-place and record the change-of-basis coefficients in transition_matrix_. Sets is_orthonormalized_ to true upon completion.

Definition at line 97 of file BasisFunction.cpp.

◆ compute_stab_param()

void BasisFunction::compute_stab_param ( )
protected

Computes the SIP penalty stabilization parameters eta_elem and eta_facet.

Element parameters eta_elem(e) depend on the polynomial order and the element geometry:

  • Triangles: eta = (6/pi) * sigma^2 * (p+1)*(p+2), where sigma is the element shape parameter from Domaine_DG::get_sig(). This is a theoretically grounded lower bound for coercivity of the SIP bilinear form on triangles.
  • Other polygons/polyhedra: eta = 10*p^2, a conservative estimate pending a more geometry-aware formula.

Face parameters eta_facet(f) are derived from the adjacent element values:

  • Boundary faces: eta_facet = eta_elem of the single adjacent element.
  • Internal faces: eta_facet = harmonic mean of the two adjacent element values, providing a balanced penalty that accounts for differing element sizes or orders on each side.

Definition at line 671 of file BasisFunction.cpp.

◆ eval_bfunc() [1/2]

void BasisFunction::eval_bfunc ( const DoubleTab & coords,
const int & nelem,
DoubleTab & fbasis ) const

Evaluates all basis functions at a set of arbitrary coordinates.

Same polynomial evaluation as the quadrature-based overload but uses a caller-provided coordinate array instead of the quadrature point table. Useful for post-processing or point-wise evaluations.

Parameters
coordsInput coordinates array of shape (nb_points, dimension).
nelemElement index (used for barycenter and mesh size).
fbasisOutput array of shape (nb_bfunc, nb_points), filled in-place.
Note
Only 2D and orders 0-2 are implemented. Throws for order > 2 or 3D.

Definition at line 321 of file BasisFunction.cpp.

◆ eval_bfunc() [2/2]

void BasisFunction::eval_bfunc ( const Quadrature_base & quad,
const int & nelem,
DoubleTab & fbasis ) const

Evaluates all basis functions at the element quadrature points.

Fills fbasis(i, k) with the value of the i-th basis function at the k-th quadrature point of element nelem, using the scaled monomial basis centered at the element barycenter. If the basis is orthonormalized, the transition matrix is applied via orthonormalize().

Parameters
quadQuadrature rule providing integration point coordinates.
nelemElement index.
fbasisOutput array of shape (nb_bfunc, nb_pts_integ_max), filled in-place.
Note
Only 2D and orders 0-2 are implemented. Throws for order > 2 or 3D.

Definition at line 226 of file BasisFunction.cpp.

◆ eval_bfunc_on_facets()

void BasisFunction::eval_bfunc_on_facets ( const Quadrature_base & quad,
const int & nelem,
const int & num_face,
DoubleTab & fbasis ) const

Evaluates all basis functions of element nelem at the quadrature points of face num_face.

Same polynomial as eval_bfunc() but uses the face quadrature point coordinates instead of the element interior points. The basis is still centered at the element barycenter, so the evaluation is consistent with the interior values across the face. If the basis is orthonormalized, the transition matrix is applied via orthonormalize().

Parameters
quadQuadrature rule providing face integration point coordinates.
nelemElement index (provides barycenter and mesh size).
num_faceFace index (selects the row in the face quadrature point table).
fbasisOutput array of shape (nb_bfunc, nb_pts_integ_facets), filled in-place.
Note
Only 2D and orders 0-2 are implemented. Throws for order > 2 or 3D.

Definition at line 456 of file BasisFunction.cpp.

◆ eval_div_bfunc()

void BasisFunction::eval_div_bfunc ( const Quadrature_base & quad,
const int & nelem,
DoubleTab & div_fbasis ) const

Definition at line 370 of file BasisFunction.cpp.

◆ eval_div_bfunc_on_facets()

void BasisFunction::eval_div_bfunc_on_facets ( const Quadrature_base & quad,
const int & nelem,
const int & num_face,
DoubleTab & div_fbasis ) const

Evaluates the divergence of the basis functions at the quadrature points of face num_face.

Computes the gradient via eval_grad_bfunc_on_facets() and then rearranges the result so that div_fbasis(d, i, k) = d(phi_i)/dx_d at the k-th face quadrature point. This permuted layout is used when assembling divergence-based operators.

Parameters
quadQuadrature rule providing face integration point coordinates.
nelemElement index.
num_faceFace index.
div_fbasisOutput array of shape (nb_bfunc, nb_pts_integ_facets), filled in-place.

Definition at line 566 of file BasisFunction.cpp.

◆ eval_grad_bfunc()

void BasisFunction::eval_grad_bfunc ( const Quadrature_base & quad,
const int & nelem,
DoubleTab & grad_fbasis ) const

Evaluates the gradients of all basis functions at the element quadrature points.

Fills grad_fbasis(i, k, d) with the d-th component of grad(phi_i) at the k-th quadrature point of element nelem. The constant basis function (index 0) has a zero gradient (left implicitly as zero by the caller's initialization). If the basis is orthonormalized, the transition matrix is applied via orthonormalize().

Parameters
quadQuadrature rule providing integration point coordinates.
nelemElement index.
grad_fbasisOutput array of shape (nb_bfunc, nb_pts_integ_max, dimension), filled in-place.
Note
Only 2D and orders 1-2 are implemented. Throws for order > 2 or 3D.

Definition at line 396 of file BasisFunction.cpp.

◆ eval_grad_bfunc_on_facets()

void BasisFunction::eval_grad_bfunc_on_facets ( const Quadrature_base & quad,
const int & nelem,
const int & num_face,
DoubleTab & grad_fbasis ) const

Evaluates the gradients of all basis functions of element nelem at the quadrature points of face num_face.

Same gradient formulas as eval_grad_bfunc() but evaluated at face quadrature points. Used in the SIP consistency and symmetry terms where the normal flux { nu * grad(phi_i) } . n must be integrated over a face. If the basis is orthonormalized, the transition matrix is applied via orthonormalize().

Parameters
quadQuadrature rule providing face integration point coordinates.
nelemElement index (provides barycenter and mesh size).
num_faceFace index (selects the row in the face quadrature point table).
grad_fbasisOutput array of shape (nb_bfunc, nb_pts_integ_facets, dimension), filled in-place.
Note
Only 2D and orders 1-2 are implemented. Throws for order > 2 or 3D.

Definition at line 510 of file BasisFunction.cpp.

◆ eval_invMassMatrix()

const Matrice_Dense BasisFunction::eval_invMassMatrix ( const Quadrature_base & quad,
const int & nelem ) const

Computes the inverse of the local L2 mass matrix for element nelem.

Two strategies are used depending on the polynomial order:

  • Order 1 (2D): The 3x3 mass matrix has an analytic block structure. The (0,0) entry is 1/volume, and the lower-right 2x2 block (linear DOFs) is inverted analytically using the determinant of the moment integrals sum_x2, sum_y2, sum_xy.
  • Order 2 (2D): The full 6x6 mass matrix is assembled by build_local_mass_matrix() and then numerically inverted via Matrice_Dense::inverse().
Parameters
quadQuadrature rule used to compute the mass matrix entries.
nelemElement index.
Returns
A nb_bfunc x nb_bfunc dense matrix containing M^{-1}.
Note
3D is not yet implemented and throws at runtime.

Definition at line 594 of file BasisFunction.cpp.

◆ get_default_quadrature_order()

const int & BasisFunction::get_default_quadrature_order ( ) const
inline

Definition at line 76 of file BasisFunction.h.

◆ get_eta_elem()

const DoubleTab & BasisFunction::get_eta_elem ( ) const
inline

Definition at line 119 of file BasisFunction.h.

◆ get_eta_facet()

const DoubleTab & BasisFunction::get_eta_facet ( ) const
inline

Definition at line 120 of file BasisFunction.h.

◆ get_order()

const int & BasisFunction::get_order ( ) const
inline

Definition at line 75 of file BasisFunction.h.

◆ gramSchmidt()

void BasisFunction::gramSchmidt ( DoubleTab & fbase,
const Quadrature_base & quad,
const int & num_elem,
const int & current_indice,
const int & nb_pts_integ,
const double & volume,
int index )
protected

Recursively orthonormalizes the local basis using the modified Gram-Schmidt process.

At step index, the function:

  1. Projects fbase[index] onto all previously orthonormalized vectors fbase[0..index-1] and subtracts those projections, making fbase[index] orthogonal to all previous ones.
  2. Normalizes fbase[index] by its L2 norm (integral divided by element volume).
  3. Records each operation as a row in transition_matrix_ so that orthonormalize() can re-apply the same transform to any future raw basis evaluation without repeating the quadrature.
  4. Recurses to process index+1.
Parameters
fbaseRaw basis values at quadrature points (nb_bfunc x nb_pts_integ), modified in-place to become orthonormal.
quadQuadrature rule used to compute inner products.
num_elemGlobal element index (used to query the quadrature).
current_indiceFirst global DOF index of this element in transition_matrix_.
nb_pts_integNumber of active quadrature points for this element.
volumeVolume of the element, used for normalization.
indexCurrent basis function index being orthonormalized (0-based).

Definition at line 142 of file BasisFunction.cpp.

◆ indices_glob_elem()

const IntTab & BasisFunction::indices_glob_elem ( const int dim = 1) const
inline

Definition at line 77 of file BasisFunction.h.

◆ initialize()

void BasisFunction::initialize ( const Domaine_DG & dom,
const int & order,
const bool & gram_schmidt )

Initializes the basis function object for a given DG domain and polynomial order.

Sets up the global DOF index table indices_glob_elem_, selects the default quadrature order (3 for order 1, 5 for order 2), and, if orthonormalization is requested, allocates and builds the block-diagonal transition matrix via allocate_transition_matrix() and build_transition_matrix(). Finally computes the element and face stabilization parameters via compute_stab_param().

Parameters
domThe DG domain providing mesh geometry and connectivity.
orderPolynomial order of the basis (0, 1, or 2).
gram_schmidtIf true, the basis is L2-orthonormalized via Gram-Schmidt.

Definition at line 34 of file BasisFunction.cpp.

◆ nb_bfunc()

const int & BasisFunction::nb_bfunc ( ) const
inline

Definition at line 102 of file BasisFunction.h.

◆ OBS_PTR()

BasisFunction::OBS_PTR ( Domaine_DG )
protected

◆ orthonormalize()

void BasisFunction::orthonormalize ( const int & nelem,
const int & nb_pts_integ,
DoubleTab & fbasis ) const
protected

Applies the pre-computed Gram-Schmidt transition matrix to a raw basis evaluation.

Iterates over basis functions in reverse order (exploiting the upper-triangular structure of the transition matrix) and replaces each raw value with the linear combination given by the corresponding row of transition_matrix_. Handles both 2D arrays (scalar basis: fbasis(i, k)) and 3D arrays (gradient basis: fbasis(i, k, d)).

Parameters
nelemElement index, used to locate the block in transition_matrix_.
nb_pts_integNumber of quadrature points to transform.
fbasisBasis (or gradient) array to transform in-place.

Definition at line 277 of file BasisFunction.cpp.

Member Data Documentation

◆ default_quad_order_

int BasisFunction::default_quad_order_ = -1
protected

Definition at line 139 of file BasisFunction.h.

◆ eta_elem

DoubleTab BasisFunction::eta_elem
protected

Definition at line 148 of file BasisFunction.h.

◆ eta_facet

DoubleTab BasisFunction::eta_facet
protected

Definition at line 149 of file BasisFunction.h.

◆ indices_glob_elem_

IntTab BasisFunction::indices_glob_elem_
protected

Definition at line 141 of file BasisFunction.h.

◆ indices_glob_elem_2D_

IntTab BasisFunction::indices_glob_elem_2D_
mutableprotected

Definition at line 142 of file BasisFunction.h.

◆ indices_glob_elem_3D_

IntTab BasisFunction::indices_glob_elem_3D_
mutableprotected

Definition at line 143 of file BasisFunction.h.

◆ is_diagonal_

bool BasisFunction::is_diagonal_ = true
protected

Definition at line 137 of file BasisFunction.h.

◆ is_orthonormalized_

bool BasisFunction::is_orthonormalized_ = true
protected

Definition at line 136 of file BasisFunction.h.

◆ nb_bfunc_

int BasisFunction::nb_bfunc_ = -1
protected

Definition at line 138 of file BasisFunction.h.

◆ order_

int BasisFunction::order_ = 1
protected

Definition at line 135 of file BasisFunction.h.

◆ transition_matrix_

Matrice_Morse BasisFunction::transition_matrix_
protected

Definition at line 146 of file BasisFunction.h.


The documentation for this class was generated from the following files: