TrioCFD 1.9.9_beta
TrioCFD documentation
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 of the Probleme_U interface //
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// End of the Probleme_U interface implementation //
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
Asks the problem to post-process its fields, probes, etc.
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
Save the problem state to disk.
int lsauv() const override
Should we save the problem state to disk now?
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
Should we print the execution statistics now?
bool updateGivenFields() override
WARNING:
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: a character string for naming TRUST objects.
Definition Nom.h:31
An array of character strings (VECT(Nom)).
Definition Noms.h:26
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
Probleme_U.
Definition Probleme_U.h:46
virtual void sauver() const
Save the problem state to disk.
virtual int postraiter(int force=1)
Asks the problem to post-process its fields, probes, etc.
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
Should we print the execution statistics now?
const Nom & le_nom() const override
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this 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
Should we save the problem state to disk now?
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()
WARNING:
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.
class Probleme_base It is a Probleme_U that is not a coupling.
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
static void set_root(const std::string dirname)
static std::string root
Base class for output streams.
Definition Sortie.h:52