15#ifndef IJK_LATA_WRITER_H_TPP
16#define IJK_LATA_WRITER_H_TPP
20#include <EcrFicPartageBin.h>
22#include <IJK_Striped_Writer.h>
23#include <Parallel_io_parameters.h>
28template<
typename _TYPE_,
typename _TYPE_ARRAY_>
43 master_file.
ouvrir(filename, ios::app);
48 Cerr <<
"Error in dumplata_header: geometry has no name" << finl;
51 for (
int dir = 0; dir < 3; dir++)
53 fname[dir] = prefix + geomname +
Nom(
".coord") +
Nom((
char)(
'x'+dir));
55 binary_file.
ouvrir(fname[dir]);
59 for (i = 0; i < n; i++)
60 tmp[i] = (
float)coord[i];
61 binary_file.
put(tmp.
addr(), n, 1);
64 master_file <<
"Geom " << geomname <<
" type_elem=HEXAEDRE" << finl;
65 master_file <<
"Champ SOMMETS_IJK_I " << basename(fname[0]) <<
" geometrie=" << geomname;
66 master_file <<
" size=" << splitting.
get_nb_elem_tot(0)+1 <<
" composantes=1" << finl;
67 master_file <<
"Champ SOMMETS_IJK_J " << basename(fname[1]) <<
" geometrie=" << geomname;
68 master_file <<
" size=" << splitting.
get_nb_elem_tot(1)+1 <<
" composantes=1" << finl;
69 master_file <<
"Champ SOMMETS_IJK_K " << basename(fname[2]) <<
" geometrie=" << geomname;
70 master_file <<
" size=" << splitting.
get_nb_elem_tot(2)+1 <<
" composantes=1" << finl;
75template<
typename _TYPE_,
typename _TYPE_ARRAY_>
78 dumplata_header(filename);
79 dumplata_add_geometry(filename, f);
82template<
typename _TYPE_,
typename _TYPE_ARRAY_>
83void dumplata_vector(
const char *filename,
const char *fieldname,
89 Nom fd = prefix + fieldname;
91 const Size_t n = striped_writer.
write_data_template<float,_TYPE_,_TYPE_ARRAY_>(fd, vx, vy, vz);
95 master_file.
ouvrir(filename, ios::app);
98 master_file <<
"Champ " << fieldname <<
" " << basename(fd) <<
" geometrie=" << geomname;
100 master_file <<
" file_offset=6";
102 master_file <<
" size=" << n <<
" localisation=FACES" <<
" composantes=3" <<
" nature=vector" << finl;
107template<
typename _TYPE_,
typename _TYPE_ARRAY_>
108void dumplata_vector_parallele_plan(
const char *filename,
const char *fieldname,
114 Nom fd_global = prefix + fieldname;
121 master_file.
ouvrir(filename, ios::app);
122 const Nom& geomname = vx.get_domaine().
le_nom();
124 master_file <<
"Champ " << fieldname <<
" " << basename(fd_global) <<
" geometrie=" << geomname;
126 master_file <<
" file_offset=6";
128 master_file <<
" size=" << n <<
" localisation=FACES" <<
" composantes=3" <<
" nature=vector" << finl;
132template<
typename _TYPE_>
133void dumplata_cellvector(
const char *filename,
const char *fieldname,
136 dumplata_scalar(filename,
Nom(fieldname)+
Nom(
"_X"), v[0], step);
137 dumplata_scalar(filename,
Nom(fieldname)+
Nom(
"_Y"), v[1], step);
138 dumplata_scalar(filename,
Nom(fieldname)+
Nom(
"_Z"), v[2], step);
141template<
typename _TYPE_,
typename _TYPE_ARRAY_>
142void dumplata_scalar(
const char *filename,
const char *fieldname,
148 Nom fd = prefix + fieldname;
153 master_file.
ouvrir(filename, ios::app);
160 master_file <<
"Champ " << fieldname <<
" " << basename(fd) <<
" geometrie=" << geomname;
162 master_file <<
" file_offset=6";
164 master_file <<
" size=" << (int)n <<
" localisation=" << loc <<
" composantes=1" << finl;
169template<
typename _TYPE_,
typename _TYPE_ARRAY_>
170void dumplata_scalar_parallele_plan(
const char *filename,
const char *fieldname,
176 Nom fd_global = prefix + fieldname;
182 master_file.
ouvrir(filename, ios::app);
189 master_file <<
"Champ " << fieldname <<
" " << basename(fd_global) <<
" geometrie=" << geomname;
191 master_file <<
" file_offset=6";
193 master_file <<
" size=" << (int)n <<
" localisation=" << loc <<
" composantes=1" << finl;
201template<
typename _TYPE_,
typename _TYPE_ARRAY_>
202void read_lata_parallel_template(
const char *filename_with_path,
int tstep,
const char *geometryname,
const char *fieldname,
206 Cerr <<
"Reading lata field: file=" << filename_with_path
207 <<
" tstep=" << tstep
208 <<
" geom=" << geometryname
209 <<
" field=" << fieldname
210 <<
" component= " << i_compo << finl;
215 const int ni_local = field.
ni();
216 const int nj_local = field.
nj();
217 const int nk_local = field.
nk();
230 const LataDBField *db_field = 0;
232 ArrOfInt ni_per_slice(n_slices_i);
233 ArrOfInt slices_offsets_i;
236 int input_ni_tot = -1, input_nj_tot = -1, input_nk_tot = -1;
237 int number_of_j_per_batch = -1;
241 split_path_filename(filename_with_path, path, dbname);
242 lata_db.read_master_file(path, filename_with_path);
243 const char * locstring;
250 db_field = &lata_db.get_field(tstep, geometryname, fieldname, locstring);
251 input_ni_tot = (int)lata_db.get_field(tstep, geometryname,
"SOMMETS_IJK_I",
"", LataDB::FIRST_AND_CURRENT).size_;
252 input_nj_tot = (int)lata_db.get_field(tstep, geometryname,
"SOMMETS_IJK_J",
"", LataDB::FIRST_AND_CURRENT).size_;
253 input_nk_tot = (int)lata_db.get_field(tstep, geometryname,
"SOMMETS_IJK_K",
"", LataDB::FIRST_AND_CURRENT).size_;
258 Cerr <<
"Error: size mismatch. Current grid (number of elements): "
262 Cerr <<
"Grid in lata file: "
263 << input_ni_tot-1 <<
" " << input_nj_tot-1 <<
" " << input_nk_tot-1 << finl;
272 number_of_j_per_batch = batch_size / input_ni_tot;
273 if (number_of_j_per_batch < 1)
274 number_of_j_per_batch = 1;
275 ni_per_slice[0] = ni_local;
276 for (
int islice = 1; islice < n_slices_i; islice++)
279 recevoir(ni_per_slice[islice], src_process, 0 );
280 envoyer(number_of_j_per_batch, src_process, 0);
287 envoyer(ni_local, dest_process, 0 );
288 recevoir(number_of_j_per_batch, dest_process, 0);
291 for (
int k = 0; k < nk_local; k++)
293 const int global_k = offset_k + k;
294 for (
int j = 0; j < nj_local; j += number_of_j_per_batch)
297 const int number_of_j_this_batch = std::min(nj_local - j, number_of_j_per_batch);
298 const int global_j = offset_j + j;
299 BigFloatTab tmp_read;
300 ArrOfDouble tmp_dispatch;
304 const Size_t start = ((Size_t) global_k * input_nj_tot + global_j) * input_ni_tot;
305 const Size_t n = number_of_j_this_batch * input_ni_tot;
306 lata_db.read_data(*db_field, tmp_read, start, n);
309 Cerr <<
"Error in read_lata_parallel_template: requested component " << i_compo
310 <<
" but only " << tmp_read.
dimension_int(1) <<
" components are available" << finl;
315 for (
int islice = n_slices_i - 1; islice >= 0; islice--)
317 const int ni_this_slice = ni_per_slice[islice];
319 tmp_dispatch.
resize_array(ni_this_slice * number_of_j_this_batch);
320 const int slice_offset_i = slices_offsets_i[islice];
321 for (
int j2 = 0; j2 < number_of_j_this_batch; j2++)
323 for (
int i = 0; i < ni_this_slice; i++)
325 int src_index = j2 * input_ni_tot + (slice_offset_i + i);
326 int dest_index = j2 * ni_this_slice + i;
327 tmp_dispatch[dest_index] = tmp_read(src_index, i_compo);
334 envoyer(tmp_dispatch, dest_process, 0 );
342 recevoir(tmp_dispatch, src_process, 0 );
345 for (
int j2 = 0; j2 < number_of_j_this_batch; j2++)
347 for (
int i = 0; i < ni_local; i++)
349 int src_index = j2 * ni_local + i;
350 field(i, j2 + j, k) = tmp_dispatch[src_index];
358template<
typename _TYPE_,
typename _TYPE_ARRAY_>
359void lire_dans_lata(
const char *filename_with_path,
int tstep,
const char *geometryname,
const char *fieldname,
365 read_lata_parallel_template<_TYPE_,_TYPE_ARRAY_>(filename_with_path, tstep, geometryname, fieldname, 0 ,
374 Cerr <<
"Error in lire_dans_lata(scalar field): provided field has unsupported localisation" << finl;
386 split_path_filename(filename_with_path, path, dbname);
389 db.read_master_file(path, filename_with_path);
392 const char * locstring;
398 const LataDBField *db_field = 0;
402 db_field = &db.get_field(tstep, geometryname, fieldname, locstring);
404 if (db_field->size_ != nitot * njtot * nktot)
406 Cerr <<
"Error reading field " << geometryname <<
" / " << fieldname <<
" / " << locstring <<
" at timestep " << tstep;
407 Cerr <<
" in file " << filename_with_path <<
" : wrong size\n";
408 Cerr <<
" Expected size = " << nitot <<
" x " << njtot <<
" x " << nktot <<
" = " << nitot * njtot * nktot <<
"\n";
409 Cerr <<
" Size in file = " << db_field->size_ << finl;
412 is_double = (db_field->datatype_.type_ == LataDBDataType::REAL64);
414 envoyer_broadcast(is_double, 0);
419 db.read_data(*db_field, data);
427 db.read_data(*db_field, data);
434template<
typename _TYPE_,
typename _TYPE_ARRAY_>
435void lire_dans_lata(
const char *filename_with_path,
int tstep,
const char *geometryname,
const char *fieldname,
441 read_lata_parallel_template<_TYPE_,_TYPE_ARRAY_>(filename_with_path, tstep, geometryname, fieldname, 0 , vx);
442 read_lata_parallel_template<_TYPE_,_TYPE_ARRAY_>(filename_with_path, tstep, geometryname, fieldname, 1 , vy);
443 read_lata_parallel_template<_TYPE_,_TYPE_ARRAY_>(filename_with_path, tstep, geometryname, fieldname, 2 , vz);
453 Cerr <<
"Error in lire_dans_lata(vx, vy, vz): provided fields have incorrect localisation" << finl;
469 split_path_filename(filename_with_path, path, dbname);
472 db.read_master_file(path, filename_with_path);
475 const char * locstring =
"FACES";
477 const LataDBField *db_field = 0;
481 db_field = &db.get_field(tstep, geometryname, fieldname, locstring);
483 if (db_field->size_ != nitot * njtot * nktot)
485 Cerr <<
"Error reading field " << geometryname <<
" / " << fieldname <<
" / " << locstring <<
" at timestep " << tstep;
486 Cerr <<
" in file " << filename_with_path <<
" : wrong size\n";
487 Cerr <<
" Expected size = " << nitot <<
" x " << njtot <<
" x " << nktot <<
" = " << nitot * njtot * nktot <<
"\n";
488 Cerr <<
" Size in file = " << db_field->size_ << finl;
491 is_double = (db_field->datatype_.type_ == LataDBDataType::REAL64);
493 envoyer_broadcast(is_double, 0);
499 db.read_data(*db_field, data);
509 db.read_data(*db_field, data);
virtual void set_64b(bool is_64b)
This class encapsulates all the information related to the eulerian mesh for TrioIJK.
int get_offset_local(int direction) const
Returns the local offset in requested direction.
int get_processor_by_ijk(const FixedVector< int, 3 > &slice) const
Return the global index of the processor according to its position.
int get_nprocessor_per_direction(int direction) const
Returns the number of slices in the given direction.
void get_slice_offsets(int direction, ArrOfInt &tab) const
Returns the indices of the first cell in requested direction of every slices in this direction.
int get_nb_items_global(Localisation loc, int direction) const
Returns the number of local items (on this processor) for the given localisation in the requested dir...
int get_nb_elem_tot(int direction) const
Returns the total (global) number of mesh cells in requested direction.
const ArrOfDouble & get_node_coordinates(int direction) const
Returns an array with the coordinates of all nodes in the mesh in requested direction.
int get_local_slice_index(int direction) const
Returns the position of the local subdomain in the requested direction.
Localisation
Localisation sub class.
const Nom & le_nom() const override
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
: This class is an IJK_Field_local with parallel informations.
Domaine_IJK::Localisation get_localisation() const
const Domaine_IJK & get_domaine() const
The class IJK_Field_vector is a fixed array of polymorphic IJK fields.
: class IJK_Striped_Writer
void redistribute_load(const BigTRUSTArray< _IN_TYPE_ > &input, IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &output, const int nitot, const int njtot, const int nktot, const int nbcompo, const int component)
Size_t write_data_template(const char *filename, const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &f)
Size_t write_data_parallele_plan_template(const char *filename, const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &vx, const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &vy, const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &vz)
class Nom: a character string for naming TRUST objects.
const Nom & le_nom() const override
Returns *this.
An array of character strings (VECT(Nom)).
static Size_t get_max_block_size()
static void barrier()
Synchronizes all processors in the current group (waits until all processors have reached the barrier...
static int me()
Returns the rank of the local processor in the current communication group. See Comm_Group::rank() an...
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.
virtual int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::out)
virtual int put(const unsigned *ob, std::streamsize n, std::streamsize nb_colonnes=1)
void set_bin(bool bin) override
Changes the write mode of the file.
_SIZE_ size_array() const
void resize_array(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
int dimension_int(int d) const