TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_Generique_Gradient.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_Generique_Gradient.h>
17#include <Domaine_VF.h>
18#include <Champ_Generique_refChamp.h>
19#include <Discretisation_base.h>
20#include <Synonyme_info.h>
21
22Implemente_instanciable(Champ_Generique_Gradient,"Gradient",Champ_Generique_Operateur_base);
23// XD gradient champ_post_operateur_base gradient INHERITS_BRACE To calculate gradient of a given field.
24
25Add_synonym(Champ_Generique_Gradient,"Champ_Post_Operateur_Gradient");
26
28{
29 return s << que_suis_je() << " " << le_nom();
30}
31
33{
35 return s ;
36}
37
39{
41 const Probleme_base& Pb = get_ref_pb_base();
42 if (sub_type(Champ_Generique_refChamp,get_source(0)))
43 {
44
45 OWN_PTR(Champ_base) espace_stockage;
46 const Champ_base& mon_champ = get_source(0).get_champ(espace_stockage);
47 if (sub_type(Champ_Inc_base,mon_champ))
48 {
49 const Champ_Inc_base& mon_champ_inc = ref_cast(Champ_Inc_base,mon_champ);
50
51 if ( (mon_champ_inc.le_nom()=="pression") || ((mon_champ_inc.le_nom()!="vitesse") && (mon_champ_inc.que_suis_je()=="Champ_P1NC"))
52 || ((mon_champ_inc.le_nom()!="vitesse") && (mon_champ_inc.que_suis_je()=="Champ_P0_VDF")) )
53 {
54
55 //We retrieve the equation even though it is not yet associated with Champ_Inc
56 //We iterate over the equations of the problem and identify the one corresponding to the unknown field
57
58 int nb_eq = Pb.nombre_d_equations();
59 int i=0;
60
61 while (i<nb_eq)
62 {
63 const Equation_base& eq_test = Pb.equation(i);
64 if ((eq_test.inconnue().le_nom() == mon_champ_inc.le_nom()) || ((i==0) && (mon_champ_inc.le_nom()=="pression") &&
65 (eq_test.le_nom()!="Conduction")))
66 break;
67 i++;
68 }
69 const Equation_base& eqn = Pb.equation(i);
70
71 Op_Grad_.associer_eqn(eqn);
72 Op_Grad_.typer();
73 Op_Grad_.l_op_base().associer_eqn(eqn);
74
75 const Domaine_dis_base& zdis = eqn.domaine_dis();
76 const Domaine_Cl_dis_base& zcl = eqn.domaine_Cl_dis();
77 const Champ_Inc_base& inco = eqn.inconnue();
78 Op_Grad_->associer(zdis, zcl, inco);
79 }
80 else
81 {
82 Cerr<<"We can apply a Champ_Generique_Gradient only to the pressure field"<<finl;
83 Cerr<<"or to a field of type Champ_P1NC or Champ_P0_VDF at one component"<<finl;
84 exit();
85 }
86 }
87 else
88 {
89 Cerr<<"We can apply a Champ_Generique_Gradient only to an unknown field of the problem"<<finl;
90 exit();
91 }
92 }
93}
94
96{
97
98 if (Op_Grad_)
99 {
100 OWN_PTR(Champ_Fonc_base) es_tmp;
101 espace_stockage = creer_espace_stockage(vectoriel,dimension,es_tmp);
102
103 }
104 else
105 {
106 //const Noms nom = get_source(0).get_property("nom");
107 Cerr<<"We can apply a Champ_Generique_Gradient only to the pressure field"<<finl;
108 Cerr<<"or to a field of type Champ_P1NC or Champ_P0_VDF at one component"<<finl;
109 exit();
110 }
111 return espace_stockage;
112}
114{
115 OWN_PTR(Champ_base) source_espace_stockage;
116 const Champ_base& source = get_source(0).get_champ(source_espace_stockage);
117
118 if (Op_Grad_)
119 {
120 OWN_PTR(Champ_Fonc_base) es_tmp;
121 espace_stockage = creer_espace_stockage(vectoriel,dimension,es_tmp);
122
123 Op_Grad_.calculer(source.valeurs(),espace_stockage->valeurs());
124
125 Nom type_op = Op_Grad_->que_suis_je();
126 if ((type_op!="Op_Grad_P1NC_to_P0") && (type_op!="Op_Grad_P0_to_Face"))
127 Op_Grad_.equation().solv_masse().appliquer(espace_stockage->valeurs());
128 }
129 else
130 {
131 const Noms nom = get_source(0).get_property("nom");
132 Cerr<<"We can apply a Champ_Generique_Gradient only to the pressure field"<<finl;
133 Cerr<<"or to a field of type Champ_P1NC or Champ_P0_VDF at one component"<<finl;
134 Cerr<<"The space of storage of field treated here "<<nom[0]<<" is of type"<<source.que_suis_je()<<finl;
135 exit();
136 }
137
138 DoubleTab& espace_valeurs = espace_stockage->valeurs();
139 espace_valeurs.echange_espace_virtuel();
140 return espace_stockage;
141}
142
144{
145
146 //Component creation should be done dynamically (Gradient_...)
147
148 Motcles motcles(2);
149 motcles[0] = "composantes";
150 motcles[1] = "unites";
151
152 int rang = motcles.search(query);
153 switch(rang)
154 {
155 case 0:
156 {
157 //Currently the choice is simply to add the component number
158 /*
159 const Noms compo_cibles = get_source(0).get_property("composantes");
160 ///int size = compo_cibles.size();
161 ///const Noms nom = get_source(0).get_property("nom");
162 ///Nom nom_champ = nom[0];
163 Nom nom_champ = "pression";
164
165 //Valid if Champ_Fonc_P1NC
166 Noms mots(dimension);
167 Nom compo_temp="gradient_";
168
169 for (int i=0; i<dimension; i++) {
170 if (i==0) {
171 mots[i] = compo_temp+nom_champ +"X";
172 }
173 else if (i==1) {
174 mots[i] = compo_temp+nom_champ +"Y";;
175 }
176 else if (i==2) {
177 mots[i] = compo_temp+nom_champ +"Z";
178 }
179 }
180
181 return mots;
182 break;
183 */
184
185 int nb_comp = dimension;
186 Noms compo(nb_comp);
187 for (int i=0; i<nb_comp; i++)
188 {
189 Nom nume(i);
190 compo[i] = nom_post_+nume;
191 }
192
193 return compo;
194 }
195
196 case 1:
197 {
198 Noms unites(dimension);
199 Noms source_unites = get_source(0).get_property("unites");
200
201 for (int i=0; i<dimension; i++)
202 {
203 unites[i] = source_unites[0]+"/m";
204 }
205
206 return unites;
207 }
208 }
209
211}
212
214{
215 Entity loc;
216 Nom type_op = Op_Grad_->que_suis_je();
217 if ((type_op=="Op_Grad_P1NC_to_P0") && (index <= 0))
218 loc = Entity::ELEMENT;
219 else if ((type_op=="Op_Grad_P0_to_Face") && (index <= 0))
220 loc=Entity::FACE;
221 else
222 {
223 Cerr << "Error of type : Gradient operator " << type_op << " is not possible for the defined field " << nom_post_ << finl;
224 throw Champ_Generique_erreur("INVALID");
225 }
226 return loc;
227}
228//Name the field as a source by default
229//"Gradient_" + nom_champ_source
231{
232 if (nom_post_=="??")
233 {
234 Nom nom_post_source, nom_champ_source;
235 const Noms nom = get_source(0).get_property("nom");
236 nom_champ_source = nom[0];
237 nom_post_source = "Gradient_";
238 nom_post_source += nom_champ_source;
239 nommer(nom_post_source);
240 }
241}
242
244{
245 Motcle directive;
246
247 Nom type_op = Op_Grad_->que_suis_je();
248 if (type_op=="Op_Grad_P1NC_to_P0")
249 directive = "champ_elem";
250 else
251 directive = "gradient_pression";
252
253 return directive;
254}
class Champ_Fonc_base Base class of fields that are functions of a calculated quantity
const Noms get_property(const Motcle &query) const override
Returns the requested property.
virtual OWN_PTR(Champ_Fonc_base) &creer_espace_stockage(const Nature_du_champ &nature
void completer(const Postraitement_base &post) override
const Probleme_base & get_ref_pb_base() const override
Returns the problem that carries the target field.
virtual const Champ_Generique_base & get_source(int i) const
class Champ_Generique_Gradient OWN_PTR(Champ_base) intended to post-process the gradient of a generic...
void completer(const Postraitement_base &post) override
const Motcle get_directive_pour_discr() const override
Returns the directive (champ_elem, champ_sommets, champ_face or pression) to launch the discretizatio...
const Noms get_property(const Motcle &query) const override
Returns the requested property.
Entity get_localisation(const int index=-1) const override
Returns the type of geometric entities on which the discrete values are attached (NODE for a P1 field...
const Champ_base & get_champ_without_evaluation(OWN_PTR(Champ_base)&espace_stockage) const override
const Champ_base & get_champ(OWN_PTR(Champ_base)&espace_stockage) const override
Classe Champ_Generique_Operateur_base Base class for generic field classes dedicated to applying an o...
virtual const Noms get_property(const Motcle &query) const
Returns the requested property.
virtual const Champ_base & get_champ(OWN_PTR(Champ_base) &espace_stockage) const =0
void nommer(const Nom &nom) override
Assigns a name to the Objet_U. Virtual method to override.
Special field class that encapsulates a reference to a volume field of TRUST of type Champ_base.
Class Champ_Inc_base.
virtual DoubleTab & valeurs()=0
class Champ_base This class is the base of the fields hierarchy.
Definition Champ_base.h:43
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
class Equation_base The role of an equation is the calculation of one or more fields....
const Nom & le_nom() const override
Returns the name of the equation.
virtual const Champ_Inc_base & inconnue() const =0
virtual Domaine_Cl_dis_base & domaine_Cl_dis()
Returns the discretized boundary condition domain associated with the equation.
Domaine_dis_base & domaine_dis()
Returns the discretized domain associated with the equation.
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
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 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
Base class for all post-processing objects.
class Probleme_base It is a Probleme_U that is not a coupling.
virtual int nombre_d_equations() const =0
virtual const Equation_base & equation(int) const =0
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
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")