TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
PrePostNN.cpp
1/****************************************************************************
2* Copyright (c) 2023, 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#include <fstream>
16#include <iostream>
17#include <sstream>
18#include <algorithm>
19#include <Process.h>
20
21#include <PrePostNN.h>
22
23PrePostNN::PrePostNN(string filename)
24{
25 string buffer, tag;
26 size_t npos;
27 ifstream f(filename,ios::in);
28
29 if(f)
30 {
31 while(getline(f, buffer))
32 {
33 buffer = trim(buffer);
34 tag = "ALPHA:";
35 npos = buffer.find(tag);
36 if(npos != string::npos) alpha = ReadDataFromLine(buffer,tag,npos);
37 tag = "LAMBDA_MEAN:";
38 npos = buffer.find(tag);
39 if(npos != string::npos) lmean = ReadDataFromLine(buffer,tag,npos);
40 tag = "LAMBDA_MAX:";
41 npos = buffer.find(tag);
42 if(npos != string::npos) lmax = ReadDataFromLine(buffer,tag,npos);
43 tag = "T_FN:";
44 npos = buffer.find(tag);
45 if(npos != string::npos) tfn = ReadDataFromLine(buffer,tag,npos);
46 tag = "B_SIGMA:";
47 npos = buffer.find(tag);
48 if(npos != string::npos) bsigma = ReadOneDataFromLine(buffer,tag,npos);
49 tag = "LAMBDA_AU:";
50 npos = buffer.find(tag);
51 if(npos != string::npos) lambda_au = ReadDataFromSeveralLines(f,5);
52 tag = "LAMBDA_AS:";
53 npos = buffer.find(tag);
54 if(npos != string::npos) lambda_as = ReadDataFromSeveralLines(f,5);
55 tag = "T_THRESH:";
56 npos = buffer.find(tag);
57 if(npos != string::npos) t_thresh = ReadOneDataFromLine(buffer,tag,npos);
58 tag = "PP_LAMBDA:";
59 npos = buffer.find(tag);
60 if(npos != string::npos) ppl = ReadPPLFromLine(buffer,tag,npos);
61 tag = "PP_T:";
62 npos = buffer.find(tag);
63 if(npos != string::npos) ppt = ReadPPTFromLine(buffer,tag,npos);
64 tag = "ILAMBDA:";
65 npos = buffer.find(tag);
66 if(npos != string::npos) ilambda = ReadIndexFromLine(buffer,tag,npos);
67 tag = "IT:";
68 npos = buffer.find(tag);
69 if(npos != string::npos) iT = ReadIndexFromLine(buffer,tag,npos);
70 }
71 f.close();
72 }
73 else
74 {
75 cerr << "fichier: " << filename << " inexistant!" << endl;
77 }
78}
79
83
84void PrePostNN::display(string tag,vector<double> vec)
85{
86 cout << tag << " ";
87 for(unsigned int i=0; i<vec.size(); i++)
88 cout << vec[i] << " ";
89 cout << endl;
90}
91
92void PrePostNN::display(string tag,vector<int> vec)
93{
94 cout << tag << " ";
95 for(unsigned int i=0; i<vec.size(); i++)
96 cout << vec[i] << " ";
97 cout << endl;
98}
99
100void PrePostNN::display(string tag,vector<vector<double>> mat)
101{
102 cout << tag << endl;
103 for(unsigned int i=0; i<mat.size(); i++)
104 {
105 for(unsigned int j=0; j<mat[i].size(); j++)
106 cout << mat[i][j] << " ";
107 cout << endl;
108 }
109}
110
111string PrePostNN::trim(const std::string& str, const std::string& whitespace)
112{
113 const auto strBegin = str.find_first_not_of(whitespace);
114 if (strBegin == std::string::npos)
115 return ""; // no content
116
117 const auto strEnd = str.find_last_not_of(whitespace);
118 const auto strRange = strEnd - strBegin + 1;
119
120 return str.substr(strBegin, strRange);
121}
122
123vector<double> PrePostNN::ReadDataFromLine(string buffer,string tag,size_t npos)
124{
125 vector<double> ret;
126 double val;
127 string sval;
128 size_t ltag;
129
130 ltag = tag.length();
131 sval = buffer.substr(npos+ltag,buffer.length()-ltag);
132 istringstream iss(sval);
133 while(!iss.eof())
134 {
135 iss >> val;
136 ret.push_back(val);
137 }
138
139 return(ret);
140}
141
142double PrePostNN::ReadOneDataFromLine(string buffer,string tag,size_t npos)
143{
144 double ret;
145 string sval;
146 size_t ltag;
147
148 ltag = tag.length();
149 sval = buffer.substr(npos+ltag,buffer.length()-ltag);
150 istringstream iss(sval);
151 iss >> ret;
152
153 return(ret);
154}
155
156enum pp_T PrePostNN::ReadPPTFromLine(string buffer,string tag,size_t npos)
157{
158 string tmp;
159 size_t ltag;
160 enum pp_T ret = INDEFT;
161
162 ltag = tag.length();
163 tmp = buffer.substr(npos+ltag,buffer.length()-ltag);
164 tmp.erase(remove(tmp.begin(), tmp.end(), ' '), tmp.end());
165
166 if( tmp.compare("TR") == 0 ) ret = TR;
167 else if( tmp.compare("TF") == 0 ) ret = TF;
168
169 return(ret);
170}
171
172enum pp_lambda PrePostNN::ReadPPLFromLine(string buffer,string tag,size_t npos)
173{
174 string tmp;
175 size_t ltag;
176 enum pp_lambda ret = INDEFL;
177
178 ltag = tag.length();
179 tmp = buffer.substr(npos+ltag,buffer.length()-ltag);
180 tmp.erase(remove(tmp.begin(), tmp.end(), ' '), tmp.end());
181
182 if( tmp.compare("LNORM") == 0 ) ret = LNORM;
183 else if( tmp.compare("LU") == 0 ) ret = LU;
184 else if( tmp.compare("LUS") == 0 ) ret = LUS;
185
186 return(ret);
187}
188
189vector<int> PrePostNN::ReadIndexFromLine(string buffer,string tag,size_t npos)
190{
191 vector<int> ret;
192 string sval;
193 int val;
194 size_t ltag;
195
196 ltag = tag.length();
197 sval = buffer.substr(npos+ltag,buffer.length()-ltag);
198 istringstream iss(sval);
199 while(!iss.eof())
200 {
201 iss >> val;
202 ret.push_back(val);
203 }
204
205 return(ret);
206}
207
208vector<vector<double>> PrePostNN::ReadDataFromSeveralLines(ifstream& f,int nblines)
209{
210 vector<vector<double>> ret;
211 vector<double> tmp;
212 string buffer;
213
214 for(int i=0; i<nblines; i++)
215 {
216 getline(f, buffer);
217 tmp = ReadDataFromLine(buffer,"",0);
218 ret.push_back(tmp);
219 }
220
221 return(ret);
222}
223
225{
226 display("ALPHA:",alpha);
227 display("LAMBDA_MEAN:",lmean);
228 display("LAMBDA_MAX:",lmax);
229 display("LAMBDA_AU:",lambda_au);
230 display("LAMBDA_AS:",lambda_as);
231 display("T_FN:",tfn);
232 cout << "B_SIGMA: " << bsigma << endl;
233 cout << "T_THRESH: " << t_thresh << endl;
234 cout << "PP_LAMBDA:" << " " << (unsigned int) ppl << endl;
235 cout << "PP_T:" << " " << (unsigned int) ppt << endl;
236 display("ILAMBDA:",ilambda);
237 display("IT:",iT);
238}
void AllDisplay()
PrePostNN(string filename)
Definition PrePostNN.cpp:23
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455