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;
66 * \brief Class to generate string from any type
68 class ToComment : public std::string
70 std::ostringstream _s ;
74 ToComment():std::string("") {}
76 ToComment(const ToComment& c):std::string() {
78 this->std::string::operator=( _s.str() );
81 ToComment & operator=(const ToComment& c) {
83 this->std::string::operator=( _s.str() );
88 ToComment( const T &anything ) {
90 this->std::string::operator=( _s.str() );
94 ToComment & operator<<( const T &anything ) {
96 this->std::string::operator=( _s.str() );
100 operator char*() const {
101 return (char*)c_str();
104 std::ostream& Stream() {
112 enum YesNo {YES, NO};
116 MgAdapt(MgAdaptHypothesisData*);
117 MgAdapt(const MgAdapt&);
120 void setData( MgAdaptHypothesisData*);
122 void setMedFileIn(std::string);
123 std::string getMedFileIn();
125 void setMedFileOut(std::string);
126 std::string getMedFileOut();
128 void setMeshName(std::string);
129 std::string getMeshName();
131 void setMeshNameOut(std::string);
132 std::string getMeshNameOut();
134 void setMeshOutMed(bool);
135 bool getMeshOutMed();
137 void setPublish(bool);
140 void setFieldName(std::string);
141 std::string getFieldName();
143 void setTimeStep(int);
144 int getTimeStep() const;
146 void setRankTimeStep(int, int );
149 void setLogFile(std::string);
150 std::string getLogFile();
152 void setVerbosityLevel(int);
153 int getVerbosityLevel();
155 void setRemoveOnSuccess(bool);
156 bool getRemoveOnSuccess();
158 MgAdaptHypothesisData* getData() const;
160 void setUseLocalMap(bool);
161 bool getUseLocalMap();
163 void setUseBackgroundMap(bool);
164 bool getUseBackgroundMap();
166 void setUseConstantValue(bool);
167 bool getUseConstantValue();
169 void setConstantValue(double);
170 bool getConstantValue();
172 void setSizeMapFile(std::string);
173 std::string getSizeMapFile();
175 void setFromMedFile(bool);
176 bool isFromMedFile();
178 void setKeepWorkingFiles(bool);
179 bool getKeepWorkingFiles();
181 void setPrintLogInFile(bool);
182 bool getPrintLogInFile();
184 void setWorkingDir(std::string);
185 std::string getWorkingDir() const;
189 static std::string getCommandToRun(MgAdapt* );
190 std::string getCommandToRun() ;
191 int compute(std::string& errStr);
192 std::string getFileName() const;
193 static std::string getExeName();
194 void copyMgAdaptHypothesisData( MgAdaptHypothesisData* ) ;
196 void checkDirPath(std::string& );
200 bool hasOptionDefined( const std::string& optionName ) const;
201 void setOptionValue(const std::string& optionName,
202 const std::string& optionValue) throw (std::invalid_argument);
203 std::string getOptionValue(const std::string& optionName,
204 bool* isDefault=0) const throw (std::invalid_argument);
205 std::vector <std::string> getCustomOptionValuesStrVec() const;
206 std::vector <std::string> getOptionValuesStrVec() const;
209 TOptionValues getOptionValues() const;
210 const TOptionValues& getCustomOptionValues() const ;
211 static double toDbl(const std::string&, bool* isOk = 0) throw (std::invalid_argument);
212 static bool toBool(const std::string&, bool* isOk = 0) throw (std::invalid_argument);
213 static int toInt(const std::string&, bool* isOk = 0 ) throw (std::invalid_argument);
217 static std::string defaultWorkingDirectory();
218 static std::string defaultLogFile();
219 static bool defaultKeepFiles();
220 static bool defaultRemoveLogOnSuccess();
221 static int defaultVerboseLevel();
222 static bool defaultPrintLogInFile();
223 static bool defaultFromMedFile();
224 static bool defaultMeshOutMed();
225 static bool defaultPublish();
226 static bool defaultUseLocalMap();
227 static bool defaultUseBackgroundMap();
228 static bool defaultUseConstantValue();
229 static bool defaultUseNoTimeStep();
230 static bool defaultUseLastTimeStep();
231 static bool defaultUseChosenTimeStep();
232 static double defaultMaximumMemory();
239 DRS_EMPTY, // a file contains no mesh with the given name
240 DRS_WARN_RENUMBER, // a file has overlapped ranges of element numbers,
241 // so the numbers from the file are ignored
242 DRS_WARN_SKIP_ELEM, // some elements were skipped due to incorrect file data
243 DRS_WARN_DESCENDING, // some elements were skipped due to descending connectivity
244 DRS_FAIL, // general failure (exception etc.)
245 DRS_NO_TIME_STEP // general failure (exception etc.)
251 std::vector<MEDCoupling::mcIdType> _famListId;
252 std::vector<std::string> _famNames;
253 group(std::string name, std::vector<MEDCoupling::mcIdType> famListId, std::vector<std::string> famNames):_name(name)
255 std::vector<MEDCoupling::mcIdType>::iterator it = famListId.begin();
256 for (; it!=famListId.end(); ++it)
257 _famListId.push_back(*it);
259 std::vector<std::string>::iterator itt = famNames.begin();
260 for (; itt!=famNames.end(); ++itt)
261 _famNames.push_back(*itt);
266 std::string _famName;
268 family(std::string famName, MEDCoupling::mcIdType famId):_famName(famName), _famId(famId) {}
275 std::string medFileIn;
276 std::string medFileOut;
277 std::string meshName;
278 std::string meshNameOut;
279 bool publish, meshOutMed;
280 bool useLocalMap, useBackgroundMap, useConstantValue;
281 std::string sizeMapFile;
282 std::string fieldName;
283 double constantValue;
286 /* advanced options */
290 std::string workingDir;
292 bool removeOnSuccess;
293 bool toKeepWorkingFiles;
297 MgAdaptHypothesisData* data;
301 TOptionValues _option2value, _customOption2value; // user defined values
302 TOptionValues _defaultOptionValues; // default values
303 TOptionNames _doubleOptions, _charOptions, _boolOptions; // to find a type of option
305 std::vector <std::string> _myErrorMessages;
307 std::string meshFormatOutputMesh;
308 std::vector< std::string> solFormatOutput;
309 std::vector <group> groupVec;
310 std::vector <family> famVec;
312 /* convert MED-->.mesh format */
313 void convertMedFile(std::string& meshIn,std::string& solFileIn, std::string& sizeMapIn) ;
314 void storeGroups(MEDCoupling::MEDFileMesh* fileMesh);
315 void restoreGroups(MEDCoupling::MEDFileMesh* fileMesh) const;
316 void storefams(MEDCoupling::MEDFileMesh* fileMesh);
317 void restorefams(MEDCoupling::MEDFileMesh* fileMesh) const;
318 void storeGroupsAndFams(MEDCoupling::MEDFileMesh* fileMesh);
319 void restoreGroupsAndFams(MEDCoupling::MEDFileMesh* fileMesh) const;
320 void convertMeshFile(std::string& meshFormatIn, std::vector< std::string>& solFieldFileNames) const ;
321 void getTimeStepInfos(std::string aFile, int& numdt, int& numit);
322 Status addMessage(const std::string& msg, const bool isFatal = false);
323 med_idt openMedFile(const std::string aFile) ;
324 bool isFileExist(std::string& fName) const;
325 void execCmd( const char* cmd, int& err);
330 #endif // MG_ADAPT_HXX