TrioCFD 1.9.9_beta
TrioCFD documentation
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/*! @brief 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 * @param filename path to the LATA master file
56 * @param splitting the IJK domain splitting containing the geometry information
57 */
58void dumplata_add_geometry(const char *filename, const Domaine_IJK& splitting)
59{
61 {
62 SFichier master_file;
63 Nom prefix = Nom(filename) + Nom(".");
64 SFichier binary_file;
65 binary_file.set_bin(1);
66 binary_file.set_64b(false);
67 ArrOfFloat tmp;
68 int n;
69
70 Nom basename(filename);
71 master_file.set_bin(0);
72 master_file.ouvrir(basename, ios::app);
73 Noms fname(3);
74 const Nom& geomname = splitting.le_nom();
75 if (geomname == "??")
76 {
77 Cerr << "Error in dumplata_header: geometry has no name" << finl;
79 }
80 for (int dir = 0; dir < 3; dir++)
81 {
82 fname[dir] = prefix + geomname + Nom(".coord") + Nom((char)('x'+dir));
83 int i;
84 binary_file.ouvrir(fname[dir]);
85 const ArrOfDouble& coord = splitting.get_node_coordinates(dir);
86 n = coord.size_array();
87 tmp.resize_array(n);
88 for (i = 0; i < n; i++)
89 tmp[i] = (float)coord[i]; // LATA in float ... pfff
90 binary_file.put(tmp.addr(), n, 1);
91 binary_file.close();
92 }
93 master_file << "Geom " << geomname << " type_elem=HEXAEDRE" << finl;
94 master_file << "Champ SOMMETS_IJK_I " << fname[0] << " geometrie=" << geomname << " size=" << splitting.get_nb_elem_tot(0)+1 << " composantes=1" << finl;
95 master_file << "Champ SOMMETS_IJK_J " << fname[1] << " geometrie=" << geomname << " size=" << splitting.get_nb_elem_tot(1)+1 << " composantes=1" << finl;
96 master_file << "Champ SOMMETS_IJK_K " << fname[2] << " geometrie=" << geomname << " size=" << splitting.get_nb_elem_tot(2)+1 << " composantes=1" << finl;
97 master_file.close();
98 }
99}
100
101void dumplata_ft_field(const char *filename, const char *meshname,
102 const char *field_name, const char *localisation,
103 const ArrOfInt& field, int step)
104{
105 Nom prefix = Nom(filename) + Nom(".") + Nom(step) + Nom(".") + Nom(meshname) + Nom(".");
106 Nom fdfield = prefix + field_name;
107 const int nval = field.size_array();
108 const trustIdType nvaltot = Process::mp_sum(nval);
109 EcrFicPartageBin file;
110 file.set_64b(false); // for interfaces, 64b never needed.
111 file.ouvrir(fdfield);
112 file.put(field.addr(), field.size_array(), 1);
113 file.syncfile();
114 file.close();
116 {
117 SFichier master_file;
118 master_file.ouvrir(filename, ios::app);
119 // NO_INDEXING because this is not a vertex or facet index
120 // In a IJK Lata file, the int written are typically PE numbers or connex components number, never need 64b.
121 Nom format = "INT32";
122 master_file << "Champ " << field_name << " " << basename(fdfield) << " geometrie=" << meshname ;
123 // Note: nvaltot is the only thing that might be huge
124 master_file << " size=" << nvaltot << " composantes=1 format="<<format<<",NO_INDEXING localisation="
125 << localisation << finl;
126 }
127
128}
129
130void dumplata_ft_field(const char *filename, const char *meshname,
131 const char *field_name, const char *localisation,
132 const ArrOfDouble& field, int step)
133{
134 Nom prefix = Nom(filename) + Nom(".") + Nom(step) + Nom(".") + Nom(meshname) + Nom(".");
135 Nom fdfield = prefix + field_name;
136 const int nval = field.size_array();
137 const trustIdType nvaltot = Process::mp_sum(nval);
138 EcrFicPartageBin file;
139 file.set_64b(false); // for interfaces, 64b never needed.
140 file.ouvrir(fdfield);
141 const int n = field.size_array();
142 ArrOfFloat tmp(n);
143 for (int i = 0; i < n; i++)
144 tmp[i] = (float)field[i];
145
146 file.put(tmp.addr(), field.size_array(), 1);
147 file.syncfile();
148 file.close();
150 {
151 SFichier master_file;
152 master_file.ouvrir(filename, ios::app);
153 int nb_compo ;
154
155 const DoubleTab* zfld = dynamic_cast<const DoubleTab*>(&field);
156 if (zfld)
157 {
158 nb_compo = zfld->dimension(1);
159 }
160 else
161 {
162 nb_compo = 1;
163 }
164 master_file << "Champ " << field_name << " " << basename(fdfield) << " geometrie=" << meshname;
165 // Note : nvaltot/nb_compo might be big ...
166 master_file << " size=" << nvaltot/nb_compo << " composantes=" << nb_compo << " localisation="
167 << localisation << finl;
168 }
169
170}
171
172void dumplata_finish(const char *filename)
173{
175 {
176 SFichier master_file;
177 master_file.ouvrir(filename, ios::app);
178 master_file << "FIN" << finl;
179 }
180}
181
182Nom dirname(const Nom& filename)
183{
184 Nom path, name;
185 split_path_filename(filename, path, name);
186 return path;
187}
188Nom basename(const Nom& filename)
189{
190 Nom path, name;
191 split_path_filename(filename, path, name);
192 return name;
193}
194
195bool lata_has_field(const char *filename_with_path, int tstep, const char *geometryname, const char *fieldname)
196{
197 Nom path, dbname;
198 split_path_filename(filename_with_path, path, dbname);
199 LataDB db;
200
201 db.read_master_file(path, filename_with_path);
202
203
204 return db.field_exists(tstep, geometryname, fieldname);
205
206}
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
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
Writing to a shared file. This class derives from Ecr_Fic_Par, using binary output.
int put(const unsigned *ob, std::streamsize n, std::streamsize pas) override
int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::out) override
Opens the file with the given mode and prot parameters. These parameters are the parameters of the st...
Sortie & syncfile() override
Triggers writing to disk of the data accumulated on the different processors since the last call to s...
void set_64b(bool is64) override
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
An array of character strings (VECT(Nom)).
Definition Noms.h:26
static double mp_sum(double)
Computes the sum of x over all processors in the current group.
Definition Process.cpp:145
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
static int je_suis_maitre()
Returns 1 if on the master processor of the current group (i.e. me() == 0), 0 otherwise.
Definition Process.cpp:82
SFichier is to the C++ ofstream class what Sortie is to the C++ ostream class.
Definition SFichier.h:29
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
Changes the write mode of the file.
Definition Sortie.cpp:252
_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