16#include <EcrFicPartageMPIIO.h>
17#include <Format_Post_Lata.h>
18#include <EcrFicPartageBin.h>
19#include <communications.h>
20#include <Fichier_Lata.h>
28#define _LATA_INT_TYPE_ trustIdType
82 Cerr <<
"Format_Post_Lata::set_param: Not implemented." << finl;
88 Cerr <<
"Format_Post_Lata::lire_motcle_non_standard: Not implemented." << finl;
98 static const char * ext =
".lata";
107 int i = (int)strlen(filename);
108 while (i > 0 && filename[i-1] !=
'/')
137template<
typename TYP,
typename LATA_TYP>
138void fill_tmp_array(
const TRUSTTab<TYP,int>& tab,
int upper,
int offset,
bool decal_fort, trustIdType decalage_partiel, LATA_TYP *tmp);
140template<
typename TYP>
141typename std::enable_if_t<std::is_same<TYP, int>::value || std::is_same<TYP, trustIdType>::value,
void>
142fill_tmp_array(
const TRUSTTab<TYP,int>& tab,
int upper,
int offset,
bool decal_fort, trustIdType decalage_partiel, _LATA_INT_TYPE_ *tmp)
144 trustIdType decal_fort_val = decal_fort ? 1 : 0;
145 const TYP *data = tab.
addr();
146 for (
int i = 0; i < upper; i++)
149 _LATA_INT_TYPE_ x = data[i+offset];
151 x += decalage_partiel;
159void fill_tmp_array<double, float>(
const TRUSTTab<double,int>& tab,
int upper,
int offset,
bool , trustIdType ,
float *tmp)
161 const double *data = tab.
addr();
162 for (
int i = 0; i < upper; i++)
163 tmp[i] = (
float) data[i+offset];
168template<
typename TYP,
typename LATA_TYP>
173 const int nb_dim = tab.
nb_dim();
175 for (
int i = 1; i < nb_dim; i++)
178 trustIdType nb_lignes_tot = 0;
180 const int tab_size = line_size * nb_lignes;
181 trustIdType nb_octets = tab_size * (trustIdType)
sizeof(LATA_TYP);
189 nb_octets = nb_colonnes * nb_lignes_tot * (trustIdType)
sizeof(LATA_TYP);
190 assert(nb_lignes == 0 || line_size == nb_colonnes);
193 nb_lignes_tot = nb_lignes;
194 nb_colonnes = line_size;
197 Cerr <<
"Format_Post_Lata_write_tab: error nb_lignes_tot" << finl;
205 sfichier << nb_octets << finl;
211 LATA_TYP *tmp =
new LATA_TYP[tab_size];
212 fill_tmp_array(tab, tab_size, 0, decal_fort, decalage_partiel, tmp);
213 sfichier.
put(tmp, tab_size, line_size);
217 sfichier << nb_octets << finl;
224 int bufsize = (N / line_size + 1) * line_size;
225 LATA_TYP *tmp =
new LATA_TYP[bufsize];
226 for (
int i = 0; i < tab_size; i += bufsize)
229 if (j_max > tab_size - i)
230 j_max = tab_size - i;
233 fill_tmp_array(tab, j_max, i, decal_fort, decalage_partiel, tmp);
236 sfichier.
put(tmp, j_max, line_size);
242 sfichier << nb_octets << finl;
245 return nb_lignes_tot;
259 return ::write_T_tab<double, float>(fichier, 0, 0, tab, nb_colonnes,
option);
273 return ::write_T_tab<int, _LATA_INT_TYPE_>(fichier, decal_fort, decalage_partiel, tab, nb_colonnes,
option);
294 if (
Motcle(option_para) ==
"MPI-IO")
296 else if (
Motcle(option_para) ==
"SIMPLE")
298 else if (
Motcle(option_para) ==
"MULTIPLE")
302 Cerr <<
"The option " << option_para <<
" for lata format for the parallel is not correct." << finl;
331 bool master_file_exists =
false;
335 if (stat(post_file, &f) == 0)
343 master_file_exists =
true;
347 while (!tmp.
eof() && cle !=
"TEMPS")
355 master_file_exists =
true;
368 before_restart = file_basename +
".before_restart" +
extension_lata();
369 rename(post_file, before_restart);
370 Cerr <<
"File " << post_file <<
" is moved to " << before_restart <<
" with times<=tinit=" << tinit << finl;
380 if (master_file_exists && for_restart)
394 LataNew.
setf(ios::scientific);
400 while (!LataOld.
eof())
411 LataNew.
get_ofstream() << mot <<
" " << temps << line << std::endl;
426 Cerr <<
"File " << post_file <<
" is rebuilt but truncated to times<tinit=" << tinit << finl;
437 if (stat(post_file, &f) == 0)
440 SFichier LataRep(post_file, ios::app);
441 LataRep.
setf(ios::scientific);
455 LataRep.
get_ofstream() << mot <<
" " << temps << line << std::endl;
467 Cerr <<
"File " << post_file <<
" is built with times from tinit=" <<
tinit_ << finl;
475void Format_Post_Lata::ecrire_offset(
SFichier& sfichier,
long int offset_single_lata)
478 sfichier <<
" file_offset=" << offset_single_lata;
485 sfichier <<
" file_offset=6";
491static Noms liste_single_lata_ecrit;
500 Motcle type_elem(type_element);
503 if (type_element ==
"PRISME") type_elem =
"PRISM6";
505 trustIdType nb_som_tot, nb_elem_tot;
513 extension_geom +=
".";
514 extension_geom += id_domaine;
515 extension_geom +=
".";
516 char str_temps[100] =
"0.0";
519 extension_geom +=
Nom(str_temps);
522 Nom nom_fichier_geom;
523 trustIdType decalage_sommets = 1, decalage_elements = 1;
526 const bool not_in_list = !liste_single_lata_ecrit.contient_(
lata_basename_),
544 DoubleTab sommets2(sommets);
546 for (
int s = 0; s < ns; s++)
548 double r = sommets(s, 0), theta = sommets(s, 1);
549 sommets2(s, 0) = r * cos(theta);
550 sommets2(s, 1) = r * sin(theta);
557 assert(nb_som_tot == 0 || nb_col == dim);
568 const int nbelem = elements.
dimension(0);
593 sfichier <<
"GEOM " << id_domaine;
594 sfichier <<
" type_elem=" << type_elem << finl;
597 sfichier <<
"CHAMP SOMMETS " <<
remove_path(nom_fichier_geom);
598 sfichier <<
" geometrie=" << id_domaine;
599 sfichier <<
" size=" << nb_som_tot;
600 sfichier <<
" composantes=" << dim;
605 sfichier <<
"CHAMP ELEMENTS " <<
remove_path(nom_fichier_geom);
607 sfichier <<
" geometrie=" << id_domaine;
608 sfichier <<
" size=" << nb_elem_tot <<
" composantes=" << elements.
dimension(1);
613 switch(
sizeof(_LATA_INT_TYPE_))
616 sfichier <<
" format=INT32" << finl;
619 sfichier <<
" format=INT64" << finl;
622 Cerr <<
"Error in Format_Post_Lata::ecrire_entete\n" <<
" sizeof(int) not supported" << finl;
635 data(0, 0) = decalage_sommets;
644 data(0, 0) = decalage_elements;
666 Cerr <<
"Error in Format_Post_Lata::ecrire_domaine\n" <<
" status = RESET. Uninitialized object" << finl;
674 const LIST(
OBS_PTR(Domaine)) bords= domaine.domaines_frontieres();
675 for (
int i=0; i<bords.size(); i++)
697 const Nom& localisation,
const Nom& nature,
const DoubleTab& valeurs)
699 Motcle id_du_champ_modifie(id_du_champ), iddomaine(id_du_domaine);
702 if ((
Motcle) localisation ==
"SOM")
704 id_du_champ_modifie.prefix(id_du_domaine);
705 id_du_champ_modifie.prefix(iddomaine);
706 id_du_champ_modifie.prefix(
"_SOM_");
708 else if ((
Motcle) localisation ==
"ELEM")
710 id_du_champ_modifie.prefix(id_du_domaine);
711 id_du_champ_modifie.prefix(iddomaine);
712 id_du_champ_modifie.prefix(
"_ELEM_");
714 else if ((
Motcle) localisation ==
"FACES")
716 id_du_champ_modifie.prefix(id_du_domaine);
717 id_du_champ_modifie.prefix(iddomaine);
718 id_du_champ_modifie.prefix(
"_FACES_");
720 Nom& id_champ = id_du_champ_modifie;
728 extension_champ +=
".";
729 extension_champ += id_champ;
730 extension_champ +=
".";
731 extension_champ += localisation;
732 extension_champ +=
".";
733 extension_champ += id_du_domaine;
734 extension_champ +=
".";
735 char str_temps[100] =
"0.0";
737 snprintf(str_temps, 100,
"%.10f", temps);
738 extension_champ += str_temps;
742 trustIdType size_tot;
745 const bool not_in_list = !liste_single_lata_ecrit.contient_(
lata_basename_),
768 sfichier <<
"Champ " << id_champ <<
" ";
770 sfichier <<
" geometrie=" << id_du_domaine;
771 sfichier <<
" localisation=" << localisation;
772 sfichier <<
" size=" << size_tot;
773 sfichier <<
" nature=" << nature;
774 sfichier <<
" noms_compo=" << noms_compo[0];
775 for (
int k = 1; k < noms_compo.size(); k++)
776 sfichier <<
"," << noms_compo[k];
778 sfichier <<
" composantes=" << nb_compo;
795template<
typename TYP>
796int Format_Post_Lata::ecrire_item_integral_T(
const Nom& id_item,
const Nom& id_du_domaine,
const Nom& id_domaine,
const Nom& localisation,
805 extension_champ +=
".";
807 extension_champ += id_item;
808 extension_champ +=
".";
809 extension_champ += localisation;
810 extension_champ +=
".";
811 extension_champ += id_du_domaine;
812 extension_champ +=
".";
813 char str_temps[100] =
"0.0";
816 extension_champ +=
Nom(str_temps);
820 trustIdType size_tot;
822 const TRUSTTab<TYP, int> valeurs =
static_cast<const TRUSTTab<TYP, int>&
>(val);
833 if (fichier_champ.is_master())
834 offset_elem_ = fichier_champ.get_SFichier().get_ofstream().tellp();
836 filename_champ = fichier_champ.get_filename();
839 trustIdType decal_partiel = 0;
851 size_tot = ::write_T_tab<TYP, _LATA_INT_TYPE_>(fichier_champ, decal, decal_partiel, valeurs, nb_compo,
options_para_);
860 sfichier <<
"Champ " << id_item <<
" ";
862 sfichier <<
" geometrie=" << id_du_domaine;
864 if (localisation !=
"") sfichier <<
" localisation=" << localisation;
866 sfichier <<
" size=" << size_tot;
867 sfichier <<
" composantes=" << nb_compo;
868 if (reference !=
"") sfichier <<
" reference=" << reference;
872 const int sz = (int)
sizeof(_LATA_INT_TYPE_);
876 sfichier <<
" format=int32";
879 sfichier <<
" format=int64";
882 Cerr <<
"Error in Format_Post_Lata::ecrire_champ_lata\n" <<
" Integer type not supported: size=" << sz << finl;
909 const Nom& reference,
const IntVect& val,
const int reference_size)
911 return ecrire_item_integral_T(id_item, id_du_domaine, id_domaine, localisation, reference, val, reference_size);
915 const Nom& reference,
const TIDVect& val,
const int reference_size)
917 return ecrire_item_integral_T(id_item, id_du_domaine, id_domaine, localisation, reference, val, reference_size);
922 if (est_le_premier_post)
927 const unsigned int one = 1;
928 const int big_endian = (*((
unsigned char*) &one) == 0) ? 1 : 0;
936 sfichier <<
"LATA_V2.1 TRUST version " << TRUST_VERSION << finl;
938 sfichier <<
"Trio_U verbosity=0" << finl;
940 sfichier <<
"Format ";
944 sfichier <<
"ASCII,";
947 sfichier <<
"BINAIRE,";
949 sfichier <<
"BIG_ENDIAN,";
951 sfichier <<
"LITTLE_ENDIAN,";
954 Cerr <<
"Error in Format_Post_Lata::ecrire_entete\n" <<
" format not supported" << finl;
957 switch(
sizeof(_LATA_INT_TYPE_))
960 sfichier <<
"INT32,";
963 sfichier <<
"INT64,";
966 Cerr <<
"Error in Format_Post_Lata::ecrire_entete\n" <<
" sizeof(int) not supported" << finl;
969 sfichier <<
"F_INDEXING,C_ORDERING,F_MARKERS_SINGLE,REAL32" << finl;
980 assert(stat !=
RESET);
984 temps_format = temps;
997 if (est_le_dernier_post)
1001 if (fichier.
is_master()) sfichier <<
"FIN" << finl;
Fichier en lecture Cette classe est a la classe C++ ifstream ce que la classe Entree est a la.
Class to use MPI-IO to write in a single file.
ifstream & get_ifstream()
Class defining operators and methods for all reading operation in an input flow (file,...
: Specialisation du Fichier_Lata pour le fichier maitre: toujours en ASCII.
virtual int is_master() const
Si le fichier est de type partage, renvoie 1 si me() est egal au master du groupe et 0 sinon,...
virtual SFichier & get_SFichier()
virtual const Nom & get_filename() const
Renvoie le nom du fichier avec le path.
virtual void syncfile()
Si le fichier est de type partage, appelle la methode syncfile(), sinon ne fait rien.
: Classe de postraitement des champs euleriens au format lata
void reset() override
Remet l'objet dans l'etat obtenu par le constructeur par defaut.
int ecrire_entete(const double temps_courant, const int reprise, const int est_le_premier_post) override
Ouvre le fichier maitre en mode ERASE et ecrit l'entete du fichier lata (sur le processeur maitre seu...
static const char * remove_path(const char *filename)
Renvoie le nom d'un fichier sans le path : on enleve les caracteres avant le dernier /.
bool un_seul_fichier_lata_
int ecrire_item_int(const Nom &id_item, const Nom &id_du_domaine, const Nom &id_domaine, const Nom &localisation, const Nom &reference, const IntVect &data, const int reference_size) override
Ecriture d'un tableau d'entiers dans le fichier de postraitement.
virtual int initialize_lata(const Nom &file_basename, const Format format=ASCII, const Options_Para options_para=SINGLE_FILE)
Initialisation de la classe, ouverture du fichier et ecriture de l'entete.
int modify_file_basename(const Nom file_basename, bool for_restart, const double tinit) override
Modifying name of the post file, plus some clever management of previously saved data in case of rest...
Options_Para options_para_
int preparer_post(const Nom &id_du_domaine, const int est_le_premier_post, const int reprise, const double t_init) override
static trustIdType write_doubletab(Fichier_Lata &fichier, const DoubleTab &tab, int &nb_colonnes, const Options_Para &option)
fichier est un fichier lata de donnees (pas le fichier maitre) on y ecrit le tableau tab tel quel (en...
int ecrire_item_tid(const Nom &id_item, const Nom &id_du_domaine, const Nom &id_domaine, const Nom &localisation, const Nom &reference, const TIDVect &data, const int reference_size)
virtual int finir_sans_reprise(const Nom file_basename)
static int ecrire_entete_lata(const Nom &base_name, const Options_Para &option, const Format &format, const int est_le_premier_post)
virtual int reconstruct(const Nom file_basename, const Nom, const double tinit)
int ecrire_domaine(const Domaine &domaine, const int est_le_premier_post) override
voir Format_Post_base::ecrire_domaine On accepte l'ecriture d'un domaine dans un pas de temps,...
Format_Post_Lata()
Constructeur par defaut: format_ ASCII et options_para_ = SINGLE_FILE.
int completer_post(const Domaine &dom, const int axi, const Nature_du_champ &nature, const int nb_compo, const Noms &noms_compo, const Motcle &loc_post, const Nom &le_nom_champ_post) override
bool restart_already_moved_
void set_param(Param ¶m) const override
int ecrire_temps(const double temps) override
commence l'ecriture d'un nouveau pas de temps En l'occurence pour le format LATA:
int ecrire_champ(const Domaine &domaine, const Noms &unite_, const Noms &noms_compo, int ncomp, double temps_, const Nom &id_du_champ, const Nom &id_du_domaine, const Nom &localisation, const Nom &nature, const DoubleTab &data) override
voir Format_Post_base::ecrire_champ
static trustIdType write_inttab(Fichier_Lata &fichier, bool decal_fort, trustIdType decalage_partiel, const IntTab &tab, int &nb_colonnes, const Options_Para &option)
Ecriture d'un tableau d'entiers dans le fichier fourni.
void ecrire_domaine_low_level(const Nom &id_dom, const DoubleTab &sommets, const IntTab &elements, const Motcle &type_elem)
Low level routine to write a mesh into a LATA file.
int initialize_by_default(const Nom &file_basename) override
Initialisation de la classe avec des parametres par defaut (format ASCII, SINGLE_FILE).
int finir(const int est_le_dernier_post) override
int initialize(const Nom &file_basename, const int format, const Nom &option_para) override
static int ecrire_temps_lata(const double temps, double &temps_format, const Nom &base_name, Status &stat, const Options_Para &option)
static const char * extension_lata()
Renvoie l'extension conventionnelle des fichiers lata : ".lata".
void resetTime(double t, const std::string dirname) override
int lire_motcle_non_standard(const Motcle &, Entree &) override
Lecture des parametres de type non simple d'un objet_U a partir d'un flot d'entree.
Classe de base des formats de postraitements pour les champs (lata, med, cgns, lml,...
OBS_PTR(Domaine_dis_base) domaine_dis_
Reference to the discretized domain - used for face fields.
Une chaine de caractere (Nom) en majuscules.
class Nom Une chaine de caractere pour nommer les objets de TRUST
virtual int debute_par(const char *const n) const
Un tableau de chaine de caracteres (VECT(Nom)).
int contient_(const char *const ch) const
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.
static const Nom & nom_du_cas()
Renvoie une reference constante vers le nom du cas.
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Helper class to factorize the readOn method of Objet_U classes.
static trustIdType mppartial_sum(trustIdType i)
Calul de la somme partielle de i sur les processeurs 0 a me()-1 (renvoie 0 sur le processeur 0).
static double mp_max(double)
static bool is_parallel()
static double mp_sum(double)
Calcule la somme de x sur tous les processeurs du groupe courant.
static void barrier()
Synchronise tous les processeurs du groupe courant (attend que tous les processeurs soient arrives a ...
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
static int je_suis_maitre()
renvoie 1 si on est sur le processeur maitre du groupe courant (c'est a dire me() == 0),...
Cette classe est a la classe C++ ofstream ce que la classe Sortie est a la classe C++ ostream Elle re...
void precision(int pre) override
void setf(IOS_FORMAT code) override
ofstream & get_ofstream()
Classe de base des flux de sortie.
virtual int put(const unsigned *ob, std::streamsize n, std::streamsize nb_colonnes=1)
: Tableau a n entrees pour n<= 4.
_SIZE_ dimension_tot(int) const override
_SIZE_ dimension(int d) const