TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Masse_DG_Elem.cpp
1/****************************************************************************
2 * Copyright (c) 2024, 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#include <Masse_DG_Elem.h>
17#include <Champ_Elem_DG.h>
18#include <TRUSTTab_parts.h>
19#include <Equation_base.h>
20#include <Matrix_tools.h>
21#include <Array_tools.h>
22#include <BasisFunction.h>
23
24Implemente_instanciable(Masse_DG_Elem, "Masse_DG_Elem", Masse_DG_base);
25
26Sortie& Masse_DG_Elem::printOn(Sortie& s) const { return s << que_suis_je() << " " << le_nom(); }
27
28Entree& Masse_DG_Elem::readOn(Entree& s) { return s; }
29
30/**
31 * @brief Applies the inverse mass matrix M^{-1} to the right-hand side vector sm in-place.
32 *
33 * @details Two strategies depending on gram_schmidt:
34 *
35 * - **Orthonormal basis** (gram_schmidt == true):
36 * Since M = diag(volume[e]), M^{-1} * sm reduces to dividing each element's
37 * DOF values by the element volume, handled by tab_divide_any_shape().
38 *
39 * - **Non-orthonormal basis** (gram_schmidt == false):
40 * For each element, the local inverse mass matrix M^{-1} is computed on-the-fly
41 * by BasisFunction::eval_invMassMatrix(). It is then applied independently to
42 * each spatial component d as a dense matrix-vector product:
43 * sm[e, d*nb_bfunc : (d+1)*nb_bfunc] = M^{-1} * sm[e, d*nb_bfunc : (d+1)*nb_bfunc]
44 * using ref_array slices to avoid data copies.
45 *
46 * After inversion, the ghost cell values are synchronized via echange_espace_virtuel().
47 *
48 * @param sm The right-hand side vector to transform in-place into M^{-1} * sm.
49 * @return A reference to sm.
50 */
51DoubleTab& Masse_DG_Elem::appliquer_impl(DoubleTab& sm) const
52{
53 if (le_dom_dg_->gram_schmidt())
54 {
55 const DoubleVect& volume = le_dom_dg_->volumes();
56
57 tab_divide_any_shape(sm, volume);
58 }
59 else
60 {
61 const Nom& nom_inco = equation().inconnue().le_nom();
62 int order = Option_DG::Get_order_for(nom_inco);
63 int dim = nom_inco.debute_par("vitesse") ? Objet_U::dimension : 1;
64
65 const BasisFunction& bfunc = le_dom_dg_->get_basisFunction(order);
66 const int nb_bfunc = bfunc.nb_bfunc();
67
68 const int quad_order = bfunc.get_default_quadrature_order();
69 const Quadrature_base& quad = le_dom_dg_->get_quadrature(quad_order);
70
71 DoubleTab res, loc;
72 DoubleTab invMsm, temp_sm;
73 invMsm.copy(sm, RESIZE_OPTIONS::COPY_INIT);
74 temp_sm.copy(sm, RESIZE_OPTIONS::COPY_INIT);
75
76 for (int num_elem = 0; num_elem < le_dom_dg_->nb_elem(); num_elem++)
77 {
78 Matrice_Dense invM = bfunc.eval_invMassMatrix(quad, num_elem);
79 for (int d = 0 ; d<dim; d++)
80 {
81 res.ref_array(temp_sm, num_elem*dim*nb_bfunc + d*nb_bfunc, nb_bfunc);
82 loc.ref_array(invMsm, num_elem*dim*nb_bfunc + d*nb_bfunc, nb_bfunc);
83
84 invM.multvect_(loc, res);
85 }
86 }
87 sm.copy(temp_sm, RESIZE_OPTIONS::COPY_INIT);
88 }
89
91
92 return sm;
93}
Manages the local polynomial basis functions for Discontinuous Galerkin elements.
const int & nb_bfunc() const
const int & get_default_quadrature_order() 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.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual const Champ_Inc_base & inconnue() const =0
const Nom & le_nom() const override
Renvoie le nom du champ.
Concrete DG mass operator for element-based unknowns.
DoubleTab & appliquer_impl(DoubleTab &) const override
Applies the inverse mass matrix M^{-1} to the right-hand side vector sm in-place.
Abstract base class for the DG mass matrix operator.
virtual DoubleVect & multvect_(const DoubleVect &, DoubleVect &) const
const Equation_base & equation() const
Renvoie la reference sur l'equation pointe par MorEqn::mon_equation.
Definition MorEqn.h:62
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
virtual int debute_par(const char *const n) const
Definition Nom.cpp:319
static int dimension
Definition Objet_U.h:99
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
virtual const Nom & le_nom() const
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
Definition Objet_U.cpp:319
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
static int Get_order_for(const Nom &n)
Definition Option_DG.cpp:70
Classe de base des flux de sortie.
Definition Sortie.h:52
void ref_array(TRUSTArray< _TYPE_, _SIZE_ > &, _SIZE_ start=0, _SIZE_ sz=-1) override
Definition TRUSTTab.tpp:332
void copy(const TRUSTTab &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:622
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")