TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
PolyMAC_MPFA_discretisation.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_Fonc_Elem_PolyMAC_MPFA_TC.h>
17#include <Champ_Fonc_Elem_PolyMAC_MPFA_rot.h>
18#include <Champ_Fonc_Tabule_Elem_PolyMAC_CDO.h>
19#include <grad_Champ_Face_PolyMAC_MPFA.h>
20#include <PolyMAC_MPFA_discretisation.h>
21#include <Champ_Fonc_Elem_PolyMAC_CDO.h>
22#include <Domaine_Cl_PolyMAC_family.h>
23#include <Domaine_PolyMAC_MPFA.h>
24#include <Champ_Fonc_Tabule.h>
25#include <Schema_Temps_base.h>
26#include <Champ_Uniforme.h>
27#include <Equation_base.h>
28#include <DescStructure.h>
29#include <Milieu_base.h>
30#include <Motcle.h>
31
32Implemente_instanciable(PolyMAC_MPFA_discretisation, "PolyMAC_MPFA|PolyMAC_P0", PolyMAC_HFV_discretisation);
33// XD PolyMAC_MPFA discretisation_base PolyMAC_P0 INHERITS_BRACE PolyMAC_MPFA discretization (previously covimac
34// XD_CONT discretization compatible with pb_multi).
35
37
39
40/**
41 * @brief Creates a velocity gradient field for PolyMAC_MPFA discretization
42 *
43 * This method creates and initializes a gradient field of the velocity field,
44 * computing the tensor ∇u where u is the velocity field. The resulting field
45 * contains all components of the velocity gradient tensor.
46 *
47 * @param z Discretized domain (must be Domaine_PolyMAC_MPFA)
48 * @param zcl Discretized boundary conditions domain (must be Domaine_Cl_PolyMAC_family)
49 * @param ch_vitesse Velocity field (must be Champ_Face_PolyMAC_MPFA)
50 * @param[out] ch Output gradient field (will be typed as grad_Champ_Face_PolyMAC_MPFA)
51 *
52 * @details The gradient field components are named according to spatial dimension:
53 * - 2D: dU_phase, dV_phase for each phase
54 * - 3D: dU_phase, dV_phase, dW_phase for each phase
55 *
56 * Where phase corresponds to each line component of the velocity field.
57 *
58 * @see grad_Champ_Face_PolyMAC_MPFA for the actual gradient field implementation
59 */
60void PolyMAC_MPFA_discretisation::grad_u(const Domaine_dis_base& z, const Domaine_Cl_dis_base& zcl, const Champ_Inc_base& ch_vitesse, OWN_PTR(Champ_Fonc_base) &ch) const
61{
62 const Champ_Face_PolyMAC_MPFA& vit = ref_cast(Champ_Face_PolyMAC_MPFA, ch_vitesse);
63 const Domaine_PolyMAC_MPFA& domaine_poly = ref_cast(Domaine_PolyMAC_MPFA, z);
64 const Domaine_Cl_PolyMAC_family& domaine_cl_poly = ref_cast(Domaine_Cl_PolyMAC_family, zcl);
65
66 ch.typer("grad_Champ_Face_PolyMAC_MPFA");
67
68 grad_Champ_Face_PolyMAC_MPFA& ch_grad_u = ref_cast(grad_Champ_Face_PolyMAC_MPFA, ch.valeur()); //
69
70 ch_grad_u.associer_domaine_dis_base(domaine_poly);
71 ch_grad_u.associer_domaine_Cl_dis_base(domaine_cl_poly);
72 ch_grad_u.associer_champ(vit);
73 ch_grad_u.nommer("gradient_vitesse");
74 ch_grad_u.fixer_nb_comp(dimension * dimension * vit.valeurs().line_size());
75
76 for (int n = 0; n < ch_grad_u.valeurs().line_size(); n++)
77 {
78 Nom phase = Nom(n);
79 if (dimension == 2)
80 {
81 ch_grad_u.fixer_nom_compo(dimension * n + 0, Nom("dU_") + phase); // dU
82 ch_grad_u.fixer_nom_compo(dimension * n + 1, Nom("dV_") + phase); // dV
83 }
84 else
85 {
86 ch_grad_u.fixer_nom_compo(dimension * n + 0, Nom("dU_") + phase); // dU
87 ch_grad_u.fixer_nom_compo(dimension * n + 1, Nom("dV_") + phase); // dV
88 ch_grad_u.fixer_nom_compo(dimension * n + 2, Nom("dW_") + phase); // dW
89 }
90 }
91 ch_grad_u.fixer_nature_du_champ(multi_scalaire); // more precisely: tensorial
92 ch_grad_u.fixer_nb_valeurs_nodales(-1);
93 ch_grad_u.fixer_unite("s-1");
94 ch_grad_u.changer_temps(-1); // so it is calculated at time 0
95}
96
97/**
98 * @brief Creates a shear rate field for PolyMAC_MPFA discretization
99 *
100 * This method creates and initializes a field representing the shear rate magnitude,
101 * which is derived from the velocity gradient tensor. The shear rate is computed
102 * as the magnitude of the strain rate tensor.
103 *
104 * @param z Discretized domain (must be Domaine_PolyMAC_MPFA)
105 * @param zcl Discretized boundary conditions domain
106 * @param ch_vitesse Velocity field (must be Champ_Face_PolyMAC_MPFA)
107 * @param[out] ch Output shear rate field (will be typed as Champ_Fonc_Elem_PolyMAC_MPFA_TC)
108 *
109 * @details The shear rate field contains one scalar component per phase,
110 * named "Taux_cisaillement_phase" where phase is the phase index.
111 */
113{
114 const Champ_Face_PolyMAC_MPFA& vit = ref_cast(Champ_Face_PolyMAC_MPFA, ch_vitesse);
115// const Domaine_PolyMAC_MPFA& domaine_poly = ref_cast(Domaine_PolyMAC_MPFA, z);
116 const Domaine_PolyMAC_MPFA& domaine = ref_cast(Domaine_PolyMAC_MPFA, vit.domaine_dis_base());
117
118 ch.typer("Champ_Fonc_Elem_PolyMAC_MPFA_TC");
119 Champ_Fonc_Elem_PolyMAC_MPFA_TC& ch_grad_u = ref_cast(Champ_Fonc_Elem_PolyMAC_MPFA_TC, ch.valeur()); //
120
121 ch_grad_u.associer_domaine_dis_base(domaine);
122 ch_grad_u.associer_champ(vit);
123 ch_grad_u.nommer("Taux_cisaillement");
124 int N = vit.valeurs().line_size();
125 ch_grad_u.fixer_nb_comp(N);
126 for (int n = 0; n < N; n++)
127 {
128 Nom phase = Nom(n);
129 ch_grad_u.fixer_nom_compo(n, Nom("Taux_cisaillement_") + phase);
130 }
131 ch_grad_u.fixer_nature_du_champ(scalaire); // more precisely: tensorial
132 ch_grad_u.fixer_nb_valeurs_nodales(domaine.nb_elem());
133 ch_grad_u.fixer_unite("s-1");
134 ch_grad_u.changer_temps(-1); // so it is calculated at time 0
135}
136
137/**
138 * @brief Creates a vorticity field for PolyMAC_MPFA discretization
139 *
140 * This method creates and initializes a vorticity field, which represents
141 * the curl of the velocity field (∇ × u). The field structure depends on
142 * the spatial dimension.
143 *
144 * @param sch Time scheme (used for temporal integration context)
145 * @param ch_vitesse Velocity field (must be Champ_Face_PolyMAC_MPFA)
146 * @param[out] ch Output vorticity field (will be typed as Champ_Fonc_Elem_PolyMAC_MPFA_rot)
147 *
148 * @details Vorticity field structure by dimension:
149 * - 2D: Scalar field with N components (one per phase)
150 * Represents the z-component of curl(u)
151 * - 3D: Vector field with 3×N components
152 * Represents full curl(u) = (ωx, ωy, ωz) for each phase
153 *
154 * @note Component naming convention:
155 * - Single phase (N=1): "vorticitex", "vorticitey", "vorticitez" for 3D
156 * - Multiple phases: "vorticite_0", "vorticite_1", etc. with offset indexing
157 */
159{
160 const Champ_Face_PolyMAC_MPFA& vit = ref_cast(Champ_Face_PolyMAC_MPFA, ch_vitesse);
161 const Domaine_PolyMAC_MPFA& domaine = ref_cast(Domaine_PolyMAC_MPFA, vit.domaine_dis_base());
162 int N = vit.valeurs().line_size();
163
164 ch.typer("Champ_Fonc_Elem_PolyMAC_MPFA_rot");
166
167 ch_rot_u.associer_domaine_dis_base(domaine);
168 ch_rot_u.associer_champ(vit);
169 ch_rot_u.nommer("vorticite");
170
171 if (dimension == 2)
172 {
173 ch_rot_u.fixer_nature_du_champ(scalaire);
174 ch_rot_u.fixer_nb_comp(N);
175 }
176 else if (dimension == 3)
177 {
178 ch_rot_u.fixer_nature_du_champ(vectoriel);
179 ch_rot_u.fixer_nb_comp(dimension * N);
180 std::string nom_compo = "vorticite";
181 if (N == 1)
182 {
183 std::vector<std::string> dir = { "x", "y", "z" };
184 for (int d = 0; d < dimension; d++)
185 ch_rot_u.fixer_nom_compo(d, nom_compo + dir[d]);
186 }
187 else
188 {
189 for (int n = 0; n < N; n++)
190 {
191 for (int d = 0; d < dimension; d++)
192 {
193 int offset = dimension * n + d;
194 ch_rot_u.fixer_nom_compo(offset, nom_compo + "_" + std::to_string(offset));
195 }
196 }
197 }
198 }
199 else
200 abort();
201
202 ch_rot_u.fixer_nb_valeurs_nodales(domaine.nb_elem());
203 ch_rot_u.fixer_unite("s-1");
204 ch_rot_u.changer_temps(-1); // so it is calculated at time 0
205}
206
207/**
208 * @brief Creates a residue field for equation solving diagnostics
209 *
210 * This method creates a field to store the residue of an equation system,
211 * which is useful for monitoring convergence and numerical solution quality.
212 * The residue represents the difference between the left and right hand sides
213 * of the discretized equation.
214 *
215 * @param z Discretized domain
216 * @param ch_inco Unknown field for which the residue is computed
217 * @param[out] champ Output residue field
218 *
219 * @note For non-face fields, the method delegates to the parent class
220 * PolyMAC_HFV_discretisation::residu()
221 */
222void PolyMAC_MPFA_discretisation::residu(const Domaine_dis_base& z, const Champ_Inc_base& ch_inco, OWN_PTR(Champ_Fonc_base) &champ) const
223{
224 Nom ch_name(ch_inco.le_nom());
225 ch_name += "_residu";
226 Cerr << "Discretization of " << ch_name << finl;
227
228 Nom type_ch = ch_inco.que_suis_je();
229 if (type_ch.debute_par("Champ_Face"))
230 {
231 Motcle loc = "champ_face";
232 Noms nom(1), unites(1);
233 nom[0] = ch_name;
234 unites[0] = "units_not_defined";
235 int nb_comp = ch_inco.valeurs().line_size() * dimension;
236
237 discretiser_champ(loc, z, vectoriel, nom, unites, nb_comp, ch_inco.temps(), champ);
238
239 Champ_Fonc_base& ch_fonc = ref_cast(Champ_Fonc_base, champ.valeur());
240 DoubleTab& tab = ch_fonc.valeurs();
241 tab = -10000.0;
242 Cerr << "[Information] Discretisation_base::residu : the residue is set to -10000.0 at initial time" << finl;
243 }
244
245 else
246 PolyMAC_HFV_discretisation::residu(z, ch_inco, champ);
247}
DoubleTab & valeurs() override
Overrides Champ_base::valeurs() Returns the array of values.
: class Champ_Face_PolyMAC_MPFA
class Champ_Fonc_Elem_PolyMAC_MPFA_TC for the calculation of the shear rate
void associer_champ(const Champ_Face_PolyMAC_MPFA &ch)
class Champ_Fonc_Elem_PolyMAC_MPFA_rot for the calculation of the vorticity.
void associer_champ(const Champ_Face_PolyMAC_MPFA &cha)
int fixer_nb_valeurs_nodales(int n) override
Sets the number of degrees of freedom per component.
class Champ_Fonc_base Base class of fields that are functions of a calculated quantity
void associer_domaine_dis_base(const Domaine_dis_base &) override
Class Champ_Inc_base.
const Domaine_dis_base & domaine_dis_base() const override
DoubleTab & valeurs() override
Returns the array of field values at the current time.
virtual double changer_temps(const double t)
Sets the time at which the field is defined.
double temps() const
Returns the time of the field.
class Domaine_Cl_dis_base Domaine_Cl_dis_base objects represent discretized boundary conditions
class Domaine_dis_base This class is the base of the hierarchy of discretized domains.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual void fixer_nb_comp(int i)
Sets the number of components of the field.
const Nom & le_nom() const override
Returns the name of the field.
void nommer(const Nom &) override
Gives a name to the field.
virtual const Nom & fixer_unite(const Nom &)
Specifies the unit of a scalar field or whose all components have the same unit.
virtual Nature_du_champ fixer_nature_du_champ(Nature_du_champ nat)
Sets the nature of a field: scalar, multiscalar, vectorial.
virtual const Nom & fixer_nom_compo(int, const Nom &)
Sets the name of the i-th component of the field.
A character string (Nom) in uppercase.
Definition Motcle.h:26
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
virtual int debute_par(const char *const n) const
Definition Nom.cpp:314
An array of character strings (VECT(Nom)).
Definition Noms.h:26
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 Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
void residu(const Domaine_dis_base &z, const Champ_Inc_base &ch_inco, OWN_PTR(Champ_Fonc_base)&champ) const override
void discretiser_champ(const Motcle &directive, const Domaine_dis_base &z, Nature_du_champ nature, const Noms &nom, const Noms &unite, int nb_comp, int nb_pas_dt, double temps, OWN_PTR(Champ_Inc_base)&champ, const Nom &sous_type=NOM_VIDE) const override
Discretizes a field for PolyMAC_HFV based on a discretization directive.
void grad_u(const Domaine_dis_base &z, const Domaine_Cl_dis_base &zcl, const Champ_Inc_base &ch_vitesse, OWN_PTR(Champ_Fonc_base)&ch) const override
Creates a velocity gradient field for PolyMAC_MPFA discretization.
void residu(const Domaine_dis_base &z, const Champ_Inc_base &ch_inco, OWN_PTR(Champ_Fonc_base)&champ) const override
Creates a residue field for equation solving diagnostics.
void creer_champ_vorticite(const Schema_Temps_base &, const Champ_Inc_base &, OWN_PTR(Champ_Fonc_base)&) const override
Creates a vorticity field for PolyMAC_MPFA discretization.
void taux_cisaillement(const Domaine_dis_base &, const Domaine_Cl_dis_base &, const Champ_Inc_base &, OWN_PTR(Champ_Fonc_base)&) const override
Creates a shear rate field for PolyMAC_MPFA discretization.
static void abort()
Abort routine for TRUST on a fatal error.
Definition Process.cpp:573
class Schema_Temps_base
Base class for output streams.
Definition Sortie.h:52
int line_size() const
Definition TRUSTVect.tpp:67
class grad_Champ_Face_PolyMAC_MPFA for the calculation of the gradient.
void associer_champ(const Champ_Face_PolyMAC_MPFA &ch)
void associer_domaine_Cl_dis_base(const Domaine_Cl_dis_base &le_dom_Cl_dis_base)
int fixer_nb_valeurs_nodales(int n) override
Sets the number of degrees of freedom per component.