TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Masse_PolyMAC_CDO_Elem.cpp
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#include <Masse_PolyMAC_CDO_Elem.h>
17#include <Domaine_Cl_PolyMAC_family.h>
18#include <Champ_Elem_PolyMAC_CDO.h>
19#include <Domaine_PolyMAC_CDO.h>
20#include <TRUSTTab_parts.h>
21#include <Equation_base.h>
22#include <Neumann_paroi.h>
23#include <Matrix_tools.h>
24#include <Array_tools.h>
25#include <Milieu_base.h>
26#include <Conds_lim.h>
27
28Implemente_instanciable(Masse_PolyMAC_CDO_Elem, "Masse_PolyMAC_CDO_Elem", Masse_PolyMAC_CDO_base);
29
30Sortie& Masse_PolyMAC_CDO_Elem::printOn(Sortie& s) const { return s << que_suis_je() << " " << le_nom(); }
31
33
34//ne touche que la partie "elements"
35DoubleTab& Masse_PolyMAC_CDO_Elem::appliquer_impl(DoubleTab& sm) const
36{
37 const Domaine_PolyMAC_CDO& domaine_PolyMAC_CDO = le_dom_PolyMAC_CDO.valeur();
38 const DoubleVect& volumes = domaine_PolyMAC_CDO.volumes();
39 const DoubleVect& porosite_elem = equation().milieu().porosite_elem();
40
41 const int nb_elem = domaine_PolyMAC_CDO.nb_elem(), nb_dim = sm.nb_dim();
42 if (nb_elem == 0)
43 {
45 return sm;
46 }
47
48 if (nb_dim == 2)
49 {
50 const int nb_comp = sm.line_size(); //sm.dimension_tot(0)/nb_elem;
51 for (int num_elem = 0; num_elem < nb_elem; num_elem++)
52 for (int k = 0; k < nb_comp; k++)
53 sm(num_elem, k) /= (volumes(num_elem) * porosite_elem(num_elem));
54 }
55 else if (sm.nb_dim() == 3)
56 {
57 const int d1 = sm.dimension(1), d2 = sm.dimension(2);
58 for (int num_elem = 0; num_elem < nb_elem; num_elem++)
59 for (int k = 0; k < d1; k++)
60 for (int d = 0; d < d2; d++)
61 sm(num_elem, k, d) /= (volumes(num_elem) * porosite_elem(num_elem));
62 }
63 else
64 {
65 Cerr << "Masse_PolyMAC_CDO_Elem::appliquer ne peut pas s'appliquer a un DoubleTab a " << sm.nb_dim() << " dimensions" << finl;
67 }
69 return sm;
70}
71
72//Masse_PolyMAC_CDO_Elem est responsable des parties de la matrice n'impliquant pas la diffusion
74{
75 const Domaine_PolyMAC_CDO& domaine = le_dom_PolyMAC_CDO.valeur();
76 const Champ_Elem_PolyMAC_CDO& ch = ref_cast(Champ_Elem_PolyMAC_CDO, equation().inconnue());
77 int e, f, ne_tot = domaine.nb_elem_tot(), nf_tot = domaine.nb_faces_tot(), n, N = ch.valeurs().line_size();
78 const bool only_ne = (matrix.nb_lignes() == ne_tot);
79
80 domaine.init_m2(), ch.fcl();
81 Stencil indice(0, 2);
82
83 //partie superieure : diagonale
84 for (e = 0; e < domaine.nb_elem(); e++)
85 for (n = 0; n < N; n++)
86 indice.append_line(N * e + n, N * e + n);
87 //partie inferieure : diagonale pour les CLs de Dirichlet
88 for (f = 0; !only_ne && f < domaine.nb_faces(); f++)
89 if (no_diff_ || ch.fcl()(f, 0) > 5)
90 for (n = 0; n < N; n++)
91 indice.append_line(N * (ne_tot + f) + n, N * (ne_tot + f) + n);
92
93 tableau_trier_retirer_doublons(indice);
94 Matrix_tools::allocate_morse_matrix(N * (ne_tot + !only_ne * nf_tot), N * (ne_tot + !only_ne * nf_tot), indice, matrix);
95}
96
97DoubleTab& Masse_PolyMAC_CDO_Elem::ajouter_masse(double dt, DoubleTab& secmem, const DoubleTab& inco, int penalisation, bool use_old_volumes) const
98{
99 if (use_old_volumes)
100 {
101 Cerr << "Masse_PolyMAC_CDO_Elem::ajouter_masse : use_old_volumes is not supported." << finl;
103 }
104 const Domaine_PolyMAC_CDO& domaine = le_dom_PolyMAC_CDO.valeur();
105 const Champ_Elem_PolyMAC_CDO& ch = ref_cast(Champ_Elem_PolyMAC_CDO, equation().inconnue());
106 const Conds_lim& cls = le_dom_Cl_PolyMAC_CDO->les_conditions_limites();
107 const DoubleVect& ve = domaine.volumes(), &pe = equation().milieu().porosite_elem(), &fs = domaine.face_surfaces();
108 int e, f, ne_tot = domaine.nb_elem_tot(), n, N = inco.line_size();
109 DoubleVect coef(equation().milieu().porosite_elem());
110 coef = 1.;
112
113 ch.fcl();
114 //partie superieure : diagonale
115 for (e = 0; e < domaine.nb_elem(); e++)
116 for (n = 0; n < N; n++)
117 secmem(e, n) += coef(e) * pe(e) * ve(e) * inco(e, n) / dt;
118
119 //partie inferieure : valeur imposee pour les CLs de Neumann / Dirichlet / Echange_Impose
120 for (f = 0; secmem.dimension_tot(0) > ne_tot && f < domaine.nb_faces(); f++)
121 if (ch.fcl()(f, 0) == 4)
122 for (n = 0; n < N; n++) //Neumann_paroi
123 secmem(N * (ne_tot + f) + n) += fs(f) * ref_cast(Neumann_paroi, cls[ch.fcl()(f, 1)].valeur()).flux_impose(ch.fcl()(f, 2), n);
124 else if (ch.fcl()(f, 0) == 6)
125 for (n = 0; n < N; n++) //Dirichlet
126 secmem(N * (ne_tot + f) + n) += ref_cast(Dirichlet, cls[ch.fcl()(f, 1)].valeur()).val_imp(ch.fcl()(f, 2), n);
127
128 return secmem;
129}
130
131Matrice_Base& Masse_PolyMAC_CDO_Elem::ajouter_masse(double dt, Matrice_Base& matrice, int penalisation) const
132{
133 const Domaine_PolyMAC_CDO& domaine = le_dom_PolyMAC_CDO.valeur();
134 const Champ_Elem_PolyMAC_CDO& ch = ref_cast(Champ_Elem_PolyMAC_CDO, equation().inconnue());
135 const DoubleVect& ve = domaine.volumes(), &pe = equation().milieu().porosite_elem();
136 int e, f, ne_tot = domaine.nb_elem_tot(), n, N = ch.valeurs().line_size();
137 Matrice_Morse& mat = ref_cast(Matrice_Morse, matrice);
138 DoubleVect coef(equation().milieu().porosite_elem());
139 coef = 1.;
141
142 domaine.init_m2(), ch.fcl();
143 //partie superieure : diagonale
144 for (e = 0; e < domaine.nb_elem(); e++)
145 for (n = 0; n < N; n++)
146 mat(N * e + n, N * e + n) += coef(e) * pe(e) * ve(e) / dt; //diagonale
147
148 //partie inferieure : 1 pour les flux imposes par CLs aux faces (si diffusion) ou pour toutes les faces (sinon)
149 for (f = 0; mat.nb_lignes() > N * ne_tot && f < domaine.nb_faces(); f++)
150 if (ch.fcl()(f, 0) > 5 || no_diff_)
151 for (n = 0; n < N; n++) //Dirichlet ou Dirichlet_homogene
152 mat(N * (ne_tot + f) + n, N * (ne_tot + f) + n) += 1;
153
154 return matrice;
155}
const IntTab & fcl() const
DoubleTab & valeurs() override
Renvoie le tableau des valeurs du champ au temps courant.
classe Conds_lim Cette classe represente un vecteur de conditions aux limites.
Definition Conds_lim.h:32
classe Dirichlet Cette classe est la classe de base de la hierarchie des conditions aux limites de ty...
Definition Dirichlet.h:31
double volumes(int i) const
Definition Domaine_VF.h:113
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual const Milieu_base & milieu() const =0
DoubleTab & ajouter_masse(double dt, DoubleTab &x, const DoubleTab &y, int penalisation=1, bool use_old_volumes=false) const override
void dimensionner(Matrice_Morse &matrix) const override
DoubleTab & appliquer_impl(DoubleTab &) const override
void appliquer_coef(DoubleVect &coef) const
Classe Matrice_Base Classe de base de la hierarchie des matrices.
Classe Matrice_Morse Represente une matrice M (creuse), non necessairement carree.
int nb_lignes() const override
Return local number of lines (=size on the current proc).
static void allocate_morse_matrix(const int nb_lines, const int nb_columns, const Stencil &stencil, Matrice_Morse &matrix, const bool &attach_stencil_to_matrix=false)
DoubleVect & porosite_elem()
Definition Milieu_base.h:58
const Equation_base & equation() const
Renvoie la reference sur l'equation pointe par MorEqn::mon_equation.
Definition MorEqn.h:62
Classe Neumann_paroi Cette condition limite correspond a un flux impose pour l'equation de.
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 void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52
int nb_dim() const
Definition TRUSTTab.h:199
_SIZE_ dimension_tot(int) const override
Definition TRUSTTab.tpp:160
void append_line(_TYPE_)
Definition TRUSTTab.tpp:213
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
int line_size() const
Definition TRUSTVect.tpp:67
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")