Version: 9.12.0
MG_ADAPT.hxx
Go to the documentation of this file.
1 // Copyright (C) 2020-2023 CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef MG_ADAPT_HXX
21 #define MG_ADAPT_HXX
22 
23 #include <string>
24 #include <map>
25 #include <vector>
26 #include <set>
27 
28 #include "SMESH_SMESH.hxx"
29 
30 namespace MEDCoupling
31 {
32  class MEDFileMesh;
33 }
34 
35 namespace MG_ADAPT
36 {
37 typedef std::map< std::string, std::string > TOptionValues;
38 typedef std::set< std::string > TOptionNames;
39 
40 std::string remove_extension(const std::string& filename);
41 
43 {
52  std::string myWorkingDir, myLogFile;
55 };
56 
57 
59 {
60 
61 public:
62 
63  MgAdapt();
65  MgAdapt(const MgAdapt&);
66  ~MgAdapt();
67  void buildModel();
68  void setData( MgAdaptHypothesisData* data);
69 
70  void setMedFileIn(std::string fileName);
71  std::string getMedFileIn();
72 
73  void setMedFileOut(std::string fileOut);
74  std::string getMedFileOut();
75 
76  void setMeshName(std::string name);
77  std::string getMeshName();
78 
79  void setMeshNameOut(std::string name);
80  std::string getMeshNameOut();
81 
82  void setMeshOutMed(bool mybool);
83  bool getMeshOutMed();
84 
85  void setPublish(bool mybool);
86  bool getPublish();
87 
88  void setFieldName(std::string myFieldName);
89  std::string getFieldName();
90 
91  void setTimeStep(int time);
92  int getTimeStep() const;
93 
94  void setRankTimeStep(int time, int myRank);
95  int getRank();
96 
97  void setTimeStepRankLast();
98  void setNoTimeStep();
99  void setChosenTimeStepRank();
100  void updateTimeStepRank();
101 
102  void setLogFile(std::string);
103  std::string getLogFile();
104 
105  void setVerbosityLevel(int verbosity);
106  int getVerbosityLevel();
107 
108  void setRemoveOnSuccess(bool mybool);
109  bool getRemoveOnSuccess();
110 
111  MgAdaptHypothesisData* getData() const;
112 
113  void setUseLocalMap(bool mybool);
114  bool getUseLocalMap();
115 
116  void setUseBackgroundMap(bool mybool);
117  bool getUseBackgroundMap();
118 
119  void setUseConstantValue(bool mybool);
120  bool getUseConstantValue();
121 
122  void setConstantValue(double cnst);
123  double getConstantValue() const;
124 
125  void setSizeMapFile(std::string mapFile);
126  std::string getSizeMapFile();
127 
128  void setFromMedFile(bool mybool);
129  bool isFromMedFile();
130 
131  void setKeepWorkingFiles(bool mybool);
132  bool getKeepWorkingFiles();
133 
134  void setPrintLogInFile(bool mybool);
135  bool getPrintLogInFile();
136 
137  void setWorkingDir(std::string dir);
138  std::string getWorkingDir() const;
139 
140 
141  bool setAll();
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) ;
148 
149  void checkDirPath(std::string& dirPath);
150 
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;
158 
159 
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);
166 
167  /* default values */
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();
184 
185  enum Status {
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.)
194  };
195 
196  struct group
197  {
198  std::string _name;
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 ) {}
203  };
204 
205  struct family
206  {
207  std::string _famName;
208  int _famId;
209  family(std::string famName, int famId):_famName(famName), _famId(famId) {}
210  };
211 
212 
213 private :
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;
225  int rank, timeStep;
226 
227  /* advanced options */
228 
229 
230  std::string logFile;
231  std::string workingDir;
236 
237  /* Model DATA */
239 
240  /* */
241 
242  TOptionValues _option2value, _customOption2value; // user defined values
244  TOptionNames _doubleOptions, _charOptions, _boolOptions; // to find a type of option
245 
246  std::vector <std::string> _errorMessages;
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;
253 
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);
267  void cleanUp();
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) ;
273 
274 };
275 
276 } // namespace MG_ADAPT
277 
278 #endif // MG_ADAPT_HXX
std::string getMeshName(std::string mesh_file)
Definition: SMESH_DriverMesh.cxx:57
#define SMESH_EXPORT
Definition: SMESH_SMESH.hxx:37
Definition: MG_ADAPT.hxx:59
bool removeOnSuccess
Definition: MG_ADAPT.hxx:233
bool meshOutMed
Definition: MG_ADAPT.hxx:219
std::vector< std::string > solFormatOutput
Definition: MG_ADAPT.hxx:249
std::string medFileOut
Definition: MG_ADAPT.hxx:216
std::string medFileIn
Definition: MG_ADAPT.hxx:215
int verbosityLevel
Definition: MG_ADAPT.hxx:232
bool fromMedFile
Definition: MG_ADAPT.hxx:214
std::string meshNameOut
Definition: MG_ADAPT.hxx:218
std::string logFile
Definition: MG_ADAPT.hxx:230
std::string meshName
Definition: MG_ADAPT.hxx:217
std::vector< family > famVec
Definition: MG_ADAPT.hxx:251
MgAdaptHypothesisData * data
Definition: MG_ADAPT.hxx:238
std::string fieldName
Definition: MG_ADAPT.hxx:223
double constantValue
Definition: MG_ADAPT.hxx:224
TOptionValues _customOption2value
Definition: MG_ADAPT.hxx:242
TOptionValues _defaultOptionValues
Definition: MG_ADAPT.hxx:243
Status _status
Definition: MG_ADAPT.hxx:247
std::string meshFormatOutputMesh
Definition: MG_ADAPT.hxx:248
bool myUseChosenTimeStep
Definition: MG_ADAPT.hxx:221
std::vector< group > groupVec
Definition: MG_ADAPT.hxx:250
bool printLogInFile
Definition: MG_ADAPT.hxx:235
std::vector< std::string > _errorMessages
Definition: MG_ADAPT.hxx:246
TOptionNames _boolOptions
Definition: MG_ADAPT.hxx:244
Status
Definition: MG_ADAPT.hxx:185
@ DRS_FAIL
Definition: MG_ADAPT.hxx:192
@ DRS_WARN_DESCENDING
Definition: MG_ADAPT.hxx:191
@ DRS_OK
Definition: MG_ADAPT.hxx:186
@ DRS_WARN_RENUMBER
Definition: MG_ADAPT.hxx:188
@ DRS_EMPTY
Definition: MG_ADAPT.hxx:187
@ DRS_WARN_SKIP_ELEM
Definition: MG_ADAPT.hxx:190
int rank
Definition: MG_ADAPT.hxx:225
bool toKeepWorkingFiles
Definition: MG_ADAPT.hxx:234
std::string sizeMapFile
Definition: MG_ADAPT.hxx:222
std::string workingDir
Definition: MG_ADAPT.hxx:231
bool useBackgroundMap
Definition: MG_ADAPT.hxx:220
std::vector< std::string > tmpFilesToBeDeleted
Definition: MG_ADAPT.hxx:252
Definition: MG_ADAPT.hxx:31
Definition: MG_ADAPT.hxx:36
std::set< std::string > TOptionNames
Definition: MG_ADAPT.hxx:38
std::string remove_extension(const std::string &filename)
Definition: MG_ADAPT.cxx:60
std::map< std::string, std::string > TOptionValues
Definition: MG_ADAPT.hxx:37
static bool toBool(const LDOMString &theStr)
Definition: SMESH_Filter_i.cxx:3500
Definition: MG_ADAPT.hxx:43
std::string myMeshFileOut
Definition: MG_ADAPT.hxx:45
bool myUseNoTimeStep
Definition: MG_ADAPT.hxx:51
bool myMeshOutMed
Definition: MG_ADAPT.hxx:47
std::string myMeshFileIn
Definition: MG_ADAPT.hxx:44
bool myRemoveLogOnSuccess
Definition: MG_ADAPT.hxx:53
double myConstantValue
Definition: MG_ADAPT.hxx:49
bool myPrintLogInFile
Definition: MG_ADAPT.hxx:53
int myVerboseLevel
Definition: MG_ADAPT.hxx:54
std::string myFileSizeMapDir
Definition: MG_ADAPT.hxx:45
bool myPublish
Definition: MG_ADAPT.hxx:47
bool myUseLocalMap
Definition: MG_ADAPT.hxx:48
bool myKeepFiles
Definition: MG_ADAPT.hxx:53
std::string myFileOutDir
Definition: MG_ADAPT.hxx:45
std::string myFileInDir
Definition: MG_ADAPT.hxx:44
std::string myLogFile
Definition: MG_ADAPT.hxx:52
std::string myOutMeshName
Definition: MG_ADAPT.hxx:44
bool fromMedFile
Definition: MG_ADAPT.hxx:46
std::string myInMeshName
Definition: MG_ADAPT.hxx:44
bool myUseBackgroundMap
Definition: MG_ADAPT.hxx:48
int myTimeStep
Definition: MG_ADAPT.hxx:50
bool myUseConstantValue
Definition: MG_ADAPT.hxx:48
bool myUseLastTimeStep
Definition: MG_ADAPT.hxx:51
std::string myFieldName
Definition: MG_ADAPT.hxx:45
std::string myMeshFileBackground
Definition: MG_ADAPT.hxx:44
std::string myWorkingDir
Definition: MG_ADAPT.hxx:52
int myRank
Definition: MG_ADAPT.hxx:50
bool myUseChosenTimeStep
Definition: MG_ADAPT.hxx:51
Definition: MG_ADAPT.hxx:206
std::string _famName
Definition: MG_ADAPT.hxx:207
family(std::string famName, int famId)
Definition: MG_ADAPT.hxx:209
int _famId
Definition: MG_ADAPT.hxx:208
Definition: MG_ADAPT.hxx:197
std::string _name
Definition: MG_ADAPT.hxx:198
std::vector< std::string > _famNames
Definition: MG_ADAPT.hxx:200
std::vector< int > _famListId
Definition: MG_ADAPT.hxx:199
group(std::string name, std::vector< int > famListId, std::vector< std::string > famNames)
Definition: MG_ADAPT.hxx:201