TRUST 1.9.8
HPC thermohydraulic platform
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 Mise a jour en temps du champ.
47 *
48 * @param (double temps) le temps de mise a jour
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.: pour etre symetrique avec Champ_Inc_base, il faudrait tester si le
66 // champ est scalaire ou multi-scalaire (voir Champ_Inc_base::creer_tableau_distribue())
67 if (valeurs_.size_array() == 0 && (!valeurs_.get_md_vector()))
68 {
69 // Note B.M.: les methodes fixer_nb_valeurs_nodales sont appelees a tort et a travers.
70 // Ne rien faire si le tableau a deja la bonne structure
71 valeurs_.resize(0, nb_compo_);
72 }
73 // Ca va planter si on a attache une autre structure parallele (c'est voulu !)
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 Sauvegarde le champ sur un flot de sortie Ecrit le nom, le temps et les valeurs.
105 *
106 * @param (Sortie& fich) un flot de sortie
107 * @return (int) renvoie toujours 1
108 */
110{
111 // en mode ecriture special seul le maitre ecrit l'entete
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 ; Ne marche pas en binaire, preferer:
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 Reprise a partir d'un flot d'entree Lit le temps et les valeurs du champ.
161 *
162 * Saute un bloc si le nom du champ est "anonyme".
163 *
164 * @param (Entree& fich) un flot d'entree
165 * @return (int) renvoie toujours 1
166 */
168{
169 double un_temps;
171 if (nom_ != Nom("anonyme")) // lecture pour reprise
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 // lecture pour sauter le bloc
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 Affecte un Champ_base dans un Champ_Fonc_base.
207 *
208 * @param (Champ_base& ch) le champ partie droite de l'affectation
209 * @return (Champ_base&) le resultat de l'affectation (*this) (avec 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 Affecte une composante d'un Champ_base dans la meme composnate d'un Champ_Fonc_base.
221 *
222 * @param (Champ_base& ch) le champ partie droite de l'affectation
223 * @param (int compo) l'indice de la composante a affecter
224 * @return (Champ_base&) le resultat de l'affectation (*this) (avec 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 NE FAIT RIEN A surcharger dans les classes derivees
241 *
242 * @param (DoubleTab&)
243 * @param (IntVect&)
244 * @return (int) renvoie toujours 0
245 */
247{
248 return 0;
249}
250
251/*! @brief NE FAIT RIEN A surcharger dans les classes derivees
252 *
253 * @param (DoubleTab& coord)
254 * @return (DoubleTab&) renvoie toujours le parametre coord
255 */
256DoubleTab& Champ_Fonc_base::remplir_coord_noeuds(DoubleTab& coord) const
257{
258 return coord;
259}
260
261/*! @brief NE FAIT RIEN A surcharger dans les classes derivees
262 *
263 * @param (DoubleTab& coord)
264 * @param (int)
265 * @return (DoubleTab&) renvoie toujours le parametre coord
266 */
267DoubleTab& Champ_Fonc_base::remplir_coord_noeuds_compo(DoubleTab& coord, int) const
268{
269 return coord;
270}
271
272/*! @brief NE FAIT RIEN A surcharger dans les classes derivees
273 *
274 * @param (DoubleTab&)
275 * @param (IntVect&)
276 * @param (int)
277 * @return (int) renvoie toujours 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}
classe Champ_Don_base classe de base des Champs donnes (non calcules)
DoubleTab & valeurs() override
Surcharge Champ_base::valeurs() Renvoie le tableau des valeurs.
DoubleTab valeurs_
classe Champ_Fonc_base Classe de base des champs qui sont fonction d'une grandeur calculee
Champ_base & affecter_compo(const Champ_base &, int compo) override
Affecte une composante d'un Champ_base dans la meme composnate d'un Champ_Fonc_base.
void associer_domaine_dis_base(const Domaine_dis_base &) override
virtual DoubleTab & remplir_coord_noeuds_compo(DoubleTab &, int) const
NE FAIT RIEN A surcharger dans les classes derivees.
virtual int remplir_coord_noeuds_et_polys(DoubleTab &, IntVect &) const
NE FAIT RIEN A surcharger dans les classes derivees.
virtual int remplir_coord_noeuds_et_polys_compo(DoubleTab &, IntVect &, int) const
NE FAIT RIEN A surcharger dans les classes derivees.
virtual const Domaine & domaine() const
DoubleTab & valeur_aux(const DoubleTab &, DoubleTab &) const override
Provoque une erreur ! Doit etre surchargee par les classes derivees.
virtual const Domaine_VF & domaine_vf() const
Champ_base & affecter_(const Champ_base &) override
Affecte un Champ_base dans un Champ_Fonc_base.
void mettre_a_jour(double temps) override
Mise a jour en temps du champ.
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
NE FAIT RIEN A surcharger dans les classes derivees.
int reprendre(Entree &) override
Reprise a partir d'un flot d'entree Lit le temps et les valeurs du champ.
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
Sauvegarde le champ sur un flot de sortie Ecrit le nom, le temps et les valeurs.
Nom get_pdi_name() const
int fixer_nb_valeurs_nodales(int nb_noeuds) override
Fixe le nombre de degres de liberte par composante.
double temps_
Definition Champ_base.h:123
Champ_base()
Constructeur par defaut d'un 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
provoque une erreur ! doit etre surchargee par les classes derivees
virtual double changer_temps(const double t)
Fixe le temps auquel se situe le champ.
virtual DoubleTab & valeur_aux(const DoubleTab &positions, DoubleTab &valeurs) const
Provoque une erreur ! Doit etre surchargee par les classes derivees.
virtual DoubleTab & valeur_aux_elems(const DoubleTab &positions, const IntVect &les_polys, DoubleTab &valeurs) const
provoque une erreur ! doit etre surchargee par les classes derivees
virtual DoubleVect & valeur_aux_compo(const DoubleTab &positions, DoubleVect &valeurs, int ncomp) const
Idem que valeur_aux(const DoubleTab &, DoubleTab &), mais calcule uniquement la composante compo du c...
class Domaine_VF
Definition Domaine_VF.h:44
const Nom & le_nom() const override
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
classe Domaine_dis_base Cette classe est la base de la hierarchie des domaines discretisees.
const Domaine & domaine() const
static int is_ecriture_special(int &special, int &a_faire)
indique si le format special a ete demande en lecture active par sauvegarde xyz .
static int is_lecture_special()
indique si le format special a ete demande en lecture active par reprise xyz .
static int ecriture_special(const Champ_base &ch, Sortie &fich)
simple appel a EcritureLectureSpecial::ecriture_special (const Domaine_VF& zvf,Sortie& fich,...
static void lecture_special(Champ_base &ch, Entree &fich)
simple appel a 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)
transforme v en un tableau parallele ayant la structure md.
: Cette classe est un OWN_PTR mais l'objet pointe est partage entre plusieurs
Definition MD_Vector.h:48
Une chaine de caractere (Nom) en majuscules.
Definition Motcle.h:26
class Nom Une chaine de caractere pour nommer les objets de TRUST
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
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
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
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")
classe 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)
classe YAML_data : collection of all needed information for data to save/restore in order to write th...
Definition YAML_data.h:26