TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
DG_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 <DG_discretisation.h>
17#include <Domaine_DG.h>
18#include <Champ_Fonc_Tabule.h>
19#include <Milieu_base.h>
20#include <Equation_base.h>
21#include <Champ_Uniforme.h>
22#include <Champ_Inc_base.h>
23#include <Schema_Temps_base.h>
24#include <Motcle.h>
25#include <Domaine_Cl_DG.h>
26#include <Option_DG.h>
27#include <Quadrature_base.h>
28#include <Quadrature_Ord1_Polygone.h>
29#include <Quadrature_Ord3_Polygone.h>
30#include <Quadrature_Ord5_Polygone.h>
31
32Implemente_instanciable(DG_discretisation, "DG", Discret_Thyd);
33// XD DG discretisation_base DG INHERITS_BRACE DG discretization
34
35
37{
38 return Discret_Thyd::readOn(s);
39}
40
41Sortie& DG_discretisation::printOn(Sortie& s) const { return s; }
42
43/*! @brief Discretisation of a field for DG formulation
44 *
45 * TODO, refactor this after stokes. And decide if we want to put this on Option_DG or not
46 *
47 * The directive is a Motcle such as "vitesse", "pression",
48 * "temperature", "champ_elem" (creates a field of type P0), ...
49 * This method determines the type of field to create based on the element type
50 * and the discretisation directive. It then determines the number of DOFs
51 * and sets all the field parameters (type, nb_compo, nb_ddl, nb_pas_dt,
52 * name(s), unit(s) and field nature) and associates the Domaine_dis to the field.
53 * See the code for the mapping between directives and the created field type.
54 *
55 */
56void DG_discretisation::discretiser_champ(const Motcle& directive, const Domaine_dis_base& dom_dis, Nature_du_champ nature, const Noms& noms, const Noms& unites, int nb_comp, int nb_pas_dt,
57 double temps, OWN_PTR(Champ_Inc_base)& champ, const Nom& sous_type) const
58{
59 Motcles motcles(7);
60 motcles[0] = "vitesse"; // Standard choice for velocity
61 motcles[1] = "pression"; // Standard choice for pressure
62 motcles[2] = "temperature"; // Standard choice for temperature
63 motcles[3] = "divergence_vitesse"; // Field type obtained by computing div v
64 motcles[4] = "gradient_pression"; // Field type obtained by computing grad P
65 motcles[5] = "champ_elem"; // Create a field at elements (type P0)
66 motcles[6] = "champ_sommets"; // Create a field at vertices (type P1)
67 // The velocity field type depends on the element type:
68// Nom type_champ_vitesse("Champ_Face_DG");
69 Nom type_elem("Champ_Elem_DG");
70 Nom type;
71 int nb_basis_func = 0; // Default value for the number of components
72 int rang = motcles.search(directive);
73 const int order_DG = Option_DG::Get_order_for(noms[0]);
74 switch(rang)
75 {
76 case 0:
77 case 1:
78 case 2:
79 case 3:
80 case 4:
81 case 5:
82 type = type_elem;
83 nb_basis_func = Option_DG::Nb_col_from_order(order_DG);
84 break;
85 default:
86 assert(rang < 0);
87 break;
88 }
89
90 if (directive == DEMANDE_DESCRIPTION)
91 Cerr << "DG discretisation : " << motcles;
92
93 if (sous_type != NOM_VIDE)
94 rang = verifie_sous_type(type, sous_type, directive);
95
96 // If the directive was not understood (or if it is a description request),
97 // call the parent class:
98 if (rang < 0)
99 {
100 Discret_Thyd::discretiser_champ(directive, dom_dis, nature, noms, unites, nb_comp, nb_pas_dt, temps, champ);
101 return;
102 }
103
104 // Compute the number of degrees of freedom
105 int nb_ddl = 0;
106 if (type.debute_par(type_elem))
107 nb_ddl = dom_dis.nb_elem();
108 else
109 assert(0);
110
111 creer_champ(champ, dom_dis, type, noms[0], unites[0], nb_comp*nb_basis_func, nb_ddl, nb_pas_dt, temps, directive, que_suis_je());
112
113 if (nature == multi_scalaire)
114 {
115 throw;
116 }
117
118 if (nb_comp == 1)
119 switch(order_DG)
120 {
121 case 0:
122 champ->fixer_nature_du_champ(scalaire);
123 break;
124 case 1:
125 champ->fixer_nature_du_champ(basis_function_order_1_scalar);
126 break;
127 case 2:
128 champ->fixer_nature_du_champ(basis_function_order_2_scalar);
129 break;
130 default:
131 assert(0);
132 }
133 else
134 switch(order_DG)
135 {
136 case 0:
137 champ->fixer_nature_du_champ(vectoriel);
138 break;
139 case 1:
140 champ->fixer_nature_du_champ(basis_function_order_1_vectorial);
141 break;
142 case 2:
143 champ->fixer_nature_du_champ(basis_function_order_2_vectorial);
144 break;
145 default:
146 assert(0);
147 }
148
149
150}
151
152/*! @brief Same as DG_discretisation::discretiser_champ(.
153 *
154 * .. , Champ_Inc)
155 *
156 */
157void DG_discretisation::discretiser_champ(const Motcle& directive, const Domaine_dis_base& z, Nature_du_champ nature, const Noms& noms, const Noms& unites, int nb_comp, double temps,
158 OWN_PTR(Champ_Fonc_base)& champ) const
159{
160 discretiser_champ_fonc_don(directive, z, nature, noms, unites, nb_comp, temps, champ);
161}
162
163/*! @brief Same as DG_discretisation::discretiser_champ(.
164 *
165 * .. , Champ_Inc)
166 *
167 */
168void DG_discretisation::discretiser_champ(const Motcle& directive, const Domaine_dis_base& z, Nature_du_champ nature, const Noms& noms, const Noms& unites, int nb_comp, double temps,
169 OWN_PTR(Champ_Don_base)& champ) const
170{
171 discretiser_champ_fonc_don(directive, z, nature, noms, unites, nb_comp, temps, champ);
172}
173
174/*! @brief Same as DG_discretisation::discretiser_champ(.
175 *
176 * .. , Champ_Inc) Common processing for champ_fonc and champ_don.
177 * This method is private (passing an Objet_U is not clean from the outside).
178 *
179 */
180void DG_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, double temps,
181 Objet_U& champ) const
182{
183 // Two pointers for easy access to champ_don or champ_fonc, depending on the type of the champ object.
184 OWN_PTR(Champ_Fonc_base) * champ_fonc = dynamic_cast<OWN_PTR(Champ_Fonc_base)*>(&champ);
185 OWN_PTR(Champ_Don_base) * champ_don = dynamic_cast<OWN_PTR(Champ_Don_base)*>(&champ);
186
187 const Domaine_DG& domaine_DG = ref_cast(Domaine_DG, z);
188
189
190 Motcles motcles(8);
191 motcles[0] = "pression"; // Standard choice for pressure
192 motcles[1] = "temperature"; // Standard choice for temperature
193 motcles[2] = "champ_fonc_quad_dg"; // With value on quadrature points
194 motcles[5] = "champ_elem_dg"; // With value on quadrature points
195 motcles[3] = "champ_elem"; // Create a field at elements (type P0)
196 motcles[6] = "champ_sommets"; // Create a field at vertices (type P1)
197 motcles[4] = "vitesse"; // Standard choice for velocity
198 motcles[7] = "champ_face"; // Standard choice for velocity
199
200 Nom type;
201 int nb_points = 0; // Default value for the number of components
202 int rang = motcles.search(directive);
203 const Quadrature_base& quad = domaine_DG.get_quadrature(5); // TODO: Make this depend from the order of discretization ...
204 int nb_pts_integ_max = quad.nb_pts_integ_max();
205
206// const int order_DG = Option_DG::Get_order_for(directive);
207 switch(rang)
208 {
209 case 0:
210 case 1:
211 case 2:
212 case 4:
213 case 5:
214 case 7:
215 type = "Champ_Fonc_Quad_DG";
216 nb_points = nb_pts_integ_max; //Option_DG::Nb_col_from_order(order_DG);;
217 break;
218 case 3:
219 type = "Champ_Fonc_Elem_DG";
220 nb_points = 1;
221 break;
222 case 6:
223 type = "Champ_Fonc_Som_DG";
224 nb_points = 1;
225 break;
226 default:
227 assert(rang < 0);
228 break;
229 }
230
231 if (directive == DEMANDE_DESCRIPTION)
232 Cerr << "DG discretisation : " << motcles;
233
234 // If the directive was not understood (or if it is a description request),
235 // call the parent class:
236 if (rang < 0)
237 {
238 if (champ_fonc)
239 Discret_Thyd::discretiser_champ(directive, z, nature, noms, unites, nb_comp, temps, *champ_fonc);
240 else
241 Discret_Thyd::discretiser_champ(directive, z, nature, noms, unites, nb_comp, temps, *champ_don);
242 return;
243 }
244
245 // Compute the number of degrees of freedom
246 int nb_ddl = 0;
247 if (type == "Champ_Fonc_Elem_DG" || type == "Champ_Fonc_Quad_DG")
248 nb_ddl = z.nb_elem();
249 else if (type == "Champ_Fonc_Som_DG")
250 nb_ddl = domaine_DG.nb_som();
251 else
252 assert(0);
253
254 bool vector = (nature==vectoriel or nature==quadrature_vectoriel or nature == basis_function_order_1_vectorial or nature == basis_function_order_2_vectorial );
255 if (vector) nb_comp = dimension;
256 else nb_comp = 1;
257 if (champ_fonc)
258 {
259 creer_champ(*champ_fonc, z, type, noms[0], unites[0], nb_comp*nb_points, nb_ddl, temps, directive, que_suis_je());
260 if (nb_comp == 1)
261 {
262 (nb_points == 1) ? champ_fonc->valeur().fixer_nature_du_champ(scalaire)
263 : champ_fonc->valeur().fixer_nature_du_champ(quadrature_scalaire);
264 }
265 else if (nb_comp == dimension)
266 {
267 (nb_points == 1) ? champ_fonc->valeur().fixer_nature_du_champ(vectoriel)
268 : champ_fonc->valeur().fixer_nature_du_champ(quadrature_vectoriel);
269 }
270 else
271 {
272 Cerr << "multi_scalaire not implemented for now" << finl;
273 exit();
274 }
275 }
276 else
277 {
278 creer_champ(*champ_don, z, type, noms[0], unites[0], nb_comp*nb_points, nb_ddl, temps, directive, que_suis_je());
279 if (nb_comp == 1)
280 {
281 (nb_points == 1) ? champ_don->valeur().fixer_nature_du_champ(scalaire)
282 : champ_don->valeur().fixer_nature_du_champ(quadrature_scalaire);
283 }
284 else if (nb_comp == dimension)
285 {
286 (nb_points == 1) ? champ_don->valeur().fixer_nature_du_champ(vectoriel)
287 : champ_don->valeur().fixer_nature_du_champ(quadrature_vectoriel);
288 }
289 else
290 {
291 Cerr << "multi_scalaire not implemented for now" << finl;
292 exit();
293 }
294 }
295
296
297
298 if ((nature == multi_scalaire) && (champ_fonc))
299 {
300 throw;
301 }
302 else if ((nature == multi_scalaire) && (champ_don))
303 {
304 Cerr << "There is no field of type Champ_Don with a multi_scalaire nature." << finl;
305 exit();
306 }
307}
308
310{
311 throw;
312}
313
314
315void DG_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
316{
317 throw;
318}
319
320
321void DG_discretisation::modifier_champ_tabule(const Domaine_dis_base& domaine_poly, Champ_Fonc_Tabule& lambda_tab, const VECT(OBS_PTR(Champ_base)) &champs_param) const
322{
323 throw;
324}
325
326/*! @brief Old copy paste, give the name to fields. Name used to allocate size of matrixes in discretiser
327 *
328 */
329Nom DG_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
330{
331 Nom type;
332 if (class_operateur == "Source")
333 {
334 type = type_operateur;
335 Nom champ = (eqn.inconnue().que_suis_je());
336 champ.suffix("Champ");
337 type += champ;
338 //type+="_DG";
339 return type;
340
341 }
342 else if (class_operateur == "Solveur_Masse")
343 {
344 Nom type_ch = eqn.inconnue().que_suis_je();
345 if (type_ch.debute_par("Champ_Elem"))
346 type_ch = "_Elem";
347
348 if (type_ch.debute_par("Champ_Face"))
349 type_ch = "_Face";
350
351 type = "Masse_DG";
352 type += type_ch;
353 }
354 else if (class_operateur == "Operateur_Grad")
355 {
356 type = "Op_Grad_DG";
357 }
358 else if (class_operateur == "Operateur_Div")
359 {
360 type = "Op_Div_DG";
361 }
362
363 else if (class_operateur == "Operateur_Diff")
364 {
365 Nom type_ch = eqn.inconnue().que_suis_je();
366 if (type_ch.debute_par("Champ_Elem"))
367 type_ch = "_Elem";
368
369 if (type_ch.debute_par("Champ_Face"))
370 type_ch = "_Face";
371
372 type = "Op_Diff";
373 if (type_operateur != "")
374 {
375 type += "_";
376 type += type_operateur;
377 }
378 type += "_DG";
379 type += type_ch;
380 }
381 else if (class_operateur == "Operateur_Conv")
382 {
383 type = "Op_Conv_";
384 type += type_operateur;
385 Nom tiret = "_";
386 type += tiret;
387 type += que_suis_je();
388 Nom type_ch = eqn.inconnue().que_suis_je();
389 if (type_ch.debute_par("Champ_Elem"))
390 type += "_Elem";
391 if (type_ch.debute_par("Champ_Face"))
392 type += "_Face";
393 type += "_DG";
394 }
395
396 else
397 return Discret_Thyd::get_name_of_type_for(class_operateur, type_operateur, eqn);
398
399 return type;
400}
401
403{
404 Cerr << "Global wall distance discretisation" << finl;
405 Noms noms(1), unites(1);
406 noms[0] = Nom("distance_paroi_globale");
407 unites[0] = Nom("m");
408 discretiser_champ(Motcle("champ_elem"), z, scalaire, noms, unites, 1, 0, ch);
409}
class Champ_Don_base base class of Given Fields (not calculated)
Class Champ_Fonc_Tabule Derived class of Champ_Fonc_base representing.
class Champ_Fonc_base Base class of fields that are functions of a calculated quantity
Class Champ_Inc_base.
class Champ_base This class is the base of the fields hierarchy.
Definition Champ_base.h:43
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
void distance_paroi(const Schema_Temps_base &, Domaine_dis_base &, OWN_PTR(Champ_Fonc_base)&) const
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
Old copy paste, give the name to fields. Name used to allocate size of matrixes in discretiser.
void distance_paroi_globale(const Schema_Temps_base &, Domaine_dis_base &, OWN_PTR(Champ_Fonc_base)&) 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
Discretisation of a field for DG formulation.
class Discret_Thyd This class is the base class representing a discretization
OBS_PTR(Domaine) le_domaine_
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
class Domaine_Cl_dis_base Domaine_Cl_dis_base objects represent discretized boundary conditions
const Quadrature_base & get_quadrature(int order) const
Definition Domaine_DG.h:100
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
class Equation_base The role of an equation is the calculation of one or more fields....
virtual const Champ_Inc_base & inconnue() const =0
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
Nom & suffix(const char *const)
Suffix extraction: Nom x("azerty");.
Definition Nom.cpp:266
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
static int Nb_col_from_order(const int order)
Return the number of columns necessary in the unknown vector for a given method order....
Definition Option_DG.cpp:83
static int Get_order_for(const Nom &n)
Definition Option_DG.cpp:70
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
int nb_pts_integ_max() const
class Schema_Temps_base
Base class for output streams.
Definition Sortie.h:52