1 // Copyright (C) 2011-2020 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : MG_ADAPT.hxx
34 #include "MEDFileMesh.hxx"
44 typedef std::map< std::string, std::string > TOptionValues;
45 typedef std::set< std::string > TOptionNames;
47 struct MgAdaptHypothesisData
49 std::string myFileInDir, myMeshFileIn, myInMeshName, myMeshFileBackground, myOutMeshName,
50 myMeshFileOut, myFileOutDir, myFileSizeMapDir, myFieldName;
52 bool myPublish, myMeshOutMed;
53 bool myUseLocalMap, myUseBackgroundMap, myUseConstantValue;
54 double myConstantValue;
55 int myRank, myTimeStep;
56 bool myUseNoTimeStep, myUseLastTimeStep, myUseChosenTimeStep;
57 std::string myWorkingDir, myLogFile;
58 bool myPrintLogInFile, myKeepFiles, myRemoveLogOnSuccess;
63 class outFileStream : public std::ofstream{
65 ~outFileStream(){close();} //to close file at dtor
69 * \brief Class to generate string from any type
71 class ToComment : public std::string
73 std::ostringstream _s ;
77 ToComment():std::string("") {}
79 ToComment(const ToComment& c):std::string() {
81 this->std::string::operator=( _s.str() );
84 ToComment & operator=(const ToComment& c) {
86 this->std::string::operator=( _s.str() );
91 ToComment( const T &anything ) {
93 this->std::string::operator=( _s.str() );
97 ToComment & operator<<( const T &anything ) {
99 this->std::string::operator=( _s.str() );
103 operator char*() const {
104 return (char*)c_str();
107 std::ostream& Stream() {
115 enum YesNo {YES, NO};
119 MgAdapt(MgAdaptHypothesisData*);
120 MgAdapt(const MgAdapt&);
123 void setData( MgAdaptHypothesisData*);
125 void setMedFileIn(std::string);
126 std::string getMedFileIn();
128 void setMedFileOut(std::string);
129 std::string getMedFileOut();
131 void setMeshName(std::string);
132 std::string getMeshName();
134 void setMeshNameOut(std::string);
135 std::string getMeshNameOut();
137 void setMeshOutMed(bool);
138 bool getMeshOutMed();
140 void setPublish(bool);
143 void setFieldName(std::string);
144 std::string getFieldName();
146 void setTimeStep(int);
147 int getTimeStep() const;
149 void setRankTimeStep(int, int );
152 void setLogFile(std::string);
153 std::string getLogFile();
155 void setVerbosityLevel(int);
156 int getVerbosityLevel();
158 void setRemoveOnSuccess(bool);
159 bool getRemoveOnSuccess();
161 MgAdaptHypothesisData* getData() const;
163 void setUseLocalMap(bool);
164 bool getUseLocalMap();
166 void setUseBackgroundMap(bool);
167 bool getUseBackgroundMap();
169 void setUseConstantValue(bool);
170 bool getUseConstantValue();
172 void setConstantValue(double);
173 bool getConstantValue();
175 void setSizeMapFile(std::string);
176 std::string getSizeMapFile();
178 void setFromMedFile(bool);
179 bool isFromMedFile();
181 void setKeepWorkingFiles(bool);
182 bool getKeepWorkingFiles();
184 void setPrintLogInFile(bool);
185 bool getPrintLogInFile();
187 void setWorkingDir(std::string);
188 std::string getWorkingDir() const;
192 static std::string getCommandToRun(MgAdapt* );
193 std::string getCommandToRun() ;
194 int compute(std::string& errStr);
195 std::string getFileName() const;
196 static std::string getExeName();
197 void copyMgAdaptHypothesisData( MgAdaptHypothesisData* ) ;
199 void checkDirPath(std::string& );
203 bool hasOptionDefined( const std::string& optionName ) const;
204 void setOptionValue(const std::string& optionName,
205 const std::string& optionValue) throw (std::invalid_argument);
206 std::string getOptionValue(const std::string& optionName,
207 bool* isDefault=0) const throw (std::invalid_argument);
208 std::vector <std::string> getCustomOptionValuesStrVec() const;
209 std::vector <std::string> getOptionValuesStrVec() const;
212 TOptionValues getOptionValues() const;
213 const TOptionValues& getCustomOptionValues() const ;
214 static double toDbl(const std::string&, bool* isOk = 0) throw (std::invalid_argument);
215 static bool toBool(const std::string&, bool* isOk = 0) throw (std::invalid_argument);
216 static int toInt(const std::string&, bool* isOk = 0 ) throw (std::invalid_argument);
217 static std::string toLowerStr(const std::string& str);
221 static std::string defaultWorkingDirectory();
222 static std::string defaultLogFile();
223 static bool defaultKeepFiles();
224 static bool defaultRemoveLogOnSuccess();
225 static int defaultVerboseLevel();
226 static bool defaultPrintLogInFile();
227 static bool defaultFromMedFile();
228 static bool defaultMeshOutMed();
229 static bool defaultPublish();
230 static bool defaultUseLocalMap();
231 static bool defaultUseBackgroundMap();
232 static bool defaultUseConstantValue();
233 static bool defaultUseNoTimeStep();
234 static bool defaultUseLastTimeStep();
235 static bool defaultUseChosenTimeStep();
236 static double defaultMaximumMemory();
243 DRS_EMPTY, // a file contains no mesh with the given name
244 DRS_WARN_RENUMBER, // a file has overlapped ranges of element numbers,
245 // so the numbers from the file are ignored
246 DRS_WARN_SKIP_ELEM, // some elements were skipped due to incorrect file data
247 DRS_WARN_DESCENDING, // some elements were skipped due to descending connectivity
248 DRS_FAIL, // general failure (exception etc.)
249 DRS_NO_TIME_STEP // general failure (exception etc.)
255 std::vector<MEDCoupling::mcIdType> _famListId;
256 std::vector<std::string> _famNames;
257 group(std::string name, std::vector<MEDCoupling::mcIdType> famListId, std::vector<std::string> famNames):_name(name)
259 std::vector<MEDCoupling::mcIdType>::iterator it = famListId.begin();
260 for (; it!=famListId.end(); ++it)
261 _famListId.push_back(*it);
263 std::vector<std::string>::iterator itt = famNames.begin();
264 for (; itt!=famNames.end(); ++itt)
265 _famNames.push_back(*itt);
270 std::string _famName;
272 family(std::string famName, MEDCoupling::mcIdType famId):_famName(famName), _famId(famId) {}
279 std::string medFileIn;
280 std::string medFileOut;
281 std::string meshName;
282 std::string meshNameOut;
283 bool publish, meshOutMed;
284 bool useLocalMap, useBackgroundMap, useConstantValue;
285 std::string sizeMapFile;
286 std::string fieldName;
287 double constantValue;
290 /* advanced options */
294 std::string workingDir;
296 bool removeOnSuccess;
297 bool toKeepWorkingFiles;
301 MgAdaptHypothesisData* data;
305 TOptionValues _option2value, _customOption2value; // user defined values
306 TOptionValues _defaultOptionValues; // default values
307 TOptionNames _doubleOptions, _charOptions, _boolOptions; // to find a type of option
309 std::vector <std::string> _myErrorMessages;
311 std::string meshFormatOutputMesh;
312 std::vector< std::string> solFormatOutput;
313 std::vector <group> groupVec;
314 std::vector <family> famVec;
315 std::vector< std::string> tmpFilesToBeDeleted;
317 /* convert MED-->.mesh format */
318 void convertMedFile(std::string& meshIn,std::string& solFileIn, std::string& sizeMapIn) ;
319 void storeGroups(MEDCoupling::MEDFileMesh* fileMesh);
320 void restoreGroups(MEDCoupling::MEDFileMesh* fileMesh) const;
321 void storefams(MEDCoupling::MEDFileMesh* fileMesh);
322 void restorefams(MEDCoupling::MEDFileMesh* fileMesh) const;
323 void storeGroupsAndFams(MEDCoupling::MEDFileMesh* fileMesh);
324 void restoreGroupsAndFams(MEDCoupling::MEDFileMesh* fileMesh) const;
325 void convertMeshFile(std::string& meshFormatIn, std::vector< std::string>& solFieldFileNames) const ;
326 void buildConstantSizeMapSolFile(const std::string& solFormatFieldFileName, const int dim, const int version, const mcIdType nbNodes) const;
327 void buildBackGroundMeshAndSolFiles(const std::vector<std::string>& fieldFileNames, const std::string& meshFormatsizeMapFile) const;
328 void getTimeStepInfos(std::string aFile, med_int& numdt, med_int& numit);
329 Status addMessage(const std::string& msg, const bool isFatal = false);
330 med_idt openMedFile(const std::string aFile) ;
331 bool isFileExist(std::string& fName) const;
332 void execCmd( const char* cmd, int& err);
334 void appendMsgToLogFile(std::string& msg);
339 #endif // MG_ADAPT_HXX