TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Operateur.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 <Discretisation_base.h>
17#include <Schema_Temps_base.h>
18#include <Operateur_base.h>
19#include <Probleme_base.h>
20#include <TRUSTTrav.h>
21#include <Operateur.h>
22#include <Perf_counters.h>
23
25{
26 os << " { " << typ << " } " << finl;
27 return os;
28}
29
30
31/*! @brief Reads an operator from an input stream.
32 *
33 * Types the operator and associates its equation with it.
34 * Format:
35 * {
36 * [A KEYWORD REPRESENTING A TYPE]
37 * }
38 *
39 * @param (Entree& is) the input stream from which to read the operator
40 * @return (Entree&) the modified input stream
41 * @throws opening brace expected
42 * @throws closing brace expected
43 */
45{
46 typ="non defini";
47 Motcle motlu;
48 is >> motlu ;
49 assert(motlu=="{");
50 while(motlu!="}")
51 {
52 is>>motlu;
53 if (motlu=="}")
54 {
55 if(typ=="non defini")
56 {
57 typ = "";
58 typer();
62 }
63 }
64 else if (motlu=="nb_sous_pas_de_temps")
65 {
66 if(typ=="non defini")
67 {
68 typ = "";
69 typer();
71 }
72 int nb_ss_pas_de_temps;
73 is >> nb_ss_pas_de_temps;
74 l_op_base().set_nb_ss_pas_de_temps(nb_ss_pas_de_temps);
76 }
77 else if (motlu=="implicite")
78 {
79 // XD op_implicite objet_lecture nul NO_BRACE not_set
80 // XD attr implicite chaine(into=["implicite"]) implicite REQ not_set
81 // XD attr mot chaine(into=["solveur"]) mot REQ not_set
82 // XD attr solveur solveur_sys_base solveur REQ not_set
83 if(typ=="non defini")
84 {
85 typ = "";
86 typer();
88 }
91 is >> motlu;
92 if(motlu != "solveur")
93 {
94 Cerr << "We expected the keyword \"solveur\" instead of : "
95 << motlu << finl;;
97 }
99 }
100 else
101 {
102 if(typ!="non defini")
103 {
104 Cerr << "We must choose the type of operator in beginning "
105 <<"of reading block (before implicit in particular) "
106 << finl;
108 }
109 typ=motlu;
110 typer();
114 is >> l_op_base();
115 }
116 }
117 return is;
118}
119
120/*! @brief Returns the field representing the unknown of the equation to which the operator belongs.
121 *
122 * @return (Champ_Inc_base&) the unknown field of the associated equation
123 */
125{
126 return le_champ_inco.valeur();
127}
128
129/*! @brief Returns the discretization of the equation to which the operator belongs.
130 *
131 * @return (Discretisation_base&) the discretization of the associated equation
132 */
134{
135 return mon_equation->discretisation();
136}
137
138/*! @brief Updates the references of the objects associated with the operator.
139 *
140 * Operateur::le_champ_inco, Operateur::champ_inco
141 * Calls Operateur_base::completer()
142 *
143 */
145{
146 if (!le_champ_inco)
147 le_champ_inco=mon_equation->inconnue();
148
150}
151
152void Operateur::associer_champ(const Champ_Inc_base& ch, const std::string& nom_ch)
153{
154 le_champ_inco = ch;
155 nom_inco_ = nom_ch;
156 l_op_base().associer_champ(ch, nom_ch);
157}
158
159/*! @brief Performs a time update of the operator.
160 *
161 * Calls Operateur_base::mettre_a_jour(double)
162 *
163 * @param (double temps) the time step for update
164 */
165void Operateur::mettre_a_jour(double temps)
166{
167 l_op_base().mettre_a_jour(temps);
168}
169/*! @brief Computes the next time step.
170 *
171 */
173{
174 // If the operator's equation is not solved, we do not compute its stability time step
175 if (equation().equation_non_resolue())
176 return DMAXFLOAT;
177 statistics().begin_count(STD_COUNTERS::compute_dt,statistics().get_last_opened_counter_level()+1);
178 double dt_stab = l_op_base().calculer_dt_stab();
179 statistics().end_count(STD_COUNTERS::compute_dt);
180 // Check that the operator did perform an mp_min:
181 assert(dt_stab==Process::mp_min(dt_stab));
182 return dt_stab;
183}
184/*! @brief Calculate the next local time steps
185 *
186 */
187void Operateur::calculer_pas_de_temps_locaux(DoubleTab& dt_locaux) const
188{
189 l_op_base().calculer_dt_local(dt_locaux);
190}
191/*! @brief Asks the equation whether printing is needed. Returns 1 for YES, 0 otherwise.
192 *
193 * @return (int) 1 if printing is needed, 0 otherwise
194 */
196{
197 return mon_equation->limpr();
198}
199
200/*! @brief Prints the operator to an output stream, if necessary.
201 *
202 * (see Schema_Temp_base::limpr())
203 *
204 * @param (Sortie& os) the output stream for printing
205 */
207{
208 if(limpr()) l_op_base().impr(os);
209}
210
211
212/*! @brief Prints the operator to an output stream unconditionally.
213 *
214 * @param (Sortie& os) the output stream for printing
215 * @return (int) return code of Operateur_base::impr(Sortie&)
216 */
218{
219 if (l_op_base().has_impr_file()) return l_op_base().impr(os);
220 return 1;
221}
222
223/*! @brief Computes and adds the contribution of the operator to the right-hand side of the equation.
224 *
225 * Calls Operateur::ajouter(const DoubleTab&, DoubleTab& )
226 *
227 * @param (Champ_Inc_base& ch) the unknown field on which the operator acts
228 * @param[in,out] (DoubleTab& resu) the array storing the right-hand side values to which the operator contribution is added
229 * @return (DoubleTab&) the right-hand side to which the operator contribution has been added
230 */
231DoubleTab& Operateur::ajouter(const Champ_Inc_base& ch, DoubleTab& resu) const
232{
233 int i ;
234 int nstep=l_op_base().get_nb_ss_pas_de_temps();
235 double dt=equation().schema_temps().pas_de_temps();
236 dt/=nstep;
237 if(nstep==1)
238 return ajouter(ch.valeurs(), resu);
239 DoubleTrav derivee(resu);
240 DoubleTrav inco(ch.valeurs());
241 inco=ch.valeurs();
242 const Solveur_Masse_base& solveur_masse=equation().solv_masse();
243 double dt_inv=1./(double(nstep));
244 for (i=0; i<nstep; i++)
245 {
246 calculer(inco, derivee);
247 derivee.echange_espace_virtuel();
248 resu.ajoute(dt_inv, derivee) ;
249 solveur_masse.appliquer(derivee);
250 inco.ajoute_sans_ech_esp_virt(dt, derivee, VECT_ALL_ITEMS) ;
251 }
252 return resu;
253}
254
255/*! @brief Returns the (name of the) type of operator to create.
256 *
257 * @return (Nom&) the name of the type of operator to create
258 */
259const Nom& Operateur::type() const
260{
261 return typ;
262}
263
264
265/*! @brief Computes the contribution of the operator and returns the array of values.
266 *
267 * @param (Champ_Inc_base& ch) the unknown field on which the operator acts
268 * @param (DoubleTab& resu) the array storing the values resulting from applying the operator to the unknown field.
269 * @return (DoubleTab&) the result of applying the operator to the unknown field
270 */
271DoubleTab& Operateur::calculer(const Champ_Inc_base& ch,DoubleTab& resu) const
272{
273 return calculer(ch.valeurs(), resu);
274}
275
276/*! @brief Adds the contribution of the operator to the array passed as parameter.
277 *
278 * Calls Operateur::ajouter(const Champ_Inc_base&, DoubleTab& )
279 *
280 * @param (DoubleTab& resu) the array storing the right-hand side values to which the operator contribution is added
281 * @return (DoubleTab&) the right-hand side to which the operator contribution has been added
282 */
283DoubleTab& Operateur::ajouter(DoubleTab& resu) const
284{
285 return ajouter(le_champ_inco->valeurs(), resu);
286}
287
288/*! @brief Applies the operator to the unknown field and returns the result.
289 *
290 * Calls Operateur::calculer(const Champ_Inc_base&, DoubleTab& );
291 *
292 * @param (DoubleTab& resu) the array storing the values resulting from applying the operator to the unknown field.
293 * @return (DoubleTab&) the result of applying the operator to the unknown field
294 */
295DoubleTab& Operateur::calculer(DoubleTab& resu) const
296{
297 resu=0.;
298 return ajouter(le_champ_inco->valeurs(), resu);
299}
300
302{
303 l_op_base().set_fichier(nom);
304}
305
307{
309}
310
311void Operateur::ajouter_contribution_explicite_au_second_membre (const Champ_Inc_base& linconnue, DoubleTab& derivee) const
312{
314}
Class Champ_Inc_base.
DoubleTab & valeurs() override
Returns the array of field values at the current time.
class Discretisation_base This class represents a spatial discretization scheme, which
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Solveur_Masse_base & solv_masse()
Returns the mass solver associated with the equation.
Schema_Temps_base & schema_temps()
Returns the time scheme associated with the equation.
const Equation_base & equation() const
Returns the reference to the equation pointed to by MorEqn::mon_equation.
Definition MorEqn.h:62
A character string (Nom) in uppercase.
Definition Motcle.h:26
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
void set_fichier(const Nom &)
virtual void calculer_dt_local(DoubleTab &) const
virtual void associer_champ(const Champ_Inc_base &, const std::string &nom_ch)
virtual void mettre_a_jour(double temps)
DOES NOTHING - to override in derived classes.
virtual double calculer_dt_stab() const
Computes dt_stab.
int set_nb_ss_pas_de_temps(int)
virtual void completer()
Associates the operator with the domaine_dis, the domaine_Cl_dis, and the unknown of its equation.
int get_nb_ss_pas_de_temps() const
virtual int impr(Sortie &os) const
DOES NOTHING - to override in derived classes.
Entree & lire_solveur(Entree &)
virtual void ajouter_contribution_explicite_au_second_membre(const Champ_Inc_base &inconnue, DoubleTab &derivee) const
void set_description(const Nom &nom)
void associer_eqn(const Equation_base &)
Associates an equation with the operator.
int set_decal_temps(int)
std::string nom_inco_
Definition Operateur.h:74
const Champ_Inc_base & mon_inconnue() const
Returns the field representing the unknown of the equation to which the operator belongs.
virtual Operateur_base & l_op_base()=0
virtual void typer()=0
Entree & lire(Entree &)
Reads an operator from an input stream.
Definition Operateur.cpp:44
double calculer_pas_de_temps() const
Computes the next time step.
int limpr() const
Asks the equation whether printing is needed. Returns 1 for YES, 0 otherwise.
int impr(Sortie &os) const
Prints the operator to an output stream unconditionally.
virtual DoubleTab & calculer(const DoubleTab &, DoubleTab &) const =0
Sortie & ecrire(Sortie &) const
Definition Operateur.cpp:24
void imprimer(Sortie &os) const
Prints the operator to an output stream, if necessary.
virtual void mettre_a_jour(double temps)
Performs a time update of the operator.
const Nom & type() const
Returns the (name of the) type of operator to create.
const Discretisation_base & discretisation() const
Returns the discretization of the equation to which the operator belongs.
void ajouter_contribution_explicite_au_second_membre(const Champ_Inc_base &inconnue, DoubleTab &derivee) const
virtual DoubleTab & ajouter(const DoubleTab &, DoubleTab &) const =0
void set_description(const Nom &nom)
virtual void completer()
Updates the references of the objects associated with the operator.
void set_fichier(const Nom &nom)
Motcle typ
Definition Operateur.h:76
void associer_champ(const Champ_Inc_base &, const std::string &nom_ch)
void calculer_pas_de_temps_locaux(DoubleTab &) const
Calculate the next local time steps.
static double mp_min(double)
Definition Process.cpp:391
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
double pas_de_temps() const
Returns the current time step (delta_t).
Solveur_Masse_base Represents the mass matrix of an equation.
virtual DoubleTab & appliquer(DoubleTab &) const
Returns appliquer_impl(x/temporal_coefficient) if a temporal coefficient is set, otherwise returns ap...
Base class for output streams.
Definition Sortie.h:52
void ajoute(_SCALAR_TYPE_ alpha, const TRUSTVect &y, Mp_vect_options opt=VECT_ALL_ITEMS)
Definition TRUSTVect.tpp:52
void ajoute_sans_ech_esp_virt(_SCALAR_TYPE_ alpha, const TRUSTVect &y, Mp_vect_options opt=VECT_REAL_ITEMS)
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")