TrioCFD 1.9.9_beta
TrioCFD documentation
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 //outside boundary faces, we do nothing and pass secmem to corriger_derivee_* (because PolyMAC_CDO has a mass matrix)
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); // otherwise we would not do the right thing
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 : error in the size of sm" << finl;
51 }
52
53 //zero out the velocity part of sm on faces with imposed velocity
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 //velocity part: velocity mass matrix if the face does not have an imposed velocity, diagonal otherwise
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 //vorticity part: diagonal if no 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 //velocity part: velocities imposed by BCs
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++) //value imposed by a Dirichlet BC
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; //homogeneous Dirichlet or Symmetry
120
121 //velocity part: 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 computed
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 imposed by 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 //velocity part: velocities imposed by BCs
151 for (f = 0; f < domaine.premiere_face_int(); f++)
152 if (ch.fcl()(f, 0) > 1)
153 mat(f, f) = 1;
154
155 //velocity part: 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 computed
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 //vorticity part: diagonal if 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
class Conds_lim This class represents a vector of boundary conditions.
Definition Conds_lim.h:32
Dirichlet This class is the base class of the hierarchy of Dirichlet-type boundary conditions.
Definition Dirichlet.h:31
int_t nb_aretes_tot() const
returns the total number of edges (real+virtual).
Definition Domaine.h:145
int nb_faces() const
Returns the total number of faces.
Definition Domaine_VF.h:471
int nb_faces_tot() const
Returns the total number of faces.
Definition Domaine_VF.h:481
int elem_faces(int i, int j) const
Returns the index of the i-th face of element num_elem; the face numbering convention is.
Definition Domaine_VF.h:542
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
Matrice_Base class - Base class of the matrix hierarchy.
Matrice_Morse class - Represents a (sparse) matrix M, not necessarily square,.
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
Returns the reference to the equation pointed to by MorEqn::mon_equation.
Definition MorEqn.h:62
static int dimension
Definition Objet_U.h:94
const Nom & que_suis_je() const
Returns the string identifying the class.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
virtual const Nom & le_nom() const
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
Definition Objet_U.cpp:317
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Base class for output streams.
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