TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
BasisFunction.h
1/****************************************************************************
2* Copyright (c) 2026, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef BasisFunction_included
17#define BasisFunction_included
18
19#include <Quadrature_base.h>
20#include <Option_DG.h>
21#include <Domaine_DG.h>
22#include <Matrice_Dense.h>
23#include <Matrice_Morse.h>
24
25
26/**
27 * @brief Manages the local polynomial basis functions for Discontinuous Galerkin elements.
28 *
29 * This class builds, stores, and evaluates the local polynomial basis {phi_i} used in
30 * the DG discretization on each element. It supports orders 0, 1, and 2 in 2D
31 * (3D is not yet implemented and throws at runtime).
32 *
33 * **Basis definition**
34 * The raw (non-orthonormalized) basis is defined on each element T as scaled monomials
35 * centered at the element barycenter xp and normalized by the characteristic length h_T:
36 * - order 0: { 1 }
37 * - order 1: { 1, (x-xp)/h, (y-yp)/h }
38 * - order 2: { 1, (x-xp)/h, (y-yp)/h, xy/h^2, x^2/h^2, y^2/h^2 }
39 *
40 * **Gram-Schmidt orthonormalization**
41 * If orthonormalization is requested (gram_schmidt flag in initialize()), the raw basis
42 * is transformed into an L2-orthonormal basis on each element via the modified Gram-Schmidt
43 * process (gramSchmidt()). The change-of-basis coefficients are stored in a sparse
44 * transition_matrix_ (block-diagonal, one nb_bfunc x nb_bfunc block per element), which
45 * is then applied on-the-fly by orthonormalize() whenever a basis or gradient is evaluated.
46 *
47 * **Global DOF indexing**
48 * indices_glob_elem_(e) gives the first global DOF index for element e. For scalar
49 * fields (dim=1) this maps directly; for vector fields (dim=2 or 3) the index is scaled
50 * accordingly via the indices_glob_elem(dim) accessor.
51 *
52 * **Stabilization parameters**
53 * compute_stab_param() fills two arrays used by the SIP penalty term:
54 * - eta_elem(e): element-local penalty coefficient, computed from the polynomial order
55 * and element geometry (sharp formula for triangles, conservative estimate otherwise).
56 * - eta_facet(f): face-local penalty, equal to eta_elem for boundary faces and to the
57 * harmonic mean of the two adjacent element values for internal faces.
58 *
59 * **Evaluation methods**
60 * All eval_* methods fill a pre-allocated output DoubleTab with values at the quadrature
61 * points provided by a Quadrature_base object. If the basis is orthonormalized, the
62 * transition matrix is applied automatically after the raw evaluation.
63 *
64 * @note 3D support is declared but not yet implemented; calling any eval_* method in 3D
65 * will throw at runtime.
66 */
68{
69public:
70 BasisFunction() = default;
71 virtual ~BasisFunction() {}
72
73 void initialize(const Domaine_DG& dom, const int& order, const bool& gram_schmidt);
74
75 inline const int& get_order() const { return order_; }
76 inline const int& get_default_quadrature_order() const { return default_quad_order_; }
77 inline const IntTab& indices_glob_elem(const int dim = 1) const
78 {
79 switch (dim)
80 {
81 case 1:
82 return indices_glob_elem_;
83 case 2:
84 if (indices_glob_elem_2D_.size() == 0)
85 {
88 }
90 case 3:
91 if (indices_glob_elem_3D_.size() == 0)
92 {
95 }
97 default:
98 Cerr << "[DG] indices_glob_elem is incorrectly sized" << finl;
99 throw;
100 }
101 }
102 inline const int& nb_bfunc() const { return nb_bfunc_; }
103
104 //Evaluation of the basis functions on integration points for elements and facets
105 void eval_bfunc(const Quadrature_base& quad, const int& nelem, DoubleTab& fbasis) const;
106 void eval_bfunc_on_facets(const Quadrature_base& quad, const int& nelem, const int& num_face, DoubleTab& grad_fbasis) const;
107 void eval_bfunc(const DoubleTab& coord, const int& nelem, DoubleTab& fbasis) const;
108
109 //Evaluation of the gradient of the basis functions on integration points for elements and facets
110 void eval_grad_bfunc(const Quadrature_base& quad, const int& nelem, DoubleTab& fbasis) const;
111 void eval_grad_bfunc_on_facets(const Quadrature_base& quad, const int& nelem, const int& num_face, DoubleTab& grad_fbasis) const;
112
113 //Evaluation of the divergence of the basis functions (need to indicate which scalar component we are using) on integration points for elements and facets
114 void eval_div_bfunc_on_facets(const Quadrature_base& quad, const int& nelem, const int& num_face, DoubleTab& div_fbasis) const;
115 void eval_div_bfunc(const Quadrature_base& quad, const int& nelem, DoubleTab& div_fbasis) const;
116
117 const Matrice_Dense eval_invMassMatrix(const Quadrature_base& quad, const int& nelem) const;
118
119 inline const DoubleTab& get_eta_elem() const { return eta_elem; }
120 inline const DoubleTab& get_eta_facet() const { return eta_facet; }
121
122protected:
124 void compute_stab_param();
125
126 const Matrice_Dense build_local_mass_matrix(const Quadrature_base& quad, const int nelem) const;
127
130 void orthonormalize(const int& nelem, const int& nb_pts_integ, DoubleTab& fbasis) const;
131
132 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);
133
135 int order_ = 1;
137 bool is_diagonal_ = true;
138 int nb_bfunc_ = -1;
140
142 mutable IntTab indices_glob_elem_2D_;
143 mutable IntTab indices_glob_elem_3D_;
144
145
147
148 DoubleTab eta_elem;
149 DoubleTab eta_facet;
150
151};
152
153
154#endif /* BasisFunction_included */
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_...
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.
DoubleTab eta_elem
Matrice_Morse transition_matrix_
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.
BasisFunction()=default
void allocate_transition_matrix()
Allocates the sparsity pattern of the block-diagonal transition matrix.
const DoubleTab & get_eta_elem() const
virtual ~BasisFunction()
const IntTab & indices_glob_elem(const int dim=1) 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_div_bfunc(const Quadrature_base &quad, const int &nelem, DoubleTab &div_fbasis) const
void build_mass_matrix()
const DoubleTab & get_eta_facet() const
OBS_PTR(Domaine_DG) dom_
const int & nb_bfunc() const
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.
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.
void build_transition_matrix()
Computes and stores the Gram-Schmidt orthonormalization coefficients.
const int & get_default_quadrature_order() const
IntTab indices_glob_elem_3D_
DoubleTab eta_facet
const int & get_order() const
IntTab indices_glob_elem_2D_
void compute_stab_param()
Computes the SIP penalty stabilization parameters eta_elem and eta_facet.
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.
IntTab indices_glob_elem_
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 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.
Classe Matrice_Morse Represente une matrice M (creuse), non necessairement carree.