1 // Copyright (C) 2020-2021 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
28 #include "SMESH_SMESH.hxx"
37 typedef std::map< std::string, std::string > TOptionValues;
38 typedef std::set< std::string > TOptionNames;
40 std::string remove_extension(const std::string& filename);
42 struct MgAdaptHypothesisData
44 std::string myFileInDir, myMeshFileIn, myInMeshName, myMeshFileBackground, myOutMeshName,
45 myMeshFileOut, myFileOutDir, myFileSizeMapDir, myFieldName;
47 bool myPublish, myMeshOutMed;
48 bool myUseLocalMap, myUseBackgroundMap, myUseConstantValue;
49 double myConstantValue;
50 int myRank, myTimeStep;
51 bool myUseNoTimeStep, myUseLastTimeStep, myUseChosenTimeStep;
52 std::string myWorkingDir, myLogFile;
53 bool myPrintLogInFile, myKeepFiles, myRemoveLogOnSuccess;
58 class SMESH_EXPORT MgAdapt
64 MgAdapt(MgAdaptHypothesisData*);
65 MgAdapt(const MgAdapt&);
68 void setData( MgAdaptHypothesisData* data);
70 void setMedFileIn(std::string fileName);
71 std::string getMedFileIn();
73 void setMedFileOut(std::string fileOut);
74 std::string getMedFileOut();
76 void setMeshName(std::string name);
77 std::string getMeshName();
79 void setMeshNameOut(std::string name);
80 std::string getMeshNameOut();
82 void setMeshOutMed(bool mybool);
85 void setPublish(bool mybool);
88 void setFieldName(std::string myFieldName);
89 std::string getFieldName();
91 void setTimeStep(int time);
92 int getTimeStep() const;
94 void setRankTimeStep(int time, int myRank);
97 void setTimeStepRankLast();
99 void setChosenTimeStepRank();
100 void updateTimeStepRank();
102 void setLogFile(std::string);
103 std::string getLogFile();
105 void setVerbosityLevel(int verbosity);
106 int getVerbosityLevel();
108 void setRemoveOnSuccess(bool mybool);
109 bool getRemoveOnSuccess();
111 MgAdaptHypothesisData* getData() const;
113 void setUseLocalMap(bool mybool);
114 bool getUseLocalMap();
116 void setUseBackgroundMap(bool mybool);
117 bool getUseBackgroundMap();
119 void setUseConstantValue(bool mybool);
120 bool getUseConstantValue();
122 void setConstantValue(double cnst);
123 double getConstantValue() const;
125 void setSizeMapFile(std::string mapFile);
126 std::string getSizeMapFile();
128 void setFromMedFile(bool mybool);
129 bool isFromMedFile();
131 void setKeepWorkingFiles(bool mybool);
132 bool getKeepWorkingFiles();
134 void setPrintLogInFile(bool mybool);
135 bool getPrintLogInFile();
137 void setWorkingDir(std::string dir);
138 std::string getWorkingDir() const;
142 static std::string getCommandToRun(MgAdapt* );
143 std::string getCommandToRun() ;
144 int compute(std::string& errStr);
145 std::string getFileName() const;
146 static std::string getExeName();
147 void copyMgAdaptHypothesisData( const MgAdaptHypothesisData* from) ;
149 void checkDirPath(std::string& dirPath);
151 bool hasOptionDefined( const std::string& optionName ) const;
152 void setOptionValue(const std::string& optionName,
153 const std::string& optionValue);
154 std::string getOptionValue(const std::string& optionName,
155 bool* isDefault=0) const;
156 std::vector <std::string> getCustomOptionValuesStrVec() const;
157 std::vector <std::string> getOptionValuesStrVec() const;
160 TOptionValues getOptionValues() const;
161 const TOptionValues& getCustomOptionValues() const ;
162 static double toDbl(const std::string&, bool* isOk = 0);
163 static bool toBool(const std::string&, bool* isOk = 0);
164 static int toInt(const std::string&, bool* isOk = 0 );
165 static std::string toLowerStr(const std::string& str);
168 static std::string defaultWorkingDirectory();
169 static std::string defaultLogFile();
170 static bool defaultKeepFiles();
171 static bool defaultRemoveLogOnSuccess();
172 static int defaultVerboseLevel();
173 static bool defaultPrintLogInFile();
174 static bool defaultFromMedFile();
175 static bool defaultMeshOutMed();
176 static bool defaultPublish();
177 static bool defaultUseLocalMap();
178 static bool defaultUseBackgroundMap();
179 static bool defaultUseConstantValue();
180 static bool defaultUseNoTimeStep();
181 static bool defaultUseLastTimeStep();
182 static bool defaultUseChosenTimeStep();
183 static double defaultMaximumMemory();
187 DRS_EMPTY, // a file contains no mesh with the given name
188 DRS_WARN_RENUMBER, // a file has overlapped ranges of element numbers,
189 // so the numbers from the file are ignored
190 DRS_WARN_SKIP_ELEM, // some elements were skipped due to incorrect file data
191 DRS_WARN_DESCENDING, // some elements were skipped due to descending connectivity
192 DRS_FAIL, // general failure (exception etc.)
193 DRS_NO_TIME_STEP // general failure (exception etc.)
199 std::vector<int> _famListId;
200 std::vector<std::string> _famNames;
201 group(std::string name, std::vector<int> famListId, std::vector<std::string> famNames)
202 :_name(name), _famListId( famListId ), _famNames( famNames ) {}
207 std::string _famName;
209 family(std::string famName, int famId):_famName(famName), _famId(famId) {}
215 std::string medFileIn;
216 std::string medFileOut;
217 std::string meshName;
218 std::string meshNameOut;
219 bool publish, meshOutMed;
220 bool useLocalMap, useBackgroundMap, useConstantValue;
221 bool myUseLastTimeStep, myUseNoTimeStep, myUseChosenTimeStep;
222 std::string sizeMapFile;
223 std::string fieldName;
224 double constantValue;
227 /* advanced options */
231 std::string workingDir;
233 bool removeOnSuccess;
234 bool toKeepWorkingFiles;
238 MgAdaptHypothesisData* data;
242 TOptionValues _option2value, _customOption2value; // user defined values
243 TOptionValues _defaultOptionValues; // default values
244 TOptionNames _doubleOptions, _charOptions, _boolOptions; // to find a type of option
246 std::vector <std::string> _myErrorMessages;
248 std::string meshFormatOutputMesh;
249 std::vector< std::string> solFormatOutput;
250 std::vector <group> groupVec;
251 std::vector <family> famVec;
252 std::vector< std::string> tmpFilesToBeDeleted;
254 /* convert MED-->.mesh format */
255 void convertMedFile(std::string& meshIn,std::string& solFileIn, std::string& sizeMapIn) ;
256 void storeGroups(MEDCoupling::MEDFileMesh* fileMesh);
257 void restoreGroups(MEDCoupling::MEDFileMesh* fileMesh) const;
258 void storefams(MEDCoupling::MEDFileMesh* fileMesh);
259 void restorefams(MEDCoupling::MEDFileMesh* fileMesh) const;
260 void storeGroupsAndFams(MEDCoupling::MEDFileMesh* fileMesh);
261 void restoreGroupsAndFams(MEDCoupling::MEDFileMesh* fileMesh) const;
262 void convertMeshFile(std::string& meshFormatIn, std::vector< std::string>& solFieldFileNames) const ;
263 void buildConstantSizeMapSolFile(const std::string& solFormatFieldFileName, const int dim, const int version, const size_t nbNodes) const;
264 void buildBackGroundMeshAndSolFiles(const std::vector<std::string>& fieldFileNames, const std::string& meshFormatsizeMapFile) const;
265 Status addMessage(const std::string& msg, const bool isFatal = false);
266 void execCmd( const char* cmd, int& err);
268 void appendMsgToLogFile(std::string& msg);
269 std::vector<std::string> getListFieldsNames(std::string fileIn) ;
270 void checkDimensionOptionAdaptation() ;
271 void checkFieldName(std::string fileIn) ;
272 void checkTimeStepRank(std::string fileIn) ;
276 } // namespace MG_ADAPT
278 #endif // MG_ADAPT_HXX