TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
IJK_Lata_writer.cpp
1/****************************************************************************
2* Copyright (c) 2025, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#include <IJK_Lata_writer.h>
17#include <iomanip>
18
19void dumplata_newtime(const char *filename, double time)
20{
22 {
23 SFichier master_file;
24
25 // Write out time with maximal double precision:
26 const int default_prec = (int)std::cout.precision();
27 constexpr int max_prec = std::numeric_limits<double>::digits10 + 1;
28 std::ostringstream oss;
29 oss << "TEMPS " << std::setprecision(max_prec) << time << std::setprecision(default_prec);
30
31 master_file.ouvrir(filename, ios::app);
32 master_file << oss.str() << finl;
33 }
34}
35
36void dumplata_header(const char *filename)
37{
39 {
40 SFichier master_file;
41
42 master_file.set_bin(0);
43 master_file.ouvrir(filename);
44 master_file << "LATA_V2.1" << finl;
45 master_file << "IJK_specific_format" << finl;
46 master_file << "TRUST" << finl;
47 Nom format = (sizeof(int)==8 ? "INT64" : "INT32");
48 master_file << "Format LITTLE_ENDIAN,C_INDEXING,C_ORDERING,F_MARKERS_NO,"<<format<<",REAL32" << finl;
49 master_file.close();
50 }
51}
52
53/*! When dumping the IJK coordinates, we do not need 64b, since only the x, y and z steps will be written.
54 * This never exceeds 32b.
55 */
56void dumplata_add_geometry(const char *filename, const Domaine_IJK& splitting)
57{
59 {
60 SFichier master_file;
61 Nom prefix = Nom(filename) + Nom(".");
62 SFichier binary_file;
63 binary_file.set_bin(1);
64 binary_file.set_64b(false);
65 ArrOfFloat tmp;
66 int n;
67
68 Nom basename(filename);
69 master_file.set_bin(0);
70 master_file.ouvrir(basename, ios::app);
71 Noms fname(3);
72 const Nom& geomname = splitting.le_nom();
73 if (geomname == "??")
74 {
75 Cerr << "Error in dumplata_header: geometry has no name" << finl;
77 }
78 for (int dir = 0; dir < 3; dir++)
79 {
80 fname[dir] = prefix + geomname + Nom(".coord") + Nom((char)('x'+dir));
81 int i;
82 binary_file.ouvrir(fname[dir]);
83 const ArrOfDouble& coord = splitting.get_node_coordinates(dir);
84 n = coord.size_array();
85 tmp.resize_array(n);
86 for (i = 0; i < n; i++)
87 tmp[i] = (float)coord[i]; // LATA in float ... pfff
88 binary_file.put(tmp.addr(), n, 1);
89 binary_file.close();
90 }
91 master_file << "Geom " << geomname << " type_elem=HEXAEDRE" << finl;
92 master_file << "Champ SOMMETS_IJK_I " << fname[0] << " geometrie=" << geomname << " size=" << splitting.get_nb_elem_tot(0)+1 << " composantes=1" << finl;
93 master_file << "Champ SOMMETS_IJK_J " << fname[1] << " geometrie=" << geomname << " size=" << splitting.get_nb_elem_tot(1)+1 << " composantes=1" << finl;
94 master_file << "Champ SOMMETS_IJK_K " << fname[2] << " geometrie=" << geomname << " size=" << splitting.get_nb_elem_tot(2)+1 << " composantes=1" << finl;
95 master_file.close();
96 }
97}
98
99void dumplata_ft_field(const char *filename, const char *meshname,
100 const char *field_name, const char *localisation,
101 const ArrOfInt& field, int step)
102{
103 Nom prefix = Nom(filename) + Nom(".") + Nom(step) + Nom(".") + Nom(meshname) + Nom(".");
104 Nom fdfield = prefix + field_name;
105 const int nval = field.size_array();
106 const trustIdType nvaltot = Process::mp_sum(nval);
107 EcrFicPartageBin file;
108 file.set_64b(false); // for interfaces, 64b never needed.
109 file.ouvrir(fdfield);
110 file.put(field.addr(), field.size_array(), 1);
111 file.syncfile();
112 file.close();
114 {
115 SFichier master_file;
116 master_file.ouvrir(filename, ios::app);
117 // NO_INDEXING car ce n'est pas un indice de sommet ou de facette
118 // In a IJK Lata file, the int written are typically PE numbers or connex components number, never need 64b.
119 Nom format = "INT32";
120 master_file << "Champ " << field_name << " " << basename(fdfield) << " geometrie=" << meshname ;
121 // Note: nvaltot is the only thing that might be huge
122 master_file << " size=" << nvaltot << " composantes=1 format="<<format<<",NO_INDEXING localisation="
123 << localisation << finl;
124 }
125
126}
127
128void dumplata_ft_field(const char *filename, const char *meshname,
129 const char *field_name, const char *localisation,
130 const ArrOfDouble& field, int step)
131{
132 Nom prefix = Nom(filename) + Nom(".") + Nom(step) + Nom(".") + Nom(meshname) + Nom(".");
133 Nom fdfield = prefix + field_name;
134 const int nval = field.size_array();
135 const trustIdType nvaltot = Process::mp_sum(nval);
136 EcrFicPartageBin file;
137 file.set_64b(false); // for interfaces, 64b never needed.
138 file.ouvrir(fdfield);
139 const int n = field.size_array();
140 ArrOfFloat tmp(n);
141 for (int i = 0; i < n; i++)
142 tmp[i] = (float)field[i];
143
144 file.put(tmp.addr(), field.size_array(), 1);
145 file.syncfile();
146 file.close();
148 {
149 SFichier master_file;
150 master_file.ouvrir(filename, ios::app);
151 int nb_compo ;
152
153 const DoubleTab* zfld = dynamic_cast<const DoubleTab*>(&field);
154 if (zfld)
155 {
156 nb_compo = zfld->dimension(1);
157 }
158 else
159 {
160 nb_compo = 1;
161 }
162 master_file << "Champ " << field_name << " " << basename(fdfield) << " geometrie=" << meshname;
163 // Note : nvaltot/nb_compo might be big ...
164 master_file << " size=" << nvaltot/nb_compo << " composantes=" << nb_compo << " localisation="
165 << localisation << finl;
166 }
167
168}
169
170void dumplata_finish(const char *filename)
171{
173 {
174 SFichier master_file;
175 master_file.ouvrir(filename, ios::app);
176 master_file << "FIN" << finl;
177 }
178}
179
180Nom dirname(const Nom& filename)
181{
182 Nom path, name;
183 split_path_filename(filename, path, name);
184 return path;
185}
186Nom basename(const Nom& filename)
187{
188 Nom path, name;
189 split_path_filename(filename, path, name);
190 return name;
191}
192
193bool lata_has_field(const char *filename_with_path, int tstep, const char *geometryname, const char *fieldname)
194{
195 Nom path, dbname;
196 split_path_filename(filename_with_path, path, dbname);
197 LataDB db;
198
199 db.read_master_file(path, filename_with_path);
200
201
202 return db.field_exists(tstep, geometryname, fieldname);
203
204}
virtual void set_64b(bool is_64b)
Definition AbstractIO.h:38
This class encapsulates all the information related to the eulerian mesh for TrioIJK.
Definition Domaine_IJK.h:47
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.
const Nom & le_nom() const override
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
Ecriture dans un fichier partage Cette classe derive de Ecr_Fic_Par, en utilisant une sortie en binai...
int put(const unsigned *ob, std::streamsize n, std::streamsize pas) override
int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::out) override
Ouvre le fichier avec les parametres mode et prot donnes Ces parametres sont les parametres de la met...
Sortie & syncfile() override
Provoque l'ecriture sur disque des donnees accumulees sur les differents processeurs depuis le dernie...
void set_64b(bool is64) override
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
Un tableau de chaine de caracteres (VECT(Nom)).
Definition Noms.h:26
static double mp_sum(double)
Calcule la somme de x sur tous les processeurs du groupe courant.
Definition Process.cpp:146
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
static int je_suis_maitre()
renvoie 1 si on est sur le processeur maitre du groupe courant (c'est a dire me() == 0),...
Definition Process.cpp:86
Cette classe est a la classe C++ ofstream ce que la classe Sortie est a la classe C++ ostream Elle re...
Definition SFichier.h:27
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)
Definition Sortie.cpp:101
void set_bin(bool bin) override
Change le mode d'ecriture du fichier.
Definition Sortie.cpp:255
_SIZE_ size_array() const
_TYPE_ * addr()
void resize_array(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133