TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
PolyMAC_HFV_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_Tabule_Elem_PolyMAC_CDO.h>
17#include <PolyMAC_HFV_discretisation.h>
18#include <Op_Diff_PolyMAC_HFV_base.h>
19#include <Champ_Fonc_Elem_PolyMAC_CDO.h>
20#include <Domaine_PolyMAC_HFV.h>
21#include <Domaine_Cl_PolyMAC_family.h>
22#include <Schema_Temps_base.h>
23#include <Champ_Fonc_Tabule.h>
24#include <Champ_Uniforme.h>
25#include <Equation_base.h>
26#include <DescStructure.h>
27#include <Milieu_base.h>
28#include <Operateur.h>
29#include <Motcle.h>
30
31Implemente_instanciable(PolyMAC_HFV_discretisation, "PolyMAC_HFV|PolyMAC_P0P1NC", PolyMAC_CDO_discretisation);
32// XD PolyMAC_HFV discretisation_base PolyMAC_P0P1NC INHERITS_BRACE PolyMAC_HFV discretization (previously PolyMAC_CDO
33// XD_CONT discretization compatible with pb_multi).
34
36
38
39/*! @brief Discretizes a field for PolyMAC_HFV based on a discretization directive.
40 *
41 * @brief The directive is a Motcle such as "vitesse", "pression",
42 * "temperature", "champ_elem" (creates a P0-type field), ...
43 * This method determines the type of field to create based on the element type
44 * and the discretization directive. It then determines the number of degrees of freedom
45 * and sets all field parameters (type, nb_compo, nb_ddl, nb_pas_dt,
46 * name(s), unit(s), and field nature) and associates the Domaine_dis with the field.
47 * See the code for the correspondence between directives and
48 * the type of field created.
49 *
50 */
51void PolyMAC_HFV_discretisation::discretiser_champ(const Motcle& directive, const Domaine_dis_base& z, Nature_du_champ nature, const Noms& noms, const Noms& unites, int nb_comp, int nb_pas_dt,
52 double temps, OWN_PTR(Champ_Inc_base) &champ, const Nom& sous_type) const
53{
54 const Domaine_PolyMAC_HFV& domaine_PolyMAC_HFV = ref_cast(Domaine_PolyMAC_HFV, z);
55
56 Motcles motcles(7);
57 motcles[0] = "vitesse"; // Standard choice for velocity
58 motcles[1] = "pression"; // Standard choice for pressure
59 motcles[2] = "temperature"; // Standard choice for temperature
60 motcles[3] = "divergence_vitesse"; // Type of field obtained by computing div v
61 motcles[4] = "gradient_pression"; // Type of field obtained by computing grad P
62 motcles[5] = "champ_elem"; // Create a field at elements (of type P0)
63 motcles[6] = "champ_sommets"; // Create a field at vertices (type P1)
64
65 // The velocity field type depends on the element type:
66 int zp1 = false, default_nb_comp = 0, rang = motcles.search(directive);
67 Nom type_elem = Nom("Champ_Elem_") + que_suis_je(), type_som = "Champ_Som_PolyMAC_HFV", type_champ_scal = zp1 ? type_som : type_elem, type_champ_vitesse =
68 zp1 ? "Champ_Arete_PolyMAC_HFV" : Nom("Champ_Face_") + que_suis_je(), type;
69 switch(rang)
70 {
71 case 0:
72 case 4:
73 type = type_champ_vitesse;
74 default_nb_comp = 3;
75 break;
76 case 1:
77 case 2:
78 case 3:
79 type = type_champ_scal;
80 default_nb_comp = 1;
81 break;
82 case 5:
83 type = type_elem;
84 default_nb_comp = 1;
85 break;
86 case 6:
87 type = type_som;
88 default_nb_comp = 1;
89 break;
90 default:
91 assert(rang < 0);
92 break;
93 }
94
95 if (directive == DEMANDE_DESCRIPTION)
96 Cerr << "PolyMAC_HFV_discretisation : " << motcles;
97
98 if (sous_type != NOM_VIDE)
99 rang = verifie_sous_type(type, sous_type, directive);
100
101 // If the directive was not understood (or if it is a demande_description)
102 // call the parent class:
103 if (rang < 0)
104 {
105 Discret_Thyd::discretiser_champ(directive, z, nature, noms, unites, nb_comp, nb_pas_dt, temps, champ);
106 return;
107 }
108
109 // Compute the number of degrees of freedom
110 int nb_ddl = 0;
111 if (type.debute_par(type_elem))
112 nb_ddl = z.nb_elem();
113 else if (type.debute_par(type_som))
114 nb_ddl = domaine_PolyMAC_HFV.nb_som();
115 else if (type.debute_par(type_champ_vitesse))
116 nb_ddl = zp1 ? domaine_PolyMAC_HFV.domaine().nb_aretes() : domaine_PolyMAC_HFV.nb_faces();
117 else
118 assert(0);
119
120 if (nb_comp < 0)
121 nb_comp = default_nb_comp;
122 assert(nb_comp > 0);
123 creer_champ(champ, z, type, noms[0], unites[0], nb_comp, nb_ddl, nb_pas_dt, temps, directive, que_suis_je());
124 if (nature == multi_scalaire)
125 {
126 champ->fixer_nature_du_champ(nature);
127 champ->fixer_unites(unites);
128 champ->fixer_noms_compo(noms);
129 }
130}
131
132/*! @brief Same as PolyMAC_HFV_discretisation::discretiser_champ(.
133 *
134 * @brief .. , Champ_Inc) Common processing for champ_fonc and champ_don.
135 * This method is private (passing an Objet_U is not clean from
136 * the outside ...)
137 *
138 */
139void PolyMAC_HFV_discretisation::discretiser_champ_fonc_don(const Motcle& directive, const Domaine_dis_base& z, Nature_du_champ nature, const Noms& noms, const Noms& unites, int nb_comp,
140 double temps, Objet_U& champ) const
141{
142 // Two pointers for easy access to champ_don or champ_fonc, depending on the type of the champ object.
143 OWN_PTR(Champ_Fonc_base) *champ_fonc = dynamic_cast<OWN_PTR(Champ_Fonc_base)*>(&champ);
144 OWN_PTR(Champ_Don_base) *champ_don = dynamic_cast<OWN_PTR(Champ_Don_base)*>(&champ);
145
146 const Domaine_PolyMAC_HFV& domaine_PolyMAC_HFV = ref_cast(Domaine_PolyMAC_HFV, z);
147
148 Motcles motcles(8);
149 motcles[0] = "pression"; // Standard choice for pressure
150 motcles[1] = "temperature"; // Standard choice for temperature
151 motcles[2] = "divergence_vitesse"; // Type of field obtained by computing div v
152 motcles[3] = "champ_elem"; // Create a field at elements (of type P0)
153 motcles[4] = "vitesse"; // Standard choice for velocity
154 motcles[5] = "gradient_pression"; // Type of field obtained by computing grad P
155 motcles[6] = "champ_sommets"; // Create a field at vertices (of type P1)
156 motcles[7] = "champ_face"; // Standard choice for velocity
157
158 // The velocity field type depends on the element type:
159 int zp1 = false, default_nb_comp = 0, rang = motcles.search(directive);
160 Nom type_elem("Champ_Fonc_Elem_PolyMAC_CDO"), type_som("Champ_Fonc_Som_PolyMAC_CDO"), type_scal = zp1 ? type_som : type_elem, type_champ_vitesse(
161 zp1 ? "Champ_Fonc_Arete_PolyMAC_HFV" : "Champ_Fonc_Face_PolyMAC_CDO"), type;
162 switch(rang)
163 {
164 case 0:
165 case 1:
166 case 2:
167 type = type_scal;
168 default_nb_comp = 1;
169 break;
170 case 4:
171 case 5:
172 type = type_champ_vitesse;
173 default_nb_comp = 3;
174 break;
175 case 3:
176 type = type_elem;
177 default_nb_comp = 1;
178 break;
179 case 6:
180 type = type_som;
181 default_nb_comp = 1;
182 break;
183 case 7:
184 type = "Champ_Fonc_Face_PolyMAC_CDO";
185 default_nb_comp = 3;
186 break;
187 default:
188 assert(rang < 0);
189 break;
190 }
191
192 if (directive == DEMANDE_DESCRIPTION)
193 Cerr << "PolyMAC_HFV_discretisation : " << motcles;
194
195 // If the directive was not understood (or if it is a demande_description)
196 // call the parent class:
197 if (rang < 0)
198 {
199 if (champ_fonc)
200 Discret_Thyd::discretiser_champ(directive, z, nature, noms, unites, nb_comp, temps, *champ_fonc);
201 else
202 Discret_Thyd::discretiser_champ(directive, z, nature, noms, unites, nb_comp, temps, *champ_don);
203 return;
204 }
205
206 // Compute the number of degrees of freedom
207 int nb_ddl = 0;
208 if (type == "Champ_Fonc_Elem_PolyMAC_CDO")
209 nb_ddl = z.nb_elem();
210 else if (type == "Champ_Fonc_Face_PolyMAC_CDO")
211 nb_ddl = domaine_PolyMAC_HFV.nb_faces();
212 else if (type == "Champ_Fonc_Som_PolyMAC_CDO")
213 nb_ddl = domaine_PolyMAC_HFV.nb_som();
214 else if (type == "Champ_Fonc_Arete_PolyMAC_HFV")
215 nb_ddl = domaine_PolyMAC_HFV.domaine().nb_aretes();
216 else
217 assert(0);
218
219 // If it is a multi-scalar field:
220 if (nb_comp < 0)
221 nb_comp = default_nb_comp;
222 if (champ_fonc)
223 creer_champ(*champ_fonc, z, type, noms[0], unites[0], nb_comp, nb_ddl, temps, directive, que_suis_je());
224 else
225 creer_champ(*champ_don, z, type, noms[0], unites[0], nb_comp, nb_ddl, temps, directive, que_suis_je());
226 if ((nature == multi_scalaire) && (champ_fonc))
227 {
228 champ_fonc->valeur().fixer_nature_du_champ(nature);
229 champ_fonc->valeur().fixer_unites(unites);
230 champ_fonc->valeur().fixer_noms_compo(noms);
231 }
232 else if ((nature == multi_scalaire) && (champ_don))
233 {
234 Cerr << "There is no field of type OWN_PTR(Champ_Don_base) with a multi_scalaire nature." << finl;
235 exit();
236 }
237}
238
239void PolyMAC_HFV_discretisation::y_plus(const Domaine_dis_base& z, const Domaine_Cl_dis_base& zcl, const Champ_Inc_base& ch_vitesse, OWN_PTR(Champ_Fonc_base) &ch) const
240{
241 Cerr << "Discretization of y plus" << finl; // Used as a global wall-distance model
242 Noms noms(1), unites(1);
243 noms[0] = Nom("y_plus");
244 unites[0] = Nom("adimensionnel");
245 discretiser_champ(Motcle("champ_elem"), z, scalaire, noms, unites, 1, 0, ch);
246 DoubleTab& tab_y_p = ch->valeurs();
247 for (int i = 0; i < tab_y_p.dimension_tot(0); i++)
248 for (int n = 0; n < tab_y_p.dimension_tot(1); n++)
249 tab_y_p(i, n) = -1.;
250}
251
252void PolyMAC_HFV_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
253{
254 abort();
255}
256
257Nom PolyMAC_HFV_discretisation::get_name_of_type_for(const Nom& class_operateur, const Nom& type_operateur, const Equation_base& eqn, const OBS_PTR(Champ_base) &champ_sup) const
258{
259 Nom type;
260 Nom type_ch = eqn.inconnue().que_suis_je();
261 if (type_ch.debute_par("Champ_Elem"))
262 type_ch = "_Elem";
263 else if (type_ch.debute_par("Champ_Som"))
264 type_ch = "_Som";
265 else if (type_ch.debute_par("Champ_Face"))
266 type_ch = "_Face";
267 else if (type_ch.debute_par("Champ_Arete"))
268 type_ch = "_Arete";
269
270 if (class_operateur == "Source")
271 type = type_operateur + type_ch + "_" + que_suis_je();
272 else if (class_operateur == "Solveur_Masse")
273 type = Nom("Masse_") + que_suis_je() + type_ch;
274 else if (class_operateur == "Operateur_Grad")
275 type = Nom("Op_Grad_") + que_suis_je() + "_Face";
276 else if (class_operateur == "Operateur_Div")
277 type = Nom("Op_Div_") + que_suis_je();
278 else if (class_operateur == "Operateur_Diff")
279 type = Nom("Op_Diff") + (type_operateur != "" ? "_" : "") + type_operateur + "_" + que_suis_je() + type_ch;
280 else if (class_operateur == "Operateur_Conv")
281 type = Nom("Op_Conv_") + type_operateur + "_" + que_suis_je() + type_ch;
282 else if (class_operateur == "Operateur_Evanescence")
283 type = Nom("Op_Evanescence") + (type_operateur != "" ? "_" : "") + type_operateur + "_" + que_suis_je() + type_ch;
284 else
285 return Discret_Thyd::get_name_of_type_for(class_operateur, type_operateur, eqn);
286
287 return type;
288}
289
290void PolyMAC_HFV_discretisation::residu(const Domaine_dis_base& z, const Champ_Inc_base& ch_inco, OWN_PTR(Champ_Fonc_base) &champ) const
291{
292 Nom ch_name(ch_inco.le_nom());
293 ch_name += "_residu";
294 Cerr << "Discretization of " << ch_name << finl;
295
296 Nom type_ch = ch_inco.que_suis_je();
297 if (type_ch.debute_par("Champ_Face"))
298 {
299 Motcle loc = "champ_face";
300 Noms nom(1), unites(1);
301 nom[0] = ch_name;
302 unites[0] = "units_not_defined";
303 int nb_comp = ch_inco.valeurs().line_size() * dimension;
304 discretiser_champ(loc, z, vectoriel, nom, unites, nb_comp, ch_inco.temps(), champ);
305 }
306 else
307 {
308 Motcle loc = "champ_elem";
309 Noms nom(1), unites(1);
310 nom[0] = ch_name;
311 unites[0] = "units_not_defined";
312 int nb_comp = ch_inco.valeurs().line_size();
313 discretiser_champ(loc, z, scalaire, nom, unites, nb_comp, ch_inco.temps(), champ);
314 }
315
316 Champ_Fonc_base& ch_fonc = ref_cast(Champ_Fonc_base, champ.valeur());
317 DoubleTab& tab = ch_fonc.valeurs();
318 tab = -10000.0;
319 Cerr << "[Information] Discretisation_base::residu : the residue is set to -10000.0 at initial time" << finl;
320}
class Champ_Don_base base class of Given Fields (not calculated)
DoubleTab & valeurs() override
Overrides Champ_base::valeurs() Returns the array of values.
class Champ_Fonc_base Base class of fields that are functions of a calculated quantity
Class Champ_Inc_base.
DoubleTab & valeurs() override
Returns the array of field values at the current time.
class Champ_base This class is the base of the fields hierarchy.
Definition Champ_base.h:43
double temps() const
Returns the time of the field.
static void creer_champ(OWN_PTR(Champ_Inc_base)&ch, const Domaine_dis_base &z, const Nom &type, const Nom &nom, const Nom &unite, int nb_comp, int nb_ddl, int nb_pas_dt, double temps, const Nom &directive=NOM_VIDE, const Nom &nom_discretisation=NOM_VIDE)
Static method that creates an OWN_PTR(Champ_Inc_base) of the specified type.
virtual Nom get_name_of_type_for(const Nom &class_operateur, const Nom &type_operteur, const Equation_base &eqn, const OBS_PTR(Champ_base)&champ_supp=OBS_PTR(Champ_base)()) const
Fills the Nom type depending on the class of operator, the type of operator and the equation.
static const Nom NOM_VIDE
static const Motcle DEMANDE_DESCRIPTION
void discretiser_champ(const Motcle &directive, const Domaine_dis_base &z, const Nom &nom, const Nom &unite, int nb_comp, int nb_pas_dt, double temps, OWN_PTR(Champ_Inc_base)&champ, const Nom &sous_type=NOM_VIDE) const
int verifie_sous_type(Nom &type, const Nom &sous_type, const Motcle &directive) const
int_t nb_aretes() const
Returns the number of real edges.
Definition Domaine.h:143
class Domaine_Cl_dis_base Domaine_Cl_dis_base objects represent discretized boundary conditions
int nb_faces() const
Returns the total number of faces.
Definition Domaine_VF.h:471
class Domaine_dis_base This class is the base of the hierarchy of discretized domains.
const Domaine & domaine() const
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
class Equation_base The role of an equation is the calculation of one or more fields....
virtual const Champ_Inc_base & inconnue() const =0
const Nom & le_nom() const override
Returns the name of the field.
A character string (Nom) in uppercase.
Definition Motcle.h:26
An array of Motcle objects.
Definition Motcle.h:63
int search(const Motcle &t) const
Definition Motcle.cpp:319
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
Base class for TRUST objects (Objet_U).
Definition Objet_U.h:68
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 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
Discretizes the incompressible fluid in PolyMAC_CDO, i.e., K and N.
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.
Nom get_name_of_type_for(const Nom &class_operateur, const Nom &type_operateur, const Equation_base &eqn, const OBS_PTR(Champ_base) &champ_sup) const override
void y_plus(const Domaine_dis_base &z, const Domaine_Cl_dis_base &, const Champ_Inc_base &vitesse, OWN_PTR(Champ_Fonc_base)&ch) const override
static void abort()
Abort routine for TRUST on a fatal error.
Definition Process.cpp:573
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
_SIZE_ dimension_tot(int) const override
Definition TRUSTTab.tpp:160
int line_size() const
Definition TRUSTVect.tpp:67