16#include <EcritureLectureSpecial.h>
17#include <Champ_Generique_base.h>
18#include <Champ_Fonc_reprise.h>
19#include <LecFicDiffuseBin.h>
20#include <Entree_complete.h>
21#include <Probleme_base.h>
22#include <Ecrire_YAML.h>
23#include <TRUST_2_PDI.h>
24#include <Op_Moyenne.h>
27#include <Perf_counters.h>
29extern void convert_to(
const char *s,
double& ob);
64 Cerr<<
"Usage : Champ_Fonc_reprise [xyz|formatte|binaire|single_hdf|pdi] fichier.xyz nom_pb nom_inco [fonction n f1(val) f2(val) ... fn(val)] [temps|last_time]"<<finl;
65 Nom nom_fic,nom_pb,nom_champ;
66 Motcle format_rep(
"xyz");
69 if ((nom_fic==Motcle(
"xyz"))||(nom_fic==Motcle(
"binaire"))||(nom_fic==Motcle(
"single_hdf"))||(nom_fic==Motcle(
"pdi"))||(nom_fic==Motcle(
"formatte")))
78 Cerr <<
"Resuming with a single_hdf option is only available for a parallel calculation !" << finl;
91 fxyz.dimensionner(nb_compo);
93 for (
int i = 0; i<nb_compo; i++)
97 fxyz[i].setString(fonction);
98 fxyz[i].addVar(
"val");
99 fxyz[i].parseString();
102 if (time==
"LAST_TIME")
105 convert_to(time,un_temps);
112 convert_to(ch,un_temps);
118 int reprend_champ_moyen=0;
119 int reprend_modele_k_eps=0;
120 int k_eps_realisable = 0;
124 if (((Motcle)nom_champ).debute_par(
"MOYENNE_"))
126 nom_champ_inc=((Motcle)nom_champ).suffix(
"MOYENNE_");
127 nom_champ+=
"_natif_";
129 reprend_champ_moyen=1;
132 if (((Motcle)nom_champ).debute_par(
"K_EPS"))
134 reprend_modele_k_eps=1;
136 if (Motcle(nom_champ).finit_par(
"_REALISABLE"))
138 k_eps_realisable = 1;
139 nom_champ_inc=((Motcle)nom_champ).prefix(
"_REALISABLE");
142 if (nom_champ_inc==
"??")
143 nom_champ_inc=nom_champ;
145 ref_ch = pb.
get_champ(Motcle(nom_champ_inc));
146 if (sub_type(Champ_Inc_base,ref_ch.valeur()))
147 Cerr << nom_champ_inc <<
" is an unknown of problem " << nom_pb << finl;
150 Cerr << nom_champ_inc <<
" is not an unknown of problem " << nom_pb << finl;
156 const Champ_Inc_base& ch_inc=ref_cast(Champ_Inc_base,ref_ch.valeur());
158 vrai_champ_->associer_domaine_dis_base(pb.
domaine_dis());
160 vrai_champ_->nommer(ch_inc.
le_nom());
161 vrai_champ_->fixer_nb_comp(ch_inc.
nb_comp());
163 vrai_champ_->valeurs() = ch_inc.
valeurs();
164 vrai_champ_->set_via_ch_fonc_reprise();
168 Nom nom_champ_pdi = Motcle(pb.
le_nom()) +
"_" + Motcle(nom_champ);
170 statistics().
begin_count(STD_COUNTERS::restart,statistics().get_last_opened_counter_level()+1);
174 OWN_PTR(Entree_Fichier_base) fic_rep;
175 Entree_Brute input_data;
176 int format_sauvegarde = 0;
177 if(format_rep ==
"single_hdf")
180 Cerr <<
"WARNING::you are using a deprecated backup file format. Please switch to PDI." << finl;
182 if (!test.ouvrir(nom_fic))
184 Cerr <<
"Error! " << nom_fic <<
" file not found ! " << finl;
187 FichierHDFPar fic_hdf;
188 fic_hdf.
open(nom_fic,
true);
193 un_temps = get_last_time(input_data);
195 Cerr <<
"In the " << nom_fic <<
" file, we find the last time: " << un_temps <<
" and read the fields." << finl;
199 input_data >> ident_lu;
201 if (ident_lu==
"format_sauvegarde:")
202 input_data >> format_sauvegarde;
205 Cerr<<
"This .sauv file is too old and the format is not supported anymore."<<finl;
210 else if (format_rep ==
"pdi")
212 init_pdi(pb, nom_fic, nom_champ_pdi, last_time, un_temps, reprend_champ_moyen);
216 if (format_rep ==
"xyz")
225 if (format_rep ==
"binaire")
226 fic_rep.typer(
"LecFicDistribueBin");
228 fic_rep.typer(
"LecFicDistribue");
229 Cerr <<
"Opening file " << nom_fic <<
" (LecFicDistribueBin)" << finl;
232 fic_rep->ouvrir(nom_fic);
236 Cerr<<
"Error while opening the file of resumption : " <<nom_fic<<finl;
242 Cerr <<
"Error in Champ_Fonc_reprise::reprendre" << finl;
243 Cerr <<
"The resumption file does not exist" << finl;
244 Cerr <<
"or could not be opened correctly." << finl;
250 un_temps = get_last_time(fic_rep.valeur());
252 fic_rep->ouvrir(nom_fic);
253 Cerr <<
"In the " << nom_fic <<
" file, we find the last time: " << un_temps <<
" and read the fields." << finl;
257 fic_rep.valeur() >> ident_lu;
259 if (ident_lu==
"format_sauvegarde:")
260 fic_rep.valeur() >> format_sauvegarde;
264 if (format_rep==
"xyz")
267 fic_rep->ouvrir(nom_fic);
271 Cerr<<
"This .sauv file is too old and the format is not supported anymore."<<finl;
278 Nom nom_temps=Nom(un_temps,time_format_from(format_sauvegarde));
279 Nom type=ref_ch->que_suis_je();
281 Nom nom_ident_champ_stat;
282 Nom nom_ident_champ_keps;
283 if (reprend_champ_moyen)
285 nom_ident=
"Operateurs_Statistique_tps";
287 nom_ident+=nom_temps;
289 nom_ident_champ_stat=nom_champ;
290 nom_ident_champ_stat+=
"Champ_Fonc";
292 nom_ident_champ_stat+=type;
294 nom_ident_champ_stat+=nom_temps;
296 else if (reprend_modele_k_eps)
298 nom_ident=
"Modele_turbulence_hyd_K_Epsilon";
300 nom_ident+=
"_Realisable";
302 nom_ident+=nom_temps;
303 nom_ident_champ_keps=nom_champ_inc;
304 nom_ident_champ_keps+=type;
306 nom_ident_champ_keps+=nom_temps;
310 nom_ident=nom_champ_inc;
313 nom_ident+=nom_temps;
317 if (fxyz.size()!=ch_inc.
nb_comp())
319 Cerr<<
"The number of components read " <<fxyz.size()<<
" for the resume function"<<finl;
320 Cerr<<
"does not corresponds to the number of components "<<ch_inc.
nb_comp()<<
" of field target"<<finl;
324 if(format_rep ==
"single_hdf")
325 read_field_from_file(s, input_data, pb, nom_ident, nom_ident_champ_stat, reprend_champ_moyen, nom_ident_champ_keps, reprend_modele_k_eps);
326 else if(format_rep ==
"pdi")
329 read_field_from_file(s, bidon, pb, nom_champ_pdi,
"", reprend_champ_moyen,
"", reprend_modele_k_eps, 1 );
332 read_field_from_file(s, fic_rep.valeur(), pb, nom_ident, nom_ident_champ_stat, reprend_champ_moyen, nom_ident_champ_keps, reprend_modele_k_eps);
335 Cerr <<
"End of resuming the file " << nom_fic <<
" after " << statistics().
get_time_since_last_open(STD_COUNTERS::restart) <<
" s" << finl;
336 statistics().
end_count(STD_COUNTERS::restart);
343 DoubleTab& tab_valeurs=le_champ().valeurs();
346 int nb_compo=fxyz.size();
347 if (tab_valeurs.
nb_dim()==1)
351 Cerr <<
"Error in the function read because the field " << le_champ().le_nom() <<
" has a single dimension." << finl;
357 Cerr <<
"Error in the number of components of the function read:" << nb_compo << finl;
358 Cerr <<
"The number of components of field " << le_champ().le_nom() <<
" is:" << tab_valeurs.
dimension_tot(1) << finl;
361 for (
int i=0; i<sz; i++)
363 for (
int j=0; j<nb_compo; j++)
365 fxyz[j].setVar(
"val",tab_valeurs(i,j));
367 tab_valeurs(i,j)=fxyz[j].eval();
372 if(format_rep ==
"pdi")
378void Champ_Fonc_reprise::init_pdi(
const Probleme_base& pb,
const Nom& nom_fic,
const Nom& ch_ident,
int last_time,
double un_temps,
int reprend_champ_moyen)
382 Ecrire_YAML yaml_file;
384 int nb_dim = le_champ().valeurs().nb_dim();
385 const Nom& pbname = pb.
le_nom();
386 yaml_file.
add_field(pbname, ch_ident, nb_dim);
387 if(reprend_champ_moyen)
389 yaml_file.
add_scalar(pbname, pbname +
"_stat_nb_champs",
"int",
false );
390 yaml_file.
add_scalar(pbname, pbname +
"_stat_tdeb",
"double",
false );
391 yaml_file.
add_scalar(pbname, pbname +
"_stat_tend",
"double",
false );
393 std::string yaml_fname =
"restart_" + pbname.
getString() +
"_" + le_champ().le_nom().getString() +
".yml";
397 TRUST_2_PDI pdi_interface;
398 int last_iteration = -1;
399 double tinit = last_time ? -1. : un_temps;
400 pdi_interface.
prepareRestart(restartComm_, last_iteration, tinit, last_time);
405 const Nom& nom_ident_champ_stat,
int reprend_champ_moyen,
const Nom& nom_ident_champ_keps,
int reprend_modele_k_eps,
411 Nom field_tag_syno=nom_ident;
413 auto create_syno= [nom_ident](std::string pattern, std::string replace)
416 std::size_t pos = s.find(pattern);
417 while (pos != std::string::npos)
419 s.replace(pos, pattern.length(), replace);
420 pos = s.find(pattern, pos + replace.length());
427 field_tag_syno=create_syno(
"PolyMAC_CDO",
"PolyMAC");
429 field_tag_syno=create_syno(
"PolyMAC_MPFA",
"PolyMAC_P0");
431 field_tag_syno=create_syno(
"PolyMAC_HFV",
"PolyMAC_P0P1NC");
433 avancer_fichier_with_syno(file,nom_ident,field_tag_syno);
437 avancer_fichier(file,nom_ident);
440 le_champ().set_PDI_dname(nom_ident);
442 if (reprend_champ_moyen)
444 double tdeb = -1,tfin=-1;
448 TRUST_2_PDI pdi_interface;
450 pdi_interface.
read(pbname +
"_stat_nb_champs", &n);
451 pdi_interface.
read(pbname +
"_stat_tdeb", &tdeb);
452 pdi_interface.
read(pbname +
"_stat_tend", &tfin);
459 avancer_fichier(file,nom_ident_champ_stat);
462 Op_Moyenne champ_moyen;
465 OWN_PTR(Champ_Generique_base) champ;
467 ajout +=
" refChamp { Pb_champ ";
468 Nom pb_name = pb.
le_nom();
471 ajout += le_champ().
le_nom();
473 Entree_complete s_complete(ajout,jdd);
484 else if (reprend_modele_k_eps)
487 avancer_fichier(file, nom_ident_champ_keps);
488 le_champ().reprendre(file);
491 le_champ().reprendre(file);
classe Champ_Fonc_base Classe de base des champs qui sont fonction d'une grandeur calculee
void associer_domaine_dis_base(const Domaine_dis_base &) override
OBS_PTR(Domaine_VF) le_dom_VF
void mettre_a_jour(double temps) override
Mise a jour en temps du champ.
classe Champ_Fonc_reprise Cette classe permet de relire un champ sauvegarde dans un fichier xyz
void mettre_a_jour(double) override
Mise a jour en temps du champ.
DoubleTab & valeurs() override
Renvoie le tableau des valeurs du champ au temps courant.
Champ_base()
Constructeur par defaut d'un Champ_base.
virtual bool is_poly_family() const
virtual bool is_PolyMAC_MPFA() const
virtual bool is_PolyMAC_CDO() const
virtual bool is_PolyMAC_HFV() const
const Nom & le_nom() const override
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
void add_field(Nom pb, Nom nom, int nb_dim)
Adds a field (name+dimension) to the block of the problem pb_name in the YAML file.
void write_champ_fonc_restart_file(const std::string &filename)
Generate the YAML file that will be read with champ_fonc_reprise.
void add_pb_base(const Probleme_base &pb_base, const Nom &full_file_name)
void add_scalar(Nom pb, Nom nom, Nom type, bool is_local)
Adds a scalar (name+type) to the block of the problem pb_name in the YAML file.
Class defining operators and methods for all reading operation in an input flow (file,...
virtual void read_dataset(Nom dataset_basename, int proc_rank, Entree_Brute &entree)
virtual void open(Nom filename, bool readOnly)
const Nom & le_nom() const override
Renvoie le nom du champ.
virtual int nb_comp() const
static Objet_U & objet(const Nom &)
Voir Interprete_bloc::objet_global() BM: la classe Interprete n'est pas le meilleur endroit pour cett...
class Nom Une chaine de caractere pour nommer les objets de TRUST
Nom & suffix(const char *const)
Extraction de suffixe : Nom x("azerty");.
const std::string & getString() const
const Nom & le_nom() const override
Renvoie *this;.
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
void fixer_tstat_deb(double, double) override
void completer(const Probleme_base &, const Nom &) override
int reprendre(Entree &is) override
Reprise d'un Objet_U sur un flot d'entree Methode a surcharger.
void set_pdi_name(const Nom &nom)
void associer(const Domaine_dis_base &une_zdis, const Champ_Generique_base &le_champ, double t1, double t2) override
DoubleTab calculer_valeurs() const override
void begin_count(const STD_COUNTERS &std_cnt, int counter_lvl=-100000)
double get_time_since_last_open(const STD_COUNTERS &name)
Give as a double the time (in second) elapsed in the operation tracked by the standard counter call n...
void end_count(const std::string &custom_count_name, int count_increment=1, long int quantity_increment=0)
End the count of a counter and update the counter values.
const Nom & le_nom() const override
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
classe Probleme_base C'est un Probleme_U qui n'est pas un couplage.
const Domaine & domaine() const
Renvoie le domaine associe au probleme.
const Champ_base & get_champ(const Motcle &nom) const override
const Discretisation_base & discretisation() const
Renvoie la discretisation associee au probleme.
const Domaine_dis_base & domaine_dis() const
Renvoie le domaine discretise associe au probleme.
static int nproc()
renvoie le nombre de processeurs dans le groupe courant Voir Comm_Group::nproc() et PE_Groups::curren...
static int me()
renvoie mon rang dans le groupe de communication courant.
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Classe de base des flux de sortie.
_SIZE_ dimension_tot(int) const override
void read(const std::string &name, void *data)
static void set_PDI_restart(int r)
void prepareRestart(OWN_PTR(Comm_Group)&nodeGroup, int &last_iteration, double &tinit, int resume_last_time)
Generic method to prepare the restart of a computation.
static void init(std::string IO_config)