TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Coloc_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 <Coloc_discretisation.h>
17#include <Domaine_Coloc.h>
18#include <Equation_base.h>
19#include <Probleme_base.h>
20
21Implemente_instanciable(Coloc_discretisation, "Coloc", Discret_Thyd);
22
23// XD coloc discretisation_base coloc INHERITS_BRACE Co-localised cell-center discretization
24
26
27Sortie& Coloc_discretisation::printOn(Sortie& s) const { return s;}
28
29void Coloc_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,
30 double temps, OWN_PTR(Champ_Inc_base)& champ, const Nom& sous_type) const
31{
32 Motcles motcles(6);
33 motcles[0] = "vitesse"; // Standard choice for velocity
34 motcles[1] = "pression"; // Standard choice for pressure
35 motcles[2] = "temperature"; // Standard choice for temperature
36 motcles[3] = "divergence_vitesse"; // Field type obtained by computing div v
37 motcles[4] = "gradient_pression"; // Field type obtained by computing grad P
38 motcles[5] = "champ_elem"; // Create a field at elements (type P0)
39
40 Nom type_champ_vec("Champ_Vect_Elem_Coloc");
41 Nom type_champ_elem("Champ_Elem_Coloc");
42 Nom type;
43 int default_nb_comp = 0; // Default value for the number of components
44 int rang = motcles.search(directive);
45
46 switch(rang)
47 {
48 case 0:
49 case 4:
50 type = type_champ_vec;
51 default_nb_comp = 3;
52 break;
53 case 1:
54 case 2:
55 case 3:
56 case 5:
57 type = type_champ_elem;
58 default_nb_comp = 1;
59 break;
60 default:
61 assert(rang < 0);
62 break;
63 }
64
65 if (directive == DEMANDE_DESCRIPTION)
66 Cerr << "Coloc_discretisation : " << motcles;
67
68 if (sous_type != NOM_VIDE)
69 rang = verifie_sous_type(type, sous_type, directive);
70
71 // If the directive was not understood (or if it is a description request),
72 // call the parent class:
73 if (rang < 0)
74 {
75 Discret_Thyd::discretiser_champ(directive, z, nature, noms, unites, nb_comp, nb_pas_dt, temps, champ);
76 return;
77 }
78
79 int nb_ddl = 0;
80 if (type.debute_par(type_champ_elem) || type.debute_par(type_champ_vec))
81 nb_ddl = z.nb_elem() ;
82 else
83 assert(0);
84
85 if (nb_comp < 0)
86 nb_comp = default_nb_comp;
87 assert(nb_comp > 0);
88 creer_champ(champ, z, type, noms[0], unites[0], nb_comp, nb_ddl, nb_pas_dt, temps, directive, que_suis_je());
89
90 if (nature == multi_scalaire)
91 {
92 champ->fixer_nature_du_champ(nature);
93 champ->fixer_unites(unites);
94 champ->fixer_noms_compo(noms);
95 }
96}
97
98void Coloc_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,
99 OWN_PTR(Champ_Fonc_base)& champ) const
100{
101 discretiser_champ_fonc_don(directive, z, nature, noms, unites, nb_comp, temps, champ);
102}
103
104void Coloc_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,
105 OWN_PTR(Champ_Don_base)& champ) const
106{
107 discretiser_champ_fonc_don(directive, z, nature, noms, unites, nb_comp, temps, champ);
108}
109
110Nom Coloc_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
111{
112 if (eqn.probleme().que_suis_je() != "Pb_Euler")
113 Process::exit("\nError with the chosen discretization !!!! \nThe colocalised discretization currently works only for the Euler problem !! Please select another one ... \n");
114
115 Nom type;
116 Nom type_ch = eqn.inconnue().que_suis_je();
117 if (type_ch.debute_par("Champ_Elem")) type_ch = "_Elem";
118 else if (type_ch.debute_par("Champ_Vect")) type_ch = "_Vect";
119
120 if (class_operateur == "Source")
121 type = type_operateur + type_ch + "_" + que_suis_je();
122 else if (class_operateur == "Solveur_Masse")
123 type = Nom("Masse_") + que_suis_je() + type_ch;
124 else if (class_operateur == "Operateur_Grad")
125 type = Nom("Op_Grad_") + type_operateur + "_" + que_suis_je() + type_ch;
126 else if (class_operateur == "Operateur_Diff")
127 type = Nom("Op_Diff") + (type_operateur != "" ? "_" : "") + type_operateur + "_" + que_suis_je() + type_ch;
128 else if (class_operateur == "Operateur_Conv")
129 type = Nom("Op_Conv_") + type_operateur + "_" + que_suis_je() + type_ch;
130 else if (class_operateur == "Operateur_NConserv")
131 type = Nom("Op_NConserv_") + type_operateur + "_" + que_suis_je() + type_ch;
132 else
133 return Discret_Thyd::get_name_of_type_for(class_operateur, type_operateur, eqn);
134
135 return type;
136}
137
138void Coloc_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,
139 double temps, Objet_U& champ) const
140{
141// Two pointers for easy access to champ_don or champ_fonc, depending on the type of the champ object.
142 OWN_PTR(Champ_Fonc_base) *champ_fonc = dynamic_cast<OWN_PTR(Champ_Fonc_base)*>(&champ);
143 OWN_PTR(Champ_Don_base) *champ_don = dynamic_cast<OWN_PTR(Champ_Don_base)*>(&champ);
144
145 Motcles motcles(6);
146 motcles[0] = "pression"; // Standard choice for pressure
147 motcles[1] = "temperature"; // Standard choice for temperature
148 motcles[2] = "divergence_vitesse"; // Field type obtained by computing div v
149 motcles[3] = "champ_elem"; // Create a field at elements (type P0)
150 motcles[4] = "vitesse"; // Standard choice for velocity
151 motcles[5] = "gradient_pression"; // Field type obtained by computing grad P
152
153// The velocity field type depends on the element type:
154 int default_nb_comp = 0,
155 rang = motcles.search(directive);
156
157 Nom type_champ_elem("Champ_Fonc_Elem_Coloc"),
158 type_champ_vect("Champ_Fonc_Vect_Coloc"),
159 type;
160
161 switch(rang)
162 {
163 case 0:
164 case 1:
165 case 2:
166 case 3:
167 type = type_champ_elem;
168 default_nb_comp = 1;
169 break;
170 case 4:
171 case 5:
172 type = type_champ_vect;
173 default_nb_comp = 3;
174 break;
175 default:
176 assert(rang < 0);
177 break;
178 }
179
180 if (directive == DEMANDE_DESCRIPTION)
181 Cerr << "Coloc_discretisation : " << motcles;
182
183// If the directive was not understood (or if it is a description request),
184// call the parent class:
185 if (rang < 0)
186 {
187 if (champ_fonc)
188 Discret_Thyd::discretiser_champ(directive, z, nature, noms, unites, nb_comp, temps, *champ_fonc);
189 else
190 Discret_Thyd::discretiser_champ(directive, z, nature, noms, unites, nb_comp, temps, *champ_don);
191 return;
192 }
193
194// Compute the number of degrees of freedom
195 int nb_ddl = 0;
196 if ((type == "Champ_Fonc_Elem_Coloc") || (type == "Champ_Fonc_Vect_Coloc")) // to be replaced by debute_par("Champ_Elem")
197 nb_ddl = z.nb_elem();
198 else
199 assert(0);
200
201// If it is a multi-scalar field, handle accordingly
202 if (nb_comp < 0)
203 nb_comp = default_nb_comp;
204 if (champ_fonc)
205 creer_champ(*champ_fonc, z, type, noms[0], unites[0], nb_comp, nb_ddl, temps, directive, que_suis_je());
206 else
207 creer_champ(*champ_don, z, type, noms[0], unites[0], nb_comp, nb_ddl, temps, directive, que_suis_je());
208 if ((nature == multi_scalaire) && (champ_fonc))
209 {
210 champ_fonc->valeur().fixer_nature_du_champ(nature);
211 champ_fonc->valeur().fixer_unites(unites);
212 champ_fonc->valeur().fixer_noms_compo(noms);
213 }
214 else if ((nature == multi_scalaire) && (champ_don))
215 {
216 Cerr << "There is no field of type OWN_PTR(Champ_Don_base) with a multi_scalaire nature." << finl;
217 exit();
218 }
219}
class Champ_Don_base base class of Given Fields (not calculated)
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 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
Discretization of a field depending on the directive and other parameters.
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
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_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
Probleme_base & probleme()
Returns the problem associated with the equation.
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
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 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