TrioCFD 1.9.8
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 Construit un fichier de type EcrFicPartage(Bin) ou EcrFicPrive(Bin), binaire ou pas selon le parametre "format".
21 *
22 * Si parallel==MULTIPLE_FILES, le fichier est de type EcrFicPrive(Bin).
23 * Dans ce cas, chaque processeur ouvre un fichier different, dont
24 * le nom est "basename_XXXXXextension", ou XXXXX est egal a Process::me().
25 * Tous les processeurs renverront is_master() == 1.
26 * Si parallel==SINGLE_FILE est non nul, le fichier est de type EcrFicPartage(Bin).
27 * Seul le processeur maitre ouvre le fichier, le nom du fichier est
28 * "basenameextension".
29 * is_master() renverra 1 sur le maitre, 0 sur les autres processeurs.
30 *
31 * @param (basename) debut du nom du fichier
32 * @param (extension) fin du nom du fichier
33 * @param (mode_append) Si mode_append==ERASE, on ouvre en mode ecriture, si mode_append==APPEND, on ouvre en mode append.
34 * @param (format) Determine si on ouvre en binaire ou pas. (valeurs possibles: Format_Post_Lata::ASCII ou Format_Post_Lata::BINAIRE)
35 * @param (parallel) fichier unique partage ou plusieurs fichiers prives...
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 // Pour un calcul sequentiel, on ouvre un fichier SFichier
56 // pour ne pas bufferiser en memoire
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 Renvoie le nom du fichier avec le path
142 *
143 */
145{
146 return filename_;
147}
148
149/*! @brief Si le fichier est de type partage, renvoie 1 si me() est egal au master du groupe et 0 sinon,
150 *
151 * Si le fichier est prive, renvoie 1 sur tous les processeurs.
152 *
153 */
155{
156 int resu = 0;
157 if (is_parallel_ == 0)
158 {
159 // Execution sequentielle, fichiers prives chaque processeur est maitre
160 resu = 1;
161 }
162 else
163 {
164 // Execution parallele : un seul maitre
166 resu = 1;
167 }
168 return resu;
169}
170
171/*! @brief Si le fichier est de type partage, appelle la methode syncfile(), sinon ne fait rien.
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 // On peut changer la precision du fichier maitre a cet endroit:
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
Si le fichier est de type partage, renvoie 1 si me() est egal au master du groupe et 0 sinon,...
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)
Construit un fichier de type EcrFicPartage(Bin) ou EcrFicPrive(Bin), binaire ou pas selon le parametr...
virtual ~Fichier_Lata()
virtual const Nom & get_filename() const
Renvoie le nom du fichier avec le path.
virtual void syncfile()
Si le fichier est de type partage, appelle la methode syncfile(), sinon ne fait rien.
: Classe de postraitement des champs euleriens au format lata
Format
@ BINAIRE
@ ASCII
Options_Para
@ SINGLE_FILE_MPIIO
@ SINGLE_FILE
@ MULTIPLE_FILES
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
static bool is_parallel()
Definition Process.cpp:110
static int me()
renvoie mon rang dans le groupe de communication courant.
Definition Process.cpp:125
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
static bool is_sequential()
Definition Process.cpp:115
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