16#include <EcritureLectureSpecial.h>
18#include <Champ_Fonc_base.h>
19#include <Domaine_VF.h>
21#include <MD_Vector_tools.h>
22#include <Octree_Double.h>
23#include <MD_Vector_composite.h>
24#include <MD_Vector_seq.h>
25#include <TRUSTTab_parts.h>
26#include <TRUST_2_PDI.h>
52 else if (md == zvf.
xa().get_md_vector())
58 Cerr <<
"Error in get_ref_coordinates_items\n"
59 <<
" descriptor not found in this domaine" << finl;
81 if (
option==
"EFichierBin" ||
option==
"LecFicDiffuseBin" ||
option==
"LecFicPartageMPIIO")
83 Cerr <<
"ERROR: EcritureLectureSpecial: - option '" <<
option <<
"' is obsolete! You may only specify 0 or 1." <<finl;
86 else if (
option==
"EcrFicPartageMPIIO" ||
option==
"EcrFicPartageBin" ||
option==
"EcrFicPartage")
88 Cerr <<
"ERROR: EcritureLectureSpecial: - option '" <<
option <<
"' is obsolete! You may only specify 0 or 1." <<finl;
97 Cerr <<
"ERROR: \"EcritureLectureSpecial " <<
option <<
"\" is not recognized." << finl;
100 Cerr <<
"EcritureLectureSpecial::Active set to " <<
Active << finl;
153 const DoubleTab& val = ch.
valeurs();
157int ecrit(
Sortie& fich,
const ArrOfBit& items_to_write,
const DoubleTab& pos,
const DoubleTab& val)
159 const int nb_dim = val.
nb_dim();
160 const int nb_comp = (nb_dim == 2) ? val.
dimension(1) : 1;
161 const int nb_val = items_to_write.
size_array();
167 int jmax = (dim + nb_comp) * nb_val;
168 ArrOfDouble tmp(jmax);
170 for (
int p = 0; p < nb_val; p++)
175 if (items_to_write[p])
177 for (
int k = 0; k < dim; k++)
178 tmp[j++] = pos(p, k);
182 for (
int k = 0; k < nb_comp; k++)
183 tmp[j++] = val(p, k);
186 fich.
put(tmp.addr(), j, dim + nb_comp );
191 int jmax = (dim + nb_comp) * 128;
192 ArrOfDouble tmp(jmax);
194 for (
int p = 0; p < nb_val; p++)
199 if (items_to_write[p])
201 for (
int k = 0; k < dim; k++)
202 tmp[j++] = pos(p, k);
206 for (
int k = 0; k < nb_comp; k++)
207 tmp[j++] = val(p, k);
210 fich.
put(tmp.addr(), j, dim + nb_comp );
219 fich.
put(tmp.addr(), j, dim + nb_comp );
221 return 8 * (dim + nb_comp) * nb_val;
229static int ecriture_special_part2(
const Domaine_VF& zvf,
Sortie& fich,
const DoubleTab& val)
236 ConstDoubleTab_parts parts(val);
237 int n = zvf.
que_suis_je() ==
"Domaine_PolyMAC_MPFA" ? 1 : parts.size();
238 for (
int i = 0; i < n; i++)
239 bytes += ecriture_special_part2(zvf, fich, parts[i]);
243 ArrOfBit items_to_write;
245 const DoubleTab& coords = get_ref_coordinates_items(zvf, md);
246 bytes += ecrit(fich, items_to_write, coords, val);
251 Cerr <<
"EcritureLectureSpecial::ecriture_special_part: Error, unknown Metadata vector type : "
266 Cerr <<
"EcritureLectureSpecial::ecriture_special: error, cannot save an array with no metadata" << finl;
270 if (nb_items_seq == 0)
273 const int nb_dim = val.
nb_dim();
274 const int nb_comp = (nb_dim == 2) ? val.
dimension(1) : 1;
276 const trustIdType n = nb_items_seq * (nb_comp + dim);
281 fich << (int)1 << finl;
283 fich << (int)1 << finl;
288 int bytes = ecriture_special_part2(zvf, fich, val);
293 fich << (int)0 << finl;
294 fich << (int)0 << finl;
295 fich << (int)0 << finl;
296 fich << (int)1 << finl;
297 fich << (int)0 << finl;
300 fich << (int)1 << finl;
301 fich << (int)0 << finl;
302 fich << (int)0 <<finl;
327static trustIdType lire_special(
Entree& fich,
const DoubleTab& coords, DoubleTab& val,
const double epsilon)
330 const int nb_dim = val.
nb_dim();
331 const int nb_comp = (nb_dim == 1) ? 1 : val.dimension(1);
336 ArrOfInt items_to_read;
338 Octree_Double octree;
348 const int buflines_max = 2048;
349 DoubleTab buffer(buflines_max, dim + nb_comp);
350 int bufptr = buflines_max;
354 double max_epsilon_needed = epsilon;
356 int error_too_many_matches = 0;
358 int error_duplicate_read = 0;
360 int count_items_read = 0;
363 trustIdType pourcent=0;
364 for (trustIdType i = 0; i < ntot; i++)
366 trustIdType tmp=(i*10)/(ntot-1);
367 if (tmp>pourcent || i==0)
370 Cerr<<
"\r"<<pourcent*10<<
"% of data has been found."<<flush;
372 if (bufptr == buflines_max)
375 trustIdType n = std::min(
static_cast<trustIdType
>(buflines_max), ntot - i);
376 n *= (dim + nb_comp);
377 assert(n <=
static_cast<trustIdType
>(buffer.size_array()));
378 fich.
get(buffer.addr(),
static_cast<int>(n));
380 const double x = buffer(bufptr, 0);
381 const double y = buffer(bufptr, 1);
382 const double z = (dim == 3) ? buffer(bufptr, 2) : 0.;
386 if (nb_items_proches > 0)
388 items.
resize_array(nb_items_proches, RESIZE_OPTIONS::NOCOPY_NOINIT);
390 for (
int j = 0; j < nb_items_proches; j++)
391 items[j] = floor_elements[index++];
395 if (nb_items_proches == 1)
397 const int flag = items_to_read[item_le_plus_proche];
401 items_to_read[item_le_plus_proche] = 2;
405 val(item_le_plus_proche) = buffer(bufptr, dim);
409 for (
int j = 0; j < nb_comp; j++)
410 val(item_le_plus_proche, j) = buffer(bufptr, dim + j);
420 error_duplicate_read++;
423 else if (nb_items_proches == 0)
431 for (
int ii = 0; ii < nb_items_proches; ii++)
433 const int i_coord = items[ii];
434 if (i_coord == item_le_plus_proche)
437 for (
int j = 0; j < dim; j++)
439 double yy = coords(i_coord, j) - buffer(bufptr, j);
444 if (max_epsilon_needed > xx)
445 max_epsilon_needed = xx;
447 error_too_many_matches++;
454 int err = (count_items_read != n_to_read) || (error_too_many_matches > 0) || (error_duplicate_read > 0);
458 error_too_many_matches =
static_cast<int>(
Process::mp_sum(error_too_many_matches));
459 error_duplicate_read =
static_cast<int>(
Process::mp_sum(error_duplicate_read));
463 if (error_too_many_matches)
465 Cerr <<
"Error in EcritureLectureSpecial: error_too_many_matches = " << error_too_many_matches
466 <<
", epsilon is too large. Suggested value: " << max_epsilon_needed << finl;
467 if (max_epsilon_needed==0)
469 Cerr <<
"It could be because your mesh has two boundaries which match exactly." << finl;
470 Cerr <<
"It is possible to do calculation with this property but xyz restart process" << finl;
471 Cerr <<
"is impossible because it can't detect the differences between faces of the two boundaries..." << finl;
472 Cerr <<
"Try to do a classic restart with .sauv files." << finl;
475 else if (error_duplicate_read)
477 Cerr <<
"Error in EcritureLectureSpecial: error_duplicate_read = " << error_duplicate_read
478 <<
", probably epsilon too large. " << finl;
482 Cerr <<
"Error in EcritureLectureSpecial: Some items were not found: epsilon too small (or the mesh has changed?)" << finl;
492static trustIdType lecture_special_part2(
const Domaine_VF& zvf,
Entree& fich, DoubleTab& val)
496 trustIdType ntot = 0;
500 DoubleTab_parts parts(val);
501 const int n = parts.size();
502 for (
int i = 0; i < n; i++)
503 ntot += lecture_special_part2(zvf, fich, parts[i]);
507 const DoubleTab& coords = get_ref_coordinates_items(zvf, md);
509 ntot += lire_special(fich, coords, val, epsilon);
513 Cerr <<
"EcritureLectureSpecial::lecture_special_part2: Error, unknown Metadata vector type : "
529 Cerr <<
"EcritureLectureSpecial::ecriture_special: error, cannot save an array with no metadata" << finl;
533 if (nb_items_seq == 0)
537 fich >> bidon >> bidon >> bidon >> bidon >> bidon;
539 trustIdType ntot = lecture_special_part2(zvf, fich, val);
540 if (ntot != nb_items_seq)
542 Cerr <<
"Internal error in EcritureLectureSpecial::lecture_special" << finl;
546 fich >> bidon >> bidon >> bidon >> bidon >> bidon >> bidon >> bidon >> bidon >> bidon >> bidon;
565 char* theValue = getenv(
"TRUST_DISABLE_MPIIO");
566 if (theValue !=
nullptr)
568 if (
option==
"EcrFicPartageMPIIO" && strcmp(theValue,
"1")==0)
option=
"EcrFicPartageBin";
int_t size_array() const
Renvoie la taille du tableau en bits.
virtual DoubleTab & valeurs()=0
classe Champ_base Cette classe est la base de la hierarchie des champs.
virtual const Domaine_dis_base & domaine_dis_base() const
DoubleTab_t & les_sommets()
virtual const DoubleTab & xv_bord() const
double xa(int num_arete, int k) const
double xv(int num_face, int k) const
int face_sommets(int i, int j) const
renvoie le numero du ieme sommet de la face num_face.
double xp(int num_elem, int k) const
const MD_Vector & md_vector_faces_bord() const
const Domaine & domaine() const
static Nom & get_Output()
Renvoie le mode d'ecriture utilise (pour pouvoir le modifier).
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 .
Entree & interpreter(Entree &fich) override
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,...
virtual int get(int *ob, std::streamsize n)
Classe de base des objets "interprete".
int get_sequential_items_flags(ArrOfBit &flags, int line_size=1) const
virtual trustIdType nb_items_seq_tot() const
Metadata for a distributed composite vector.
Dummy parallel descriptor used for sequential computations.
C'est le plus simple des descripteurs, utilise pour les tableaux de valeurs aux sommets,...
: Cette classe est un OWN_PTR mais l'objet pointe est partage entre plusieurs
const MD_Vector_base & valeur() const
class Nom Une chaine de caractere pour nommer les objets de TRUST
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.
const ArrOfInt_t & floor_elements() const
static int_t search_nodes_close_to(double x, double y, double z, const DoubleTab_t &coords, ArrOfInt_t &node_list, double epsilon)
Methode hors classe Cherche parmi les sommets de la liste node_list ceux qui sont a une.
void build_nodes(const DoubleTab_t &coords, const bool include_virtual, const double epsilon=0.)
construit un octree contenant les points de coordonnees coords.
int_t search_elements(double x, double y, double z, int_t &index) const
cherche les elements ou les points contenus dans l'octree_floor qui contient le point (x,...
static double mp_min(double)
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),...
static bool is_sequential()
Classe de base des flux de sortie.
virtual int put(const unsigned *ob, std::streamsize n, std::streamsize nb_colonnes=1)
virtual Sortie & syncfile()
_SIZE_ size_array() const
void resize_array(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
_SIZE_ dimension(int d) const
virtual const MD_Vector & get_md_vector() const
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")
static int is_PDI_checkpoint()