TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_Fonc_base.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 <EcritureLectureSpecial.h>
17#include <Champ_Fonc_base.h>
18#include <MD_Vector_tools.h>
19#include <Domaine_VF.h>
20#include <Domaine.h>
21#include <TRUSTTrav.h>
22#include <TRUST_2_PDI.h>
23
24Implemente_base(Champ_Fonc_base, "Champ_Fonc_base", Champ_Don_base);
25
26Sortie& Champ_Fonc_base::printOn(Sortie& s) const { return s; }
27
28Entree& Champ_Fonc_base::readOn(Entree& s) { return s; }
29
31{
32 le_dom_VF = ref_cast(Domaine_VF, z_dis);
33}
34
36{
37 return le_dom_VF ? le_dom_VF.valeur() : Champ_Don_base::domaine_dis_base() /* throw */;
38}
39
41{
42 assert (le_dom_VF);
43 return le_dom_VF.valeur();
44}
45
46/*! @brief Time update of the field.
47 *
48 * @param (double temps) the update time
49 */
50void Champ_Fonc_base::mettre_a_jour(double un_temps)
51{
52 changer_temps(un_temps);
54}
55
57{
58 Cerr << "Error in Champ_Fonc_base::fixer_nb_valeurs_nodales: method not reimplemented for the class " << que_suis_je() << finl;
60 return nb_noeuds;
61}
62
63void Champ_Fonc_base::creer_tableau_distribue(const MD_Vector& md, RESIZE_OPTIONS opt)
64{
65 // Note B.M.: to be symmetric with Champ_Inc_base, we should test if the
66 // field is scalar or multi-scalar (see Champ_Inc_base::creer_tableau_distribue())
67 if (valeurs_.size_array() == 0 && (!valeurs_.get_md_vector()))
68 {
69 // Note B.M.: the fixer_nb_valeurs_nodales methods are called haphazardly.
70 // Do nothing if the array already has the correct structure
71 valeurs_.resize(0, nb_compo_);
72 }
73 // This will crash if we attached another parallel structure (this is intentional!)
74 if (!(valeurs_.get_md_vector() == md))
75 {
76 if (valeurs_.get_md_vector())
77 {
78 Cerr << "Internal error in Champ_Fonc_base::creer_tableau_distribue:\n" << " array has already a (wrong) parallel descriptor" << finl;
80 }
82 }
83}
84
85
87{
88 Nom name = pdi_name_ == "??" ? (Motcle)nom_ : (Motcle)pdi_name_;
89 return name;
90}
91
92/*! @brief for PDI IO: retrieve name, type and dimensions of the field to save/restore.
93 */
94std::vector<YAML_data> Champ_Fonc_base::data_a_sauvegarder() const
95{
96 const Nom& name = get_pdi_name();
97 int nb_dim = valeurs().nb_dim();
98 YAML_data d(name.getString(), "double", nb_dim);
99 std::vector<YAML_data> data;
100 data.push_back(d);
101 return data;
102}
103
104/*! @brief Saves the field to an output stream. Writes the name, time and values.
105 *
106 * @param (Sortie& fich) an output stream
107 * @return (int) always returns 1
108 */
110{
111 // in special write mode only the master writes the header
112 int a_faire, special;
114
115 if (a_faire)
116 {
117 Nom mon_ident(nom_);
118 mon_ident += que_suis_je();
119 mon_ident += domaine_dis_base().domaine().le_nom();
120 mon_ident += Nom(temps_, "%e");
121 fich << mon_ident << finl;
122 fich << que_suis_je() << finl;
123 fich << temps_ << finl;
124 }
125 int bytes = 0;
126 if (special)
127 bytes = EcritureLectureSpecial::ecriture_special(*this, fich);
129 {
130 bytes = 8 * valeurs().size_array();
131 const Nom& name = get_pdi_name();
132 TRUST_2_PDI pdi_interface;
133 pdi_interface.share_TRUSTTab_dimensions(valeurs(), name, 1 /*write mode*/);
134
135 // Sharing the unknown field with PDI
136 if( valeurs().dimension_tot(0) )
137 pdi_interface.TRUST_start_sharing(name.getString(), valeurs().addr());
138 else
139 {
140 // if the dimension is null in a direction - might happen in parallel - sharing an empty array
141 ArrOfDouble garbage( valeurs().nb_dim() );
142 pdi_interface.TRUST_start_sharing(name.getString(), garbage.addr());
143 }
144 }
145 else
146 {
147 bytes = 8 * valeurs().size_array();
148 valeurs().ecrit(fich);
149 }
150 if (a_faire)
151 {
152 //fich << flush ; Does not work in binary, prefer:
153 fich.flush();
154 }
155 Cerr << "Backup of the field " << nom_ << " performed on time : " << Nom(temps_, "%e") << finl;
156
157 return bytes;
158}
159
160/*! @brief Restart from an input stream. Reads the time and values of the field.
161 *
162 * Skips a block if the field name is "anonymous".
163 *
164 * @param (Entree& fich) an input stream
165 * @return (int) always returns 1
166 */
168{
169 double un_temps;
171 if (nom_ != Nom("anonyme")) // reading for restart
172 {
173 Cerr << "Resume of the field " << nom_;
175 {
176 TRUST_2_PDI pdi_interface;
177 const Nom& name = get_pdi_name();
178 pdi_interface.share_TRUSTTab_dimensions(valeurs(), name, 0 /*read mode*/);
179 pdi_interface.read(name.getChar(), valeurs().addr());
180 }
181 else
182 {
183 fich >> un_temps;
184 if (special)
186 else
187 valeurs().lit(fich);
188 }
189 Cerr << " performed." << finl;
190 }
191 else // reading to skip the block
192 {
194 {
195 Cerr << finl << "Problem in the resumption " << finl;
196 Cerr << "PDI format does not require to navigate through file..." << finl;
198 }
199 DoubleTab tempo;
200 fich >> un_temps;
201 tempo.jump(fich);
202 }
203 return 1;
204}
205
206/*! @brief Assigns a Champ_base to a Champ_Fonc_base.
207 *
208 * @param (Champ_base& ch) the field on the right side of the assignment
209 * @return (Champ_base&) the result of the assignment (*this) (with upcast)
210 */
212{
213 DoubleTab noeuds;
214 remplir_coord_noeuds(noeuds);
215 ch.valeur_aux(noeuds, valeurs());
216
217 return *this;
218}
219
220/*! @brief Assigns a component of a Champ_base to the same component of a Champ_Fonc_base.
221 *
222 * @param (Champ_base& ch) the field on the right side of the assignment
223 * @param (int compo) the index of the component to assign
224 * @return (Champ_base&) the result of the assignment (*this) (with upcast)
225 */
227{
228 DoubleTab noeuds;
229 IntVect polys;
230 if (!remplir_coord_noeuds_et_polys_compo(noeuds, polys, compo))
231 {
232 remplir_coord_noeuds_compo(noeuds, compo);
233 ch.valeur_aux_compo(noeuds, valeurs(), compo);
234 }
235 else
236 ch.valeur_aux_elems_compo(noeuds, polys, valeurs(), compo);
237 return *this;
238}
239
240/*! @brief DOES NOTHING TO override in derived classes
241 *
242 * @param (DoubleTab&)
243 * @param (IntVect&)
244 * @return (int) always returns 0
245 */
247{
248 return 0;
249}
250
251/*! @brief DOES NOTHING TO override in derived classes
252 *
253 * @param (DoubleTab& coord)
254 * @return (DoubleTab&) always returns the coord parameter
255 */
256DoubleTab& Champ_Fonc_base::remplir_coord_noeuds(DoubleTab& coord) const
257{
258 return coord;
259}
260
261/*! @brief DOES NOTHING TO override in derived classes
262 *
263 * @param (DoubleTab& coord)
264 * @param (int)
265 * @return (DoubleTab&) always returns the coord parameter
266 */
267DoubleTab& Champ_Fonc_base::remplir_coord_noeuds_compo(DoubleTab& coord, int) const
268{
269 return coord;
270}
271
272/*! @brief DOES NOTHING TO override in derived classes
273 *
274 * @param (DoubleTab&)
275 * @param (IntVect&)
276 * @param (int)
277 * @return (int) always returns 0
278 */
280{
281 return 0;
282}
283
284const Domaine& Champ_Fonc_base::domaine() const
285{
286 return domaine_dis_base().domaine();
287}
288
289DoubleTab& Champ_Fonc_base::valeur_aux(const DoubleTab& positions, DoubleTab& tab_valeurs) const
290{
291 const Domaine& domaine = domaine_dis_base().domaine();
292 IntTrav les_polys;
293 domaine.chercher_elements(positions, les_polys);
294 return valeur_aux_elems(positions, les_polys, tab_valeurs);
295}
class Champ_Don_base base class of Given Fields (not calculated)
DoubleTab & valeurs() override
Overrides Champ_base::valeurs() Returns the array of values.
DoubleTab valeurs_
class Champ_Fonc_base Base class of fields that are functions of a calculated quantity
Champ_base & affecter_compo(const Champ_base &, int compo) override
Assigns a component of a Champ_base to the same component of a Champ_Fonc_base.
void associer_domaine_dis_base(const Domaine_dis_base &) override
virtual DoubleTab & remplir_coord_noeuds_compo(DoubleTab &, int) const
DOES NOTHING TO override in derived classes.
virtual int remplir_coord_noeuds_et_polys(DoubleTab &, IntVect &) const
DOES NOTHING TO override in derived classes.
virtual int remplir_coord_noeuds_et_polys_compo(DoubleTab &, IntVect &, int) const
DOES NOTHING TO override in derived classes.
virtual const Domaine & domaine() const
DoubleTab & valeur_aux(const DoubleTab &, DoubleTab &) const override
Causes an error! Must be overridden by derived classes.
virtual const Domaine_VF & domaine_vf() const
Champ_base & affecter_(const Champ_base &) override
Assigns a Champ_base to a Champ_Fonc_base.
void mettre_a_jour(double temps) override
Time update of the field.
virtual std::vector< YAML_data > data_a_sauvegarder() const
for PDI IO: retrieve name, type and dimensions of the field to save/restore.
virtual DoubleTab & remplir_coord_noeuds(DoubleTab &) const
DOES NOTHING TO override in derived classes.
int reprendre(Entree &) override
Restart from an input stream. Reads the time and values of the field.
virtual void creer_tableau_distribue(const MD_Vector &, RESIZE_OPTIONS=RESIZE_OPTIONS::COPY_INIT)
const Domaine_dis_base & domaine_dis_base() const override
int sauvegarder(Sortie &) const override
Saves the field to an output stream. Writes the name, time and values.
Nom get_pdi_name() const
int fixer_nb_valeurs_nodales(int nb_noeuds) override
Sets the number of degrees of freedom per component.
double temps_
Definition Champ_base.h:123
Champ_base()
Default constructor of a Champ_base.
virtual const Domaine_dis_base & domaine_dis_base() const
virtual DoubleVect & valeur_aux_elems_compo(const DoubleTab &positions, const IntVect &les_polys, DoubleVect &valeurs, int ncomp) const
Causes an error! Must be overridden by derived classes.
virtual double changer_temps(const double t)
Sets the time at which the field is defined.
virtual DoubleTab & valeur_aux(const DoubleTab &positions, DoubleTab &valeurs) const
Causes an error! Must be overridden by derived classes.
virtual DoubleTab & valeur_aux_elems(const DoubleTab &positions, const IntVect &les_polys, DoubleTab &valeurs) const
Causes an error! Must be overridden by derived classes.
virtual DoubleVect & valeur_aux_compo(const DoubleTab &positions, DoubleVect &valeurs, int ncomp) const
Same as valeur_aux(const DoubleTab &, DoubleTab &), but computes only the component compo of the fiel...
class Domaine_VF
Definition Domaine_VF.h:44
const Nom & le_nom() const override
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
class Domaine_dis_base This class is the base of the hierarchy of discretized domains.
const Domaine & domaine() const
static int is_ecriture_special(int &special, int &a_faire)
Indicates whether the special format was requested in active writing by xyz save.
static int is_lecture_special()
Indicates whether the special format was requested in active reading by xyz restart.
static int ecriture_special(const Champ_base &ch, Sortie &fich)
Simple call to EcritureLectureSpecial::ecriture_special (const Domaine_VF& zvf,Sortie& fich,...
static void lecture_special(Champ_base &ch, Entree &fich)
Simple call to EcritureLectureSpecial::lecture_special (const Domaine_VF& zvf,Entree& fich,...
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
int nb_compo_
Definition Field_base.h:95
static void creer_tableau_distribue(const MD_Vector &, Array_base &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Transforms v into a parallel array having the structure md.
: This class is an OWN_PTR but the pointed object is shared among multiple
Definition MD_Vector.h:48
A character string (Nom) in uppercase.
Definition Motcle.h:26
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
const char * getChar() const
Definition Nom.h:91
const std::string & getString() const
Definition Nom.h:92
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
virtual Sortie & flush()
Definition Sortie.cpp:138
_SIZE_ size_array() const
_TYPE_ * addr()
void jump(Entree &) override
Definition TRUSTTab.tpp:701
void lit(Entree &, bool resize_and_read=true) override
Definition TRUSTTab.tpp:710
int nb_dim() const
Definition TRUSTTab.h:199
void ecrit(Sortie &) const override
Definition TRUSTTab.tpp:688
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")
TRUST_2_PDI Encapsulation of PDI methods (library used for IO operations). See the website pdi....
Definition TRUST_2_PDI.h:59
void read(const std::string &name, void *data)
static int is_PDI_checkpoint()
static int is_PDI_restart()
void share_TRUSTTab_dimensions(const DoubleTab &tab, const Nom &name, int write)
Generic method to share the dimensions of a TRUST DoubleTab with PDI.
void TRUST_start_sharing(const std::string &name, const void *data)
YAML_data class: collection of all needed information for data to save/restore in order to write the ...
Definition YAML_data.h:26