TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Masse_PolyMAC_CDO_Face.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 <Champ_Face_PolyMAC_CDO.h>
17#include <Masse_PolyMAC_CDO_Face.h>
18#include <Domaine_Cl_PolyMAC_family.h>
19#include <Domaine_PolyMAC_CDO.h>
20#include <TRUSTTab_parts.h>
21#include <Equation_base.h>
22#include <Probleme_base.h>
23#include <Matrix_tools.h>
24#include <Array_tools.h>
25#include <Operateur.h>
26#include <Dirichlet.h>
27
28Implemente_instanciable(Masse_PolyMAC_CDO_Face, "Masse_PolyMAC_CDO_Face", Masse_PolyMAC_CDO_base);
29
30Sortie& Masse_PolyMAC_CDO_Face::printOn(Sortie& s) const { return s << que_suis_je() << " " << le_nom(); }
31
33
34DoubleTab& Masse_PolyMAC_CDO_Face::appliquer_impl(DoubleTab& sm) const
35{
36 //hors faces de bord, on ne fait rien et on passe secmem a corriger_derivee_* (car PolyMAC_CDO a une matrice de masse)
37 assert(le_dom_PolyMAC_CDO);
38 assert(le_dom_Cl_PolyMAC_CDO);
39 const Domaine_PolyMAC_CDO& domaine_PolyMAC_CDO = le_dom_PolyMAC_CDO.valeur();
40 const Champ_Face_PolyMAC_CDO& ch = ref_cast(Champ_Face_PolyMAC_CDO, equation().inconnue());
41 ch.fcl();
42
43 assert(sm.nb_dim() <= 2); // sinon on ne fait pas ce qu'il faut
44 int nb_faces_tot = domaine_PolyMAC_CDO.nb_faces_tot();
45 int nb_aretes_tot = (dimension < 3 ? domaine_PolyMAC_CDO.nb_som_tot() : domaine_PolyMAC_CDO.domaine().nb_aretes_tot()), nc = sm.line_size();
46
47 if (sm.dimension_tot(0) != nb_faces_tot && sm.dimension_tot(0) != nb_faces_tot + nb_aretes_tot)
48 {
49 Cerr << "Masse_PolyMAC_CDO_Face::appliquer : erreur dans la taille de sm" << finl;
51 }
52
53 //mise a zero de la partie vitesse de sm sur les faces a vitesse imposee
54 for (int f = 0; f < domaine_PolyMAC_CDO.nb_faces(); f++)
55 if (ch.fcl()(f, 0) > 1)
56 for (int k = 0; k < nc; k++)
57 sm(f, k) = 0;
58
59 return sm;
60}
61
63{
64 const Domaine_PolyMAC_CDO& domaine = le_dom_PolyMAC_CDO;
65 const IntTab& e_f = domaine.elem_faces();
66 const Champ_Face_PolyMAC_CDO& ch = ref_cast(Champ_Face_PolyMAC_CDO, equation().inconnue());
67 int i, j, k, e, a, f, fb, nf_tot = domaine.nb_faces_tot(), na_tot = dimension < 3 ? domaine.domaine().nb_som_tot() : domaine.domaine().nb_aretes_tot();
68 const bool only_m2 = (matrix.nb_lignes() == nf_tot);
69
70 domaine.init_m1(), domaine.init_m2(), ch.init_ra();
71 Stencil indice(0, 2);
72
73 //partie vitesses : matrice de masse des vitesses si la face n'est pas a vitesse imposee, diagonale sinon
74 for (e = 0; e < domaine.nb_elem_tot(); e++)
75 for (i = 0, j = domaine.m2d(e); j < domaine.m2d(e + 1); i++, j++)
76 if (ch.fcl()(f = e_f(e, i), 0) > 1 && f < domaine.nb_faces())
77 indice.append_line(f, f);
78 else
79 for (k = domaine.m2i(j); f < domaine.nb_faces() && k < domaine.m2i(j + 1); k++)
80 if (ch.fcl()(fb = e_f(e, domaine.m2j(k)), 0) < 2)
81 indice.append_line(f, fb);
82
83 //partie vorticites : diagonale si pas de diffusion
84 if (!only_m2)
85 for (a = 0; no_diff_ && a < (dimension < 3 ? domaine.nb_som() : domaine.domaine().nb_aretes()); a++)
86 indice.append_line(nf_tot + a, nf_tot + a);
87
88 tableau_trier_retirer_doublons(indice);
89 Matrix_tools::allocate_morse_matrix(nf_tot + !only_m2 * na_tot, nf_tot + !only_m2 * na_tot, indice, matrix);
90}
91
92DoubleTab& Masse_PolyMAC_CDO_Face::ajouter_masse(double dt, DoubleTab& secmem, const DoubleTab& inco, int penalisation, bool use_old_volumes) const
93{
94 if (use_old_volumes)
95 {
96 Cerr << "Masse_PolyMAC_CDO_Face::ajouter_masse : use_old_volumes is not supported." << finl;
98 }
99 const Domaine_PolyMAC_CDO& domaine = le_dom_PolyMAC_CDO;
100 const Champ_Face_PolyMAC_CDO& ch = ref_cast(Champ_Face_PolyMAC_CDO, equation().inconnue());
101 const Conds_lim& cls = le_dom_Cl_PolyMAC_CDO->les_conditions_limites();
102 const IntTab& e_f = domaine.elem_faces(), &f_e = domaine.face_voisins();
103 const DoubleTab& nf = domaine.face_normales();
104 const DoubleVect& fs = domaine.face_surfaces(), &pe = equation().milieu().porosite_elem(), &ve = domaine.volumes();
105 DoubleVect coef(equation().milieu().porosite_face());
106 coef = 1.;
107 int i, j, k, l, e, f, fb;
108
110
111 domaine.init_m1(), domaine.init_m2(), ch.init_ra();
112
113 //partie vitesses : vitesses imposees par CLs
114 for (f = 0; f < domaine.premiere_face_int(); f++)
115 if (ch.fcl()(f, 0) == 3 && (!polymac_flica5 || sub_type(Dirichlet, cls[ch.fcl()(f, 1)].valeur())))
116 for (k = 0, secmem(f) = 0; k < dimension; k++) //valeur imposee par une CL de type Dirichlet
117 secmem(f) += nf(f, k) * ref_cast(Dirichlet, cls[ch.fcl()(f, 1)].valeur()).val_imp(ch.fcl()(f, 2), k) / fs(f);
118 else if (ch.fcl()(f, 0) > 1)
119 secmem(f) = 0; //Dirichlet homogene ou Symetrie
120
121 //partie vitesses : m2 / dt
122 for (e = 0; e < domaine.nb_elem_tot(); e++)
123 for (i = 0, j = domaine.m2d(e); j < domaine.m2d(e + 1); i++, j++)
124 for (f = e_f(e, i), k = domaine.m2i(j); ch.fcl()(f, 0) < 2 && f < domaine.nb_faces() && k < domaine.m2i(j + 1); k++)
125 if (ch.fcl()(fb = e_f(e, domaine.m2j(k)), 0) < 2) //vfb calcule
126 secmem(f) += ve(e) * pe(e) * domaine.m2c(k) * (e == f_e(f, 0) ? 1 : -1) * (e == f_e(fb, 0) ? 1 : -1) * coef(f) * inco(fb) / dt;
127 else if (ch.fcl()(fb, 0) == 3 && (!polymac_flica5 || sub_type(Dirichlet, cls[ch.fcl()(f, 1)].valeur())))
128 for (l = 0; l < dimension; l++) //vfb impose par Dirichlet
129 secmem(f) += ve(e) * pe(e) * domaine.m2c(k) * (e == f_e(f, 0) ? 1 : -1) * (e == f_e(fb, 0) ? 1 : -1) * coef(f)
130 * ref_cast(Dirichlet, cls[ch.fcl()(fb, 1)].valeur()).val_imp(ch.fcl()(fb, 2), l) * nf(fb, l) / (fs(fb) * dt);
131
132 return secmem;
133}
134
135Matrice_Base& Masse_PolyMAC_CDO_Face::ajouter_masse(double dt, Matrice_Base& matrice, int penalisation) const
136{
137 const Domaine_PolyMAC_CDO& domaine = le_dom_PolyMAC_CDO;
138 const Champ_Face_PolyMAC_CDO& ch = ref_cast(Champ_Face_PolyMAC_CDO, equation().inconnue());
139 const IntTab& e_f = domaine.elem_faces(), &f_e = domaine.face_voisins();
140 const DoubleVect& pe = equation().milieu().porosite_elem(), &ve = domaine.volumes();
141 DoubleVect coef(equation().milieu().porosite_face());
142 coef = 1.;
143 int i, j, k, e, a, f, fb, nf_tot = domaine.nb_faces_tot();
144 Matrice_Morse& mat = ref_cast(Matrice_Morse, matrice);
145
147
148 domaine.init_m1(), domaine.init_m2(), ch.init_ra();
149
150 //partie vitesses : vitesses imposees par CLs
151 for (f = 0; f < domaine.premiere_face_int(); f++)
152 if (ch.fcl()(f, 0) > 1)
153 mat(f, f) = 1;
154
155 //partie vitesses : m2 / dt
156 for (e = 0; e < domaine.nb_elem_tot(); e++)
157 for (i = 0, j = domaine.m2d(e); j < domaine.m2d(e + 1); i++, j++)
158 for (f = e_f(e, i), k = domaine.m2i(j); ch.fcl()(f, 0) < 2 && f < domaine.nb_faces() && k < domaine.m2i(j + 1); k++)
159 if (ch.fcl()(fb = e_f(e, domaine.m2j(k)), 0) < 2) //vfb calcule
160 mat(f, fb) += ve(e) * pe(e) * domaine.m2c(k) * (e == f_e(f, 0) ? 1 : -1) * (e == f_e(fb, 0) ? 1 : -1) * coef(f) / dt;
161
162 //partie vorticites : diagonale si Op_Diff_negligeable
163 if (mat.nb_lignes() > nf_tot)
164 for (a = 0; no_diff_ && a < (dimension < 3 ? domaine.nb_som() : domaine.domaine().nb_aretes()); a++)
165 mat(nf_tot + a, nf_tot + a) = 1;
166
167 return matrice;
168}
const IntTab & fcl() const
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
int_t nb_aretes_tot() const
renvoie le nombre d'aretes total (reelles+virtuelles).
Definition Domaine.h:145
int nb_faces() const
renvoie le nombre global de faces.
Definition Domaine_VF.h:471
int nb_faces_tot() const
renvoie le nombre total de faces.
Definition Domaine_VF.h:481
int elem_faces(int i, int j) const
renvoie le numero de le ieme face de la maille num_elem la facon dont ces faces sont numerotees est
Definition Domaine_VF.h:543
const Domaine & domaine() const
int nb_som_tot() const
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
void dimensionner(Matrice_Morse &matrix) const override
DoubleTab & appliquer_impl(DoubleTab &) const override
DoubleTab & ajouter_masse(double dt, DoubleTab &x, const DoubleTab &y, int penalisation=1, bool use_old_volumes=false) 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
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 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
int line_size() const
Definition TRUSTVect.tpp:67