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;
794template<
typename TYP>
795int Format_Post_Lata::ecrire_item_integral_T(
const Nom& id_item,
const Nom& id_du_domaine,
const Nom& id_domaine,
const Nom& localisation,
804 extension_champ +=
".";
806 extension_champ += id_item;
807 extension_champ +=
".";
808 extension_champ += localisation;
809 extension_champ +=
".";
810 extension_champ += id_du_domaine;
811 extension_champ +=
".";
812 char str_temps[100] =
"0.0";
815 extension_champ +=
Nom(str_temps);
819 trustIdType size_tot;
821 const TRUSTTab<TYP, int> valeurs =
static_cast<const TRUSTTab<TYP, int>&
>(val);
832 if (fichier_champ.is_master())
833 offset_elem_ = fichier_champ.get_SFichier().get_ofstream().tellp();
835 filename_champ = fichier_champ.get_filename();
838 trustIdType decal_partiel = 0;
850 size_tot = ::write_T_tab<TYP, _LATA_INT_TYPE_>(fichier_champ, decal, decal_partiel, valeurs, nb_compo,
options_para_);
859 sfichier <<
"Champ " << id_item <<
" ";
861 sfichier <<
" geometrie=" << id_du_domaine;
863 if (localisation !=
"") sfichier <<
" localisation=" << localisation;
865 sfichier <<
" size=" << size_tot;
866 sfichier <<
" composantes=" << nb_compo;
867 if (reference !=
"") sfichier <<
" reference=" << reference;
871 const int sz = (int)
sizeof(_LATA_INT_TYPE_);
875 sfichier <<
" format=int32";
878 sfichier <<
" format=int64";
881 Cerr <<
"Error in Format_Post_Lata::ecrire_champ_lata\n" <<
" Integer type not supported: size=" << sz << finl;
908 const Nom& reference,
const IntVect& val,
const int reference_size)
910 return ecrire_item_integral_T(id_item, id_du_domaine, id_domaine, localisation, reference, val, reference_size);
914 const Nom& reference,
const TIDVect& val,
const int reference_size)
916 return ecrire_item_integral_T(id_item, id_du_domaine, id_domaine, localisation, reference, val, reference_size);
921 if (est_le_premier_post)
926 const unsigned int one = 1;
927 const int big_endian = (*((
unsigned char*) &one) == 0) ? 1 : 0;
935 sfichier <<
"LATA_V2.1 TRUST version " << TRUST_VERSION << finl;
937 sfichier <<
"Trio_U verbosity=0" << finl;
939 sfichier <<
"Format ";
943 sfichier <<
"ASCII,";
946 sfichier <<
"BINAIRE,";
948 sfichier <<
"BIG_ENDIAN,";
950 sfichier <<
"LITTLE_ENDIAN,";
953 Cerr <<
"Error in Format_Post_Lata::ecrire_entete\n" <<
" format not supported" << finl;
956 switch(
sizeof(_LATA_INT_TYPE_))
959 sfichier <<
"INT32,";
962 sfichier <<
"INT64,";
965 Cerr <<
"Error in Format_Post_Lata::ecrire_entete\n" <<
" sizeof(int) not supported" << finl;
968 sfichier <<
"F_INDEXING,C_ORDERING,F_MARKERS_SINGLE,REAL32" << finl;
979 assert(stat !=
RESET);
983 temps_format = temps;
996 if (est_le_dernier_post)
1000 if (fichier.
is_master()) sfichier <<
"FIN" << finl;
File for reading. This class is to the C++ ifstream class what the Entree class is to the.
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,...
: Specialization of Fichier_Lata for the master file: always in ASCII.
virtual int is_master() const
If the file is of shared type, returns 1 if me() equals the group master, 0 otherwise.
virtual SFichier & get_SFichier()
virtual const Nom & get_filename() const
Returns the file name with its path.
virtual void syncfile()
If the file is of shared type, calls the syncfile() method; otherwise does nothing.
: Post-processing class for Eulerian fields in LATA format.
void reset() override
Resets the object to the state obtained by the default constructor.
int ecrire_entete(const double temps_courant, const int reprise, const int est_le_premier_post) override
Opens the master file in ERASE mode and writes the lata file header (on the master processor only).
static const char * remove_path(const char *filename)
Returns the file name without its path: strips all characters before the last /.
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
Writing an integer array to the post-processing file.
virtual int initialize_lata(const Nom &file_basename, const Format format=ASCII, const Options_Para options_para=SINGLE_FILE)
Initializes the class, opens the file and writes the header.
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 is a lata data file (not the master file). The array tab is written as-is (in binary or ASCII...
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
See Format_Post_base::ecrire_domaine. Writing a domain within a time step is accepted,...
Format_Post_Lata()
Default constructor: format_ ASCII and 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
Starts writing a new time step. For the LATA format specifically:
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)
Writing an integer array to the given file.
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
Initializes the class with default parameters (ASCII format, 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()
Returns the conventional extension for lata files: ".lata".
void resetTime(double t, const std::string dirname) override
int lire_motcle_non_standard(const Motcle &, Entree &) override
Reads non-simple-type parameters of an Objet_U from an input stream.
Base class for post-processing output formats for fields (lata, med, cgns, lml, single_lata).
OBS_PTR(Domaine_dis_base) domaine_dis_
Reference to the discretized domain - used for face fields.
A character string (Nom) in uppercase.
class Nom: a character string for naming TRUST objects.
virtual int debute_par(const char *const n) const
An array of character strings (VECT(Nom)).
int contient_(const char *const ch) const
const Nom & que_suis_je() const
Returns the string identifying the class.
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
static const Nom & nom_du_cas()
Returns a constant reference to the case name. This method is static.
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Helper class to factorize the readOn method of Objet_U classes.
static trustIdType mppartial_sum(trustIdType i)
Computes the partial sum of x over processors 0 to me()-1 (returns 0 on processor 0).
static double mp_max(double)
static bool is_parallel()
static double mp_sum(double)
Computes the sum of x over all processors in the current group.
static void barrier()
Synchronizes all processors in the current group (waits until all processors have reached the barrier...
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
static int je_suis_maitre()
Returns 1 if on the master processor of the current group (i.e. me() == 0), 0 otherwise.
SFichier is to the C++ ofstream class what Sortie is to the C++ ostream class.
void precision(int pre) override
void setf(IOS_FORMAT code) override
ofstream & get_ofstream()
Base class for output streams.
virtual int put(const unsigned *ob, std::streamsize n, std::streamsize nb_colonnes=1)
N-dimensional array for N <= 4.
_SIZE_ dimension_tot(int) const override
_SIZE_ dimension(int d) const