TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Fichier_Lata.cpp
1/****************************************************************************
2* Copyright (c) 2026, 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 <EcrFicPartageMPIIO.h>
17#include <EcrFicPartageBin.h>
18#include <Fichier_Lata.h>
19
20/*! @brief Builds a file of type EcrFicPartage(Bin) or EcrFicPrive(Bin), binary or not depending on the "format" parameter.
21 *
22 * If parallel==MULTIPLE_FILES, the file is of type EcrFicPrive(Bin).
23 * In this case, each processor opens a different file named
24 * "basename_XXXXXextension", where XXXXX equals Process::me().
25 * All processors will return is_master() == 1.
26 * If parallel==SINGLE_FILE is non-zero, the file is of type EcrFicPartage(Bin).
27 * Only the master processor opens the file; the file name is
28 * "basenameextension".
29 * is_master() returns 1 on the master, 0 on other processors.
30 *
31 * @param (basename) beginning of the file name
32 * @param (extension) end of the file name
33 * @param (mode_append) If mode_append==ERASE, opens in write mode; if mode_append==APPEND, opens in append mode.
34 * @param (format) Determines whether to open in binary mode or not. (possible values: Format_Post_Lata::ASCII or Format_Post_Lata::BINAIRE)
35 * @param (parallel) single shared file or multiple private files...
36 */
37Fichier_Lata::Fichier_Lata(const char * basename, const char * extension,
38 Mode mode_append,
41 filename_(""),
42 fichier_(0),
44{
45 char s[20] = "";
46
47 switch(parallel)
48 {
51 {
52 is_parallel_ = 1;
53 filename_ = basename;
54 filename_ += extension;
55 // For sequential execution, open a SFichier
56 // to avoid buffering in memory
58 fichier_ = new SFichier;
59 else
60 {
63 else
65 }
66 break;
67 }
69 {
70 is_parallel_ = 0;
71 fichier_ = new SFichier;
72 const int moi = Process::me();
73 snprintf(s, 20, "_%05d", (int)moi);
74 break;
75 }
76 default:
77 Cerr << "Fichier_Lata::Fichier_Lata: parallel option not supported " << (int)parallel << finl;
79 }
80 filename_ = basename;
81 filename_ += s;
82 filename_ += extension;
83
84 switch(format)
85 {
87 fichier_->set_bin(0);
88 break;
90 fichier_->set_bin(1);
91 break;
92 default:
93 Cerr << "Fichier_Lata::Fichier_Lata: format not supported " << (int)format << finl;
95 }
96
97
98 IOS_OPEN_MODE mode = ios::out;
99 switch(mode_append)
100 {
101 case ERASE:
102 mode = ios::out;
103 break;
104 case APPEND:
105 mode = ios::out | ios::app;
106 break;
107 default:
108 Cerr << "Fichier_Lata::Fichier_Lata: open mode not supported " << (int)mode_append << finl;
110 }
111 //if (Process::je_suis_maitre() || parallel==Format_Post_Lata::MULTIPLE_FILES)
112 {
113 int ok = fichier_->ouvrir(filename_, mode);
114 if (!ok)
115 {
116 Cerr << "Error in Fichier_Lata::Fichier_Lata\n"
117 << " Error while opening file : " << filename_
118 << finl;
120 }
121 fichier_->setf(ios::scientific);
122 fichier_->precision(8);
123 }
124}
125
127{
128 if (fichier_)
129 {
130 delete fichier_;
131 fichier_ = 0;
132 }
133}
134
136{
137 assert(fichier_);
138 return *fichier_;
139}
140
141/*! @brief Returns the file name with its path.
142 *
143 */
145{
146 return filename_;
147}
148
149/*! @brief If the file is of shared type, returns 1 if me() equals the group master, 0 otherwise.
150 *
151 * If the file is private, returns 1 on all processors.
152 *
153 */
155{
156 int resu = 0;
157 if (is_parallel_ == 0)
158 {
159 // Sequential execution, private files: each processor is master
160 resu = 1;
161 }
162 else
163 {
164 // Parallel execution: a single master
166 resu = 1;
167 }
168 return resu;
169}
170
171/*! @brief If the file is of shared type, calls the syncfile() method; otherwise does nothing.
172 *
173 */
175{
177 fichier_->syncfile();
178}
179
181 const char * extension,
182 Mode mode_append,
184 Fichier_Lata(basename, extension,
185 mode_append, Format_Post_Lata::ASCII, parallel)
186{
187 fichier_->setf(ios::scientific);
188 // The precision of the master file can be changed here:
189 fichier_->precision(8);
190}
Class to use MPI-IO to write in a single file.
Fichier_Lata_maitre(const char *basename, const char *extension, Mode mode_append, Format_Post_Lata::Options_Para parallel)
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()
SFichier * fichier_
Fichier_Lata(const char *basename, const char *extension, Mode mode_append, Format_Post_Lata::Format format, Format_Post_Lata::Options_Para parallel)
Builds a file of type EcrFicPartage(Bin) or EcrFicPrive(Bin), binary or not depending on the "format"...
virtual ~Fichier_Lata()
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.
Format
@ BINAIRE
@ ASCII
Options_Para
@ SINGLE_FILE_MPIIO
@ SINGLE_FILE
@ MULTIPLE_FILES
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
static bool is_parallel()
Definition Process.cpp:108
static int me()
Returns the rank of the local processor in the current communication group. See Comm_Group::rank() an...
Definition Process.cpp:122
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
static bool is_sequential()
Definition Process.cpp:113
SFichier is to the C++ ofstream class what Sortie is to the C++ ostream class.
Definition SFichier.h:29