TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
LecFicDiffuse_JDD.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 <LecFicDiffuse_JDD.h>
17#include <communications.h>
18#include <EFichier.h>
19#include <SChaine.h>
20#include <Type_Verifie.h>
21
22Implemente_instanciable_sans_constructeur(LecFicDiffuse_JDD,"LecFicDiffuse_JDD",Lec_Diffuse_base);
23
26{
27 throw;
28}
29
31{
32 throw;
33}
34
38
39/*! @brief ouverture du fichier name.
40 *
41 * Cette methode doit etre appelee sur tous les processeurs. En cas
42 * d'echec : exit()
43 *
44 */
46 IOS_OPEN_MODE mode)
47{
48 int ok = ouvrir(name, mode);
49 if (!ok && Process::je_suis_maitre())
50 {
51 Cerr << "File " << name << " does not exist (LecFicDiffuse_JDD)" << finl;
53 }
54}
55
56
57/*! @brief Ouverture du fichier.
58 *
59 * Cette methode doit etre appelee par tous les processeurs du groupe.
60 * Valeur de retour: 1 si ok, 0 sinon
61 *
62 */
63int LecFicDiffuse_JDD::ouvrir(const char* name,
64 IOS_OPEN_MODE mode)
65{
66 int ok = 0;
68 {
69 Cout <<"Reading data file "<<finl;
70 bool fin_lu = false;
71 Motcle fin("fin|end");
72 EFichier file_;
73 ok = file_.ouvrir(name, mode);
74 if (!ok )
75 {
76 Cerr << "File " << name << " does not exist (LecFicDiffuse_JDD)" << finl;
78 }
79
80 SChaine prov;
81 Nom motlu;
82 Nom comments="";
83 file_>>motlu;
84 int nb_accolade=0;
85 int nb_accolade_sa=-1;
86 int line=1;
87 bool petsc_format = false;
88 while (!fin_lu)
89 {
90 if (file_.eof())
91 {
92 break;
93 }
94 if (motlu=="{")
95 nb_accolade++;
96 if (motlu=="}")
97 nb_accolade--;
98 if (fin==motlu)
99 {
100 fin_lu = true;
101 nb_accolade_sa=nb_accolade;
102 }
103 if (!fin_lu)
104 {
105 if (motlu=="#")
106 {
107 // Cerr<<" on passe les commentaires"<<finl;
108 comments += std::string("[") + std::string(name) + "] : Comments bloc starts at line " + std::to_string(line)+ " ";
109 int jol = file_.jumpOfLines();
110 for(int jump=0; jump<jol; jump++)
111 prov <<"\n";
112 line+=jol;
113 file_>>motlu;
114 while (motlu!="#")
115 {
116 if (file_.eof())
117 {
118 Cerr << comments;
119 Nom msg = "\nProblem while reading some # \n # not closed.\n";
120 msg+= "============================================\nExiting TRUST.";
121 Process::exit(msg);
122 }
123 jol = file_.jumpOfLines();
124 for(int jump=0; jump<jol; jump++)
125 prov <<"\n";
126 line += jol;
127 file_ >> motlu;
128 }
129 comments += "and ends at line " + std::to_string(line)+"\n";
130 jol = file_.jumpOfLines();
131 for(int jump=0; jump<jol; jump++)
132 prov <<"\n";
133 line += jol;
134 }
135
136 else if (motlu=="/*")
137 {
138 // Cerr<<" on passe le bloc de commentaires"<<finl;
139 int ouvrante=1;
140 comments += std::string("[") + std::string(name) + "] : Comments bloc starts at line " + std::to_string(line) + " ";
141 while (ouvrante!=0)
142 {
143 int jol = file_.jumpOfLines();
144 for(int jump=0; jump<jol; jump++)
145 prov <<"\n";
146 line+=jol;
147 file_ >>motlu;
148 if (file_.eof())
149 {
150 Cerr << comments;
151 Nom msg = "\nProblem while reading some /* \n not closed.\n";
152 msg+= "============================================\nExiting TRUST.";
153 Process::exit(msg);
154 }
155 if (motlu=="/*") ouvrante++;
156 if (motlu=="*/") ouvrante--;
157 }
158 comments += "and ends at line " + std::to_string(line)+"\n";
159 int jol = file_.jumpOfLines();
160 for(int jump=0; jump<jol; jump++)
161 prov <<"\n";
162 line+=jol;
163 }
164 else if ((motlu.find("}")!=-1 && motlu != "}") || (motlu.find("{")!=-1 && motlu != "{") || (motlu.find("#")!=-1) || (motlu.find(",")!=-1 && motlu != "," && !petsc_format))
165 {
166 Nom msg = "Error while reading '" + motlu.getString() + "' from datafile " + name + " at line " + std::to_string(line) + ".\nCheck for missing space character.\n";
167 msg+= "============================================\nExiting TRUST.";
168 Process::exit(msg);
169 }
170
171 /* GF ne pas reactiver ce morceau de code car cela
172 est complique pour la traduction des jdd en python
173 else if (motlu=="##")
174 {
175
176 Cerr<<" The comment line is crossed."<<finl;
177 std::string ligne;
178 std::getline(file_.get_ifstream(), ligne);
179
180 }
181 */
182 else
183 {
184 prov<<motlu;
185 int jol = file_.jumpOfLines();
186 if(jol==0)
187 prov << " ";
188 else
189 for(int jump=0; jump<jol; jump++)
190 prov <<"\n";
191 line+=jol;
192 if( apply_verif )
193 verifie(motlu);
194 petsc_format = false;
195 if ((motlu.debute_par("-pc_fieldsplit_") && motlu.finit_par("_fields")))
196 petsc_format = true;
197 }
198 file_>>motlu;
199
200 }
201 }
202 if (fin_lu)
203 nb_accolade=nb_accolade_sa;
204 if (nb_accolade!=0)
205 {
206 if (nb_accolade<0)
207 Cerr<<"Error perhaps extra \"}\" or missing \"#\" in data file"<<finl;
208 else
209 Cerr<<"Error check for missing \"}\" in data file"<<finl;
211 }
212
213 chaine_.init(prov.get_str());
214 Cout <<finl;
215
216 Process::Journal()<<"JDD interpreted: "<<finl<<prov.get_str()<<finl<<finl;
217 }
218 envoyer_broadcast(ok, 0);
219 return ok;
220}
221
EFichier(const char *name, IOS_OPEN_MODE mode=ios::in)
Definition EFichier.cpp:20
virtual int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::in)
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual int jumpOfLines()
Definition Entree.cpp:238
Cette classe implemente les operateurs et les methodes virtuelles de la classe EFichier de la facon s...
static bool apply_verif
! whether obsolete keywords should be checked or not. True by default.
Entree & get_entree_master() override
int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::in) override
Ouverture du fichier.
Classe de base des entrees diffusees: le processeur maitre lit les donnees dans la classe get_entree_...
Une chaine de caractere (Nom) en majuscules.
Definition Motcle.h:26
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
const std::string & getString() const
Definition Nom.h:92
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
static Sortie & Journal(int message_level=0)
Renvoie un objet statique de type Sortie qui sert de journal d'evenements.
Definition Process.cpp:588
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 derivee de Sortie empile ce qu'on lui envoie dans une chaine de caracteres.
Definition SChaine.h:26
const char * get_str() const
returns a copy of the string stored by the SChaine
Definition SChaine.cpp:72
Classe de base des flux de sortie.
Definition Sortie.h:52