TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Couplage_U.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 <Couplage_U.h>
17#include <Probleme_base.h>
18
19
20Implemente_instanciable(Couplage_U,"Couplage_U",Probleme_U);
21
22//////////////////////////////////////////////////
23// //
24// Implementation de l'interface de Probleme_U //
25// //
26//////////////////////////////////////////////////
27
28
30{
31 for(int i=0; i<nb_problemes(); i++)
33 for(int i=0; i<nb_problemes(); i++)
35}
36
38{
39 for(int i=0; i< nb_problemes(); i++)
41}
42
44{
45 assert(nb_problemes()>0);
46 return probleme(0).presentTime();
47}
48
50{
51 bool ok=true;
52 for(int i=0; i<nb_problemes(); i++)
53 ok = ok && probleme(i).initTimeStep(dt);
54 return ok;
55}
56
57
59{
60 for(int i=0; i<nb_problemes(); i++)
62}
63
65{
66 bool stat=true;
67 for(int i=0; i<nb_problemes(); i++)
68 stat = stat && probleme(i).isStationary();
69 return stat;
70}
71
73{
74 Cerr << "[Parameter] ----------------------------" << finl;
75 std::string dir="";
76 for(int i=0; i<nb_problemes(); i++)
77 {
78 std::string dirname = ref_cast(Probleme_base, probleme(i)).newCompute();
79 dir = dirname.empty() ? dir : dirname;
80 }
81 return dir;
82}
83
85{
86 for(int i=0; i<nb_problemes(); i++)
87 probleme(i).setStationary(flag);
88}
89
91{
92 for(int i=0; i<nb_problemes(); i++)
94}
95
97{
98 const std::string current_dirname = Sortie_Fichier_base::root;
99 for(int i=0; i<nb_problemes(); i++)
100 {
101 if (str_params_.count("SORTIE_ROOT_DIRECTORY") != 0)
102 {
103 // We transmit the SORTIE_ROOT_DIRECTORY to each problem:
104 probleme(i).setInputStringValue("SORTIE_ROOT_DIRECTORY", getOutputStringValue("SORTIE_ROOT_DIRECTORY"));
105 // We reset the IO directory to the current dirname before post-processing
106 Sortie_Fichier_base::set_root(current_dirname);
107 }
108 probleme(i).resetTime(t);
109 }
110}
111
112bool Couplage_U::iterateTimeStep(bool& converged)
113{
114 bool ok=true;
115 converged=true;
116 for(int i=0; i<nb_problemes(); i++)
117 {
118 bool cv = false;
119 ok = ok && probleme(i).iterateTimeStep(cv);
120 converged = converged && cv;
121 }
122 return ok;
123}
124
125// Adds the input fields names this pb understands to noms
127{
128 for (int i=0; i<nb_problemes(); i++)
130}
131// Adds the output fields names this pb understands to noms
133{
134 for (int i=0; i<nb_problemes(); i++)
136}
137
138
140{
141 int ok=1;
142 for(int i=0; i<nb_problemes(); i++)
143 ok = ok && probleme(i).postraiter(force);
144 return ok;
145}
146
148{
149 bool ok=false;
150 for(int i=0; i<nb_problemes(); i++)
151 ok = ok || probleme(i).limpr();
152 return ok;
153}
154
156{
157 bool ok=false;
158 for(int i=0; i<nb_problemes(); i++)
159 ok = ok || probleme(i).lsauv();
160 return ok;
161}
162
164{
165 for(int i=0; i<nb_problemes(); i++)
166 probleme(i).sauver();
167}
168
170{
171 bool ok=true;
172 for(int i=0; i<nb_problemes(); i++)
173 ok = ok && probleme(i).updateGivenFields();
174 return ok;
175}
176
178{
179 assert(nb_problemes()>0);
180 return probleme(0).futureTime();
181}
182
183OBS_PTR(Field_base) Couplage_U::findInputField(const Nom& name) const
184{
186 for (int i=0; i<nb_problemes(); i++)
187 {
188 ch=probleme(i).findInputField(name);
189 if (ch)
190 return ch;
191 }
192 return ch;
193}
194OBS_PTR(Champ_Generique_base) Couplage_U::findOutputField(const Nom& name) const
195{
196 OBS_PTR(Champ_Generique_base) ch;
197 for (int i=0; i<nb_problemes(); i++)
198 {
199 ch=probleme(i).findOutputField(name);
200 if (ch)
201 return ch;
202 }
203 return ch;
204}
205
206///////////////////////////////////////////////////////////
207// //
208// Fin de l'implementation de l'interface de Probleme_U //
209// //
210///////////////////////////////////////////////////////////
211
212
213
214// PrintOn and ReadOn
215
217{
218 return s << que_suis_je() << finl;
219}
220
222{
223 return s ;
224}
225
226
227int Couplage_U::indice_probleme(const Nom& nom_pb) const
228{
229 int i=0;
230 while ((i< nb_problemes()))
231 {
232 if(probleme(i).le_nom()==nom_pb)
233 {
234 return i;
235 }
236 i++;
237 }
238 Cerr << "Problem " << nom_pb
239 << " not found in Couplage_U " << le_nom() << finl;
240 exit();
241 // Avoid compiler warning
242 return 0;
243}
class Champ_Generique_base
class Couplage_U
Definition Couplage_U.h:31
void validateTimeStep() override
Validates the calculated unknown by moving the present time at the end of the time step.
double presentTime() const override
Returns the present time.
int postraiter(int force=1) override
Demande au probleme de postraiter ses champs, sondes,.
const Probleme_U & probleme(int i) const
Definition Couplage_U.h:127
void initialize() override
This method is called once at the beginning, before any other one of the interface Problem.
OBS_PTR(Field_base) findInputField(const Nom &name) const override
bool iterateTimeStep(bool &converged) override
In the case solveTimeStep uses an iterative process, this method executes a single iteration.
void sauver() const override
Sauvegarder l'etat du probleme sur disque.
int lsauv() const override
Doit-on sauvegarder l'etat du probleme sur disque maintenant ?
void resetTime(double t) override
Reset the current time of the Problem to a given value.
bool initTimeStep(double dt) override
This method allocates and initializes the unknown and given fields for the future time step.
void setStationary(bool) override
Tells to the Problem that stationary is reached or not.
void abortTimeStep() override
Aborts the resolution of the current time step.
int limpr() const override
Doit-on imprimer les statistiques d'execution maintenant ?
bool updateGivenFields() override
ATTENTION :
void terminate() override
This method is called once at the end, after any other one.
int indice_probleme(const Nom &nom_pb) const
void getOutputFieldsNames(Noms &noms) const override
double futureTime() const override
Returns the future time (end of current computing interval) This value is valid between initTimeStep ...
std::string newCompute() override
int nb_problemes() const
Definition Couplage_U.h:117
bool isStationary() const override
Tells if the Problem unknowns have changed during the last time step.
void getInputFieldsNames(Noms &noms) const override
This method is used to find the names of input fields understood by the Problem.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
Un tableau de chaine de caracteres (VECT(Nom)).
Definition Noms.h:26
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
classe Probleme_U
Definition Probleme_U.h:46
virtual void sauver() const
Sauvegarder l'etat du probleme sur disque.
virtual int postraiter(int force=1)
Demande au probleme de postraiter ses champs, sondes,.
virtual void getInputFieldsNames(Noms &noms) const
This method is used to find the names of input fields understood by the Problem.
virtual bool initTimeStep(double dt)
This method allocates and initializes the unknown and given fields for the future time step.
virtual void validateTimeStep()
Validates the calculated unknown by moving the present time at the end of the time step.
virtual int limpr() const
Doit-on imprimer les statistiques d'execution maintenant ?
const Nom & le_nom() const override
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
Definition Probleme_U.h:109
virtual bool iterateTimeStep(bool &converged)
In the case solveTimeStep uses an iterative process, this method executes a single iteration.
virtual void setInputStringValue(const std::string &name, const std::string &val)
Definition Probleme_U.h:88
virtual void terminate()
This method is called once at the end, after any other one.
virtual void abortTimeStep()
Aborts the resolution of the current time step.
virtual double futureTime() const
Returns the future time (end of current computing interval) This value is valid between initTimeStep ...
virtual int lsauv() const
Doit-on sauvegarder l'etat du probleme sur disque maintenant ?
virtual std::string getOutputStringValue(const std::string &name)
virtual bool isStationary() const
Tells if the Problem unknowns have changed during the last time step.
virtual double presentTime() const
Returns the present time.
virtual void setStationary(bool)
Tells to the Problem that stationary is reached or not.
virtual void getOutputFieldsNames(Noms &noms) const
std::map< std::string, std::string > str_params_
Definition Probleme_U.h:114
virtual void resetTime(double time)
Reset the current time of the Problem to a given value.
virtual bool updateGivenFields()
ATTENTION :
virtual void post_initialize()
Definition Probleme_U.h:91
virtual void initialize()
This method is called once at the beginning, before any other one of the interface Problem.
classe Probleme_base C'est un Probleme_U qui n'est pas un couplage.
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
static void set_root(const std::string dirname)
static std::string root
Classe de base des flux de sortie.
Definition Sortie.h:52