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/
19 // File : MG_ADAPT.hxx
32 #include "MEDFileMesh.hxx"
38 std::string remove_extension(const std::string& filename);
42 typedef std::map< std::string, std::string > TOptionValues;
43 typedef std::set< std::string > TOptionNames;
45 struct MgAdaptHypothesisData
47 std::string myFileInDir, myMeshFileIn, myInMeshName, myMeshFileBackground, myOutMeshName,
48 myMeshFileOut, myFileOutDir, myFileSizeMapDir, myFieldName;
50 bool myPublish, myMeshOutMed;
51 bool myUseLocalMap, myUseBackgroundMap, myUseConstantValue;
52 double myConstantValue;
53 int myRank, myTimeStep;
54 bool myUseNoTimeStep, myUseLastTimeStep, myUseChosenTimeStep;
55 std::string myWorkingDir, myLogFile;
56 bool myPrintLogInFile, myKeepFiles, myRemoveLogOnSuccess;
61 class outFileStream : public std::ofstream{
63 ~outFileStream(){close();} //to close file at dtor
67 * \brief Class to generate string from any type
69 class ToComment : public std::string
71 std::ostringstream _s ;
75 ToComment():std::string("") {}
77 ToComment(const ToComment& c):std::string() {
79 this->std::string::operator=( _s.str() );
82 ToComment & operator=(const ToComment& c) {
84 this->std::string::operator=( _s.str() );
89 ToComment( const T &anything ) {
91 this->std::string::operator=( _s.str() );
95 ToComment & operator<<( const T &anything ) {
97 this->std::string::operator=( _s.str() );
101 operator char*() const {
102 return (char*)c_str();
105 std::ostream& Stream() {
117 MgAdapt(MgAdaptHypothesisData*);
118 MgAdapt(const MgAdapt&);
121 void setData( MgAdaptHypothesisData* data);
123 void setMedFileIn(std::string fileName);
124 std::string getMedFileIn();
126 void setMedFileOut(std::string fileOut);
127 std::string getMedFileOut();
129 void setMeshName(std::string name);
130 std::string getMeshName();
132 void setMeshNameOut(std::string name);
133 std::string getMeshNameOut();
135 void setMeshOutMed(bool mybool);
136 bool getMeshOutMed();
138 void setPublish(bool mybool);
141 void setFieldName(std::string myFieldName);
142 std::string getFieldName();
144 void setTimeStep(int time);
145 int getTimeStep() const;
147 void setRankTimeStep(int time, int myRank);
150 void setTimeStepRankLast();
151 void setNoTimeStep();
152 void setChosenTimeStepRank();
153 void updateTimeStepRank();
155 void setLogFile(std::string);
156 std::string getLogFile();
158 void setVerbosityLevel(int verbosity);
159 int getVerbosityLevel();
161 void setRemoveOnSuccess(bool mybool);
162 bool getRemoveOnSuccess();
164 MgAdaptHypothesisData* getData() const;
166 void setUseLocalMap(bool mybool);
167 bool getUseLocalMap();
169 void setUseBackgroundMap(bool mybool);
170 bool getUseBackgroundMap();
172 void setUseConstantValue(bool mybool);
173 bool getUseConstantValue();
175 void setConstantValue(double cnst);
176 double getConstantValue() const;
178 void setSizeMapFile(std::string mapFile);
179 std::string getSizeMapFile();
181 void setFromMedFile(bool mybool);
182 bool isFromMedFile();
184 void setKeepWorkingFiles(bool mybool);
185 bool getKeepWorkingFiles();
187 void setPrintLogInFile(bool mybool);
188 bool getPrintLogInFile();
190 void setWorkingDir(std::string dir);
191 std::string getWorkingDir() const;
195 static std::string getCommandToRun(MgAdapt* );
196 std::string getCommandToRun() ;
197 int compute(std::string& errStr);
198 std::string getFileName() const;
199 static std::string getExeName();
200 void copyMgAdaptHypothesisData( const MgAdaptHypothesisData* from) ;
202 void checkDirPath(std::string& dirPath);
204 bool hasOptionDefined( const std::string& optionName ) const;
205 void setOptionValue(const std::string& optionName,
206 const std::string& optionValue) throw (std::invalid_argument);
207 std::string getOptionValue(const std::string& optionName,
208 bool* isDefault=0) const throw (std::invalid_argument);
209 std::vector <std::string> getCustomOptionValuesStrVec() const;
210 std::vector <std::string> getOptionValuesStrVec() const;
213 TOptionValues getOptionValues() const;
214 const TOptionValues& getCustomOptionValues() const ;
215 static double toDbl(const std::string&, bool* isOk = 0) throw (std::invalid_argument);
216 static bool toBool(const std::string&, bool* isOk = 0) throw (std::invalid_argument);
217 static int toInt(const std::string&, bool* isOk = 0 ) throw (std::invalid_argument);
218 static std::string toLowerStr(const std::string& str);
222 static std::string defaultWorkingDirectory();
223 static std::string defaultLogFile();
224 static bool defaultKeepFiles();
225 static bool defaultRemoveLogOnSuccess();
226 static int defaultVerboseLevel();
227 static bool defaultPrintLogInFile();
228 static bool defaultFromMedFile();
229 static bool defaultMeshOutMed();
230 static bool defaultPublish();
231 static bool defaultUseLocalMap();
232 static bool defaultUseBackgroundMap();
233 static bool defaultUseConstantValue();
234 static bool defaultUseNoTimeStep();
235 static bool defaultUseLastTimeStep();
236 static bool defaultUseChosenTimeStep();
237 static double defaultMaximumMemory();
238 static bool isFileExist(const std::string& fName);
245 DRS_EMPTY, // a file contains no mesh with the given name
246 DRS_WARN_RENUMBER, // a file has overlapped ranges of element numbers,
247 // so the numbers from the file are ignored
248 DRS_WARN_SKIP_ELEM, // some elements were skipped due to incorrect file data
249 DRS_WARN_DESCENDING, // some elements were skipped due to descending connectivity
250 DRS_FAIL, // general failure (exception etc.)
251 DRS_NO_TIME_STEP // general failure (exception etc.)
257 std::vector<MEDCoupling::mcIdType> _famListId;
258 std::vector<std::string> _famNames;
259 group(std::string name, std::vector<MEDCoupling::mcIdType> famListId, std::vector<std::string> famNames):_name(name)
261 std::vector<MEDCoupling::mcIdType>::iterator it = famListId.begin();
262 for (; it!=famListId.end(); ++it)
263 _famListId.push_back(*it);
265 std::vector<std::string>::iterator itt = famNames.begin();
266 for (; itt!=famNames.end(); ++itt)
267 _famNames.push_back(*itt);
272 std::string _famName;
274 family(std::string famName, MEDCoupling::mcIdType famId):_famName(famName), _famId(famId) {}
281 std::string medFileIn;
282 std::string medFileOut;
283 std::string meshName;
284 std::string meshNameOut;
285 bool publish, meshOutMed;
286 bool useLocalMap, useBackgroundMap, useConstantValue;
287 bool myUseLastTimeStep, myUseNoTimeStep, myUseChosenTimeStep;
288 std::string sizeMapFile;
289 std::string fieldName;
290 double constantValue;
293 /* advanced options */
297 std::string workingDir;
299 bool removeOnSuccess;
300 bool toKeepWorkingFiles;
304 MgAdaptHypothesisData* data;
308 TOptionValues _option2value, _customOption2value; // user defined values
309 TOptionValues _defaultOptionValues; // default values
310 TOptionNames _doubleOptions, _charOptions, _boolOptions; // to find a type of option
312 std::vector <std::string> _myErrorMessages;
314 std::string meshFormatOutputMesh;
315 std::vector< std::string> solFormatOutput;
316 std::vector <group> groupVec;
317 std::vector <family> famVec;
318 std::vector< std::string> tmpFilesToBeDeleted;
320 /* convert MED-->.mesh format */
321 void convertMedFile(std::string& meshIn,std::string& solFileIn, std::string& sizeMapIn) ;
322 void storeGroups(MEDCoupling::MEDFileMesh* fileMesh);
323 void restoreGroups(MEDCoupling::MEDFileMesh* fileMesh) const;
324 void storefams(MEDCoupling::MEDFileMesh* fileMesh);
325 void restorefams(MEDCoupling::MEDFileMesh* fileMesh) const;
326 void storeGroupsAndFams(MEDCoupling::MEDFileMesh* fileMesh);
327 void restoreGroupsAndFams(MEDCoupling::MEDFileMesh* fileMesh) const;
328 void convertMeshFile(std::string& meshFormatIn, std::vector< std::string>& solFieldFileNames) const ;
329 void buildConstantSizeMapSolFile(const std::string& solFormatFieldFileName, const int dim, const int version, const mcIdType nbNodes) const;
330 void buildBackGroundMeshAndSolFiles(const std::vector<std::string>& fieldFileNames, const std::string& meshFormatsizeMapFile) const;
331 void getTimeStepInfos(std::string aFile, med_int& numdt, med_int& numit);
332 Status addMessage(const std::string& msg, const bool isFatal = false);
333 med_idt openMedFile(const std::string aFile) ;
334 void execCmd( const char* cmd, int& err);
336 void appendMsgToLogFile(std::string& msg);
341 #endif // MG_ADAPT_HXX