TrioCFD 1.9.9_beta
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 Opens file name.
40 *
41 * This method must be called on all processors. On failure: exit().
42 *
43 */
45 IOS_OPEN_MODE mode)
46{
47 int ok = ouvrir(name, mode);
48 if (!ok && Process::je_suis_maitre())
49 {
50 Cerr << "File " << name << " does not exist (LecFicDiffuse_JDD)" << finl;
52 }
53}
54
55
56/*! @brief Opens the file.
57 *
58 * This method must be called by all processors in the group.
59 * Return value: 1 if ok, 0 otherwise.
60 *
61 */
62int LecFicDiffuse_JDD::ouvrir(const char* name,
63 IOS_OPEN_MODE mode)
64{
65 int ok = 0;
67 {
68 Cout <<"Reading data file "<<finl;
69 bool fin_lu = false;
70 Motcle fin("fin|end");
71 EFichier file_;
72 ok = file_.ouvrir(name, mode);
73 if (!ok )
74 {
75 Cerr << "File " << name << " does not exist (LecFicDiffuse_JDD)" << finl;
77 }
78
79 SChaine prov;
80 Nom motlu;
81 Nom comments="";
82 file_>>motlu;
83 int nb_accolade=0;
84 int nb_accolade_sa=-1;
85 int line=1;
86 bool petsc_format = false;
87 while (!fin_lu)
88 {
89 if (file_.eof())
90 {
91 break;
92 }
93 if (motlu=="{")
94 nb_accolade++;
95 if (motlu=="}")
96 nb_accolade--;
97 if (fin==motlu)
98 {
99 fin_lu = true;
100 nb_accolade_sa=nb_accolade;
101 }
102 if (!fin_lu)
103 {
104 if (motlu=="#")
105 {
106 // Cerr<<" on passe les commentaires"<<finl;
107 comments += std::string("[") + std::string(name) + "] : Comments bloc starts at line " + std::to_string(line)+ " ";
108 int jol = file_.jumpOfLines();
109 for(int jump=0; jump<jol; jump++)
110 prov <<"\n";
111 line+=jol;
112 file_>>motlu;
113 while (motlu!="#")
114 {
115 if (file_.eof())
116 {
117 Cerr << comments;
118 Nom msg = "\nProblem while reading some # \n # not closed.\n";
119 msg+= "============================================\nExiting TRUST.";
120 Process::exit(msg);
121 }
122 jol = file_.jumpOfLines();
123 for(int jump=0; jump<jol; jump++)
124 prov <<"\n";
125 line += jol;
126 file_ >> motlu;
127 }
128 comments += "and ends at line " + std::to_string(line)+"\n";
129 jol = file_.jumpOfLines();
130 for(int jump=0; jump<jol; jump++)
131 prov <<"\n";
132 line += jol;
133 }
134
135 else if (motlu=="/*")
136 {
137 // Cerr<<" on passe le bloc de commentaires"<<finl;
138 int ouvrante=1;
139 comments += std::string("[") + std::string(name) + "] : Comments bloc starts at line " + std::to_string(line) + " ";
140 while (ouvrante!=0)
141 {
142 int jol = file_.jumpOfLines();
143 for(int jump=0; jump<jol; jump++)
144 prov <<"\n";
145 line+=jol;
146 file_ >>motlu;
147 if (file_.eof())
148 {
149 Cerr << comments;
150 Nom msg = "\nProblem while reading some /* \n not closed.\n";
151 msg+= "============================================\nExiting TRUST.";
152 Process::exit(msg);
153 }
154 if (motlu=="/*") ouvrante++;
155 if (motlu=="*/") ouvrante--;
156 }
157 comments += "and ends at line " + std::to_string(line)+"\n";
158 int jol = file_.jumpOfLines();
159 for(int jump=0; jump<jol; jump++)
160 prov <<"\n";
161 line+=jol;
162 }
163 else if ((motlu.find("}")!=-1 && motlu != "}") || (motlu.find("{")!=-1 && motlu != "{") || (motlu.find("#")!=-1) || (motlu.find(",")!=-1 && motlu != "," && !petsc_format))
164 {
165 Nom msg = "Error while reading '" + motlu.getString() + "' from datafile " + name + " at line " + std::to_string(line) + ".\nCheck for missing space character.\n";
166 msg+= "============================================\nExiting TRUST.";
167 Process::exit(msg);
168 }
169
170 /* GF do not re-enable this code block as it complicates
171 the translation of data sets to Python
172 else if (motlu=="##")
173 {
174
175 Cerr<<" The comment line is crossed."<<finl;
176 std::string ligne;
177 std::getline(file_.get_ifstream(), ligne);
178
179 }
180 */
181 else
182 {
183 prov<<motlu;
184 int jol = file_.jumpOfLines();
185 if(jol==0)
186 prov << " ";
187 else
188 for(int jump=0; jump<jol; jump++)
189 prov <<"\n";
190 line+=jol;
191 if( apply_verif )
192 verifie(motlu);
193 petsc_format = false;
194 if ((motlu.debute_par("-pc_fieldsplit_") && motlu.finit_par("_fields")))
195 petsc_format = true;
196 }
197 file_>>motlu;
198
199 }
200 }
201 if (fin_lu)
202 nb_accolade=nb_accolade_sa;
203 if (nb_accolade!=0)
204 {
205 if (nb_accolade<0)
206 Cerr<<"Error perhaps extra \"}\" or missing \"#\" in data file"<<finl;
207 else
208 Cerr<<"Error check for missing \"}\" in data file"<<finl;
210 }
211
212 chaine_.init(prov.get_str());
213 Cout <<finl;
214
215 Process::Journal()<<"JDD interpreted: "<<finl<<prov.get_str()<<finl<<finl;
216 }
217 envoyer_broadcast(ok, 0);
218 return ok;
219}
220
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
This class implements the operators and virtual methods of the EFichier class as follows: The file to...
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
Opens the file.
Base class for diffused inputs: the master processor reads data from get_entree_master() and broadcas...
A character string (Nom) in uppercase.
Definition Motcle.h:26
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
const std::string & getString() const
Definition Nom.h:92
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
static Sortie & Journal(int message_level=0)
Returns a static Sortie object used as an event journal.
Definition Process.cpp:592
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
This class, derived from Sortie, accumulates what is sent to it into a character string.
Definition SChaine.h:26
const char * get_str() const
returns a copy of the string stored by the SChaine
Definition SChaine.cpp:72
Base class for output streams.
Definition Sortie.h:52