1 // Copyright (C) 2007-2022 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
19 // Author : Anthony Geay (CEA/DEN)
21 #ifndef __MEDFILEMESHLL_HXX__
22 #define __MEDFILEMESHLL_HXX__
24 #include "MEDFileBasis.hxx"
25 #include "MEDFileMeshElt.hxx"
27 #include "MEDCouplingUMesh.hxx"
28 #include "MEDCouplingCMesh.hxx"
29 #include "MEDCoupling1GTUMesh.hxx"
30 #include "MEDCouplingPartDefinition.hxx"
31 #include "MEDCouplingCurveLinearMesh.hxx"
34 #include "InterpKernelAutoPtr.hxx"
42 class MEDFileMeshReadSelector;
44 class MeshOrStructMeshCls
47 MeshOrStructMeshCls(int mid):_mid(mid) { }
49 virtual ~MeshOrStructMeshCls() {}
50 int getID() const { return _mid; }
51 virtual std::vector<std::string> getAxisInfoOnMesh(med_idt fid, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& nstep, int& Mdim, MEDFileString& description, MEDFileString& dtunit, MEDFileString& univName) const = 0;
52 virtual double checkMeshTimeStep(med_idt fid, const std::string& mName, int nstep, int dt, int it) const = 0;
57 class MeshCls : public MeshOrStructMeshCls
60 MeshCls(int mid):MeshOrStructMeshCls(mid) { }
61 std::vector<std::string> getAxisInfoOnMesh(med_idt fid, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& nstep, int& Mdim, MEDFileString& description, MEDFileString& dtunit, MEDFileString& univName) const;
62 double checkMeshTimeStep(med_idt fid, const std::string& mName, int nstep, int dt, int it) const;
65 class StructMeshCls : public MeshOrStructMeshCls
68 StructMeshCls(int mid):MeshOrStructMeshCls(mid) { }
69 std::vector<std::string> getAxisInfoOnMesh(med_idt fid, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& nstep, int& Mdim, MEDFileString& description, MEDFileString& dtunit, MEDFileString& univName) const;
70 double checkMeshTimeStep(med_idt fid, const std::string& mName, int nstep, int dt, int it) const;
73 class MEDFileMeshL2 : public RefCountObject
77 std::size_t getHeapMemorySizeWithoutChildren() const;
78 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
79 const char *getName() const { return _name.getReprForWrite(); }
80 const char *getDescription() const { return _description.getReprForWrite(); }
81 const char *getUnivName() const { return _univ_name.getReprForWrite(); }
82 const char *getTimeUnit() const { return _dt_unit.getReprForWrite(); }
83 int getIteration() const { return _iteration; }
84 int getOrder() const { return _order; }
85 double getTime() const { return _time; }
86 MCAuto<PartDefinition> getPartDefOfCoo() const { return _part_coords; }
87 std::vector<std::string> getAxisInfoOnMesh(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& nstep, int& Mdim);
88 static INTERP_KERNEL::AutoCppPtr<MeshOrStructMeshCls> GetMeshIdFromName(med_idt fid, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& dt, int& it, std::string& dtunit1);
89 static void ReadFamiliesAndGrps(med_idt fid, const std::string& mname, std::map<std::string,mcIdType>& fams, std::map<std::string, std::vector<std::string> >& grps, MEDFileMeshReadSelector *mrs);
90 static void WriteFamiliesAndGrps(med_idt fid, const std::string& mname, const std::map<std::string,mcIdType>& fams, const std::map<std::string, std::vector<std::string> >& grps, int tooLongStrPol);
91 static bool RenameFamiliesFromFileToMem(std::vector< std::string >& famNames);
92 static bool RenameFamiliesFromMemToFile(std::vector< std::string >& famNames);
93 static MEDCoupling::MEDCouplingAxisType TraduceAxisType(med_axis_type at);
94 static MEDCoupling::MEDCouplingAxisType TraduceAxisTypeStruct(med_grid_type gt);
95 static med_axis_type TraduceAxisTypeRev(MEDCoupling::MEDCouplingAxisType at);
96 static med_grid_type TraduceAxisTypeRevStruct(MEDCoupling::MEDCouplingAxisType at);
98 typedef bool (*RenameFamiliesPatternFunc)(std::vector< std::string >&);
99 static void RenameFamiliesPatternInternal(std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > >& crudeFams, RenameFamiliesPatternFunc func);
100 static void RenameFamiliesFromFileToMemInternal(std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > >& crudeFams);
101 static void RenameFamiliesFromMemToFileInternal(std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > >& crudeFams);
103 static const char ZE_SEP_FOR_FAMILY_KILLERS[];
104 static int ZE_SEP2_FOR_FAMILY_KILLERS;
107 MEDFileString _description;
108 MEDFileString _univ_name;
109 MEDFileString _dt_unit;
113 MCAuto<PartDefinition> _part_coords;
116 class MEDFileUMeshL2 : public MEDFileMeshL2
120 std::string getClassName() const override { return std::string("MEDFileUMeshL2"); }
121 std::vector<std::string> loadCommonPart(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it, int& Mdim);
122 void loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs);
123 void loadPart(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<mcIdType>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs);
124 void dealWithCoordsInLoadPart(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, const std::vector<std::string>& infosOnComp, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<mcIdType>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs);
125 std::vector<std::string> loadPartConnectivityOnly(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<mcIdType>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs, int& Mdim);
126 void loadConnectivity(med_idt fid, int mdim, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs);
127 void loadPartOfConnectivity(med_idt fid, int mdim, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<mcIdType>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs);
128 void loadCoords(med_idt fid, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it);
129 void loadPartCoords(med_idt fid, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it, mcIdType nMin, mcIdType nMax);
130 void loadPartCoordsSlice(med_idt fid, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it, const DataArrayIdType *nodeIds, mcIdType nbOfCoordLS);
131 int getNumberOfLevels() const { return (int)_per_type_mesh.size(); }
132 bool emptyLev(int levId) const { return _per_type_mesh[levId].empty(); }
133 const std::vector< MCAuto<MEDFileUMeshPerType> >& getLev(int levId) const { return _per_type_mesh[levId]; }
134 bool isFamDefinedOnLev(int levId) const;
135 bool isNumDefinedOnLev(int levId) const;
136 bool isNamesDefinedOnLev(int levId) const;
137 MCAuto<DataArrayDouble> getCoords() const { return _coords; }
138 MCAuto<DataArrayIdType> getCoordsFamily() const { return _fam_coords; }
139 MCAuto<DataArrayIdType> getCoordsNum() const { return _num_coords; }
140 MCAuto<DataArrayIdType> getCoordsGlobalNum() const { return _global_num_coords; }
141 MCAuto<DataArrayAsciiChar> getCoordsName() const { return _name_coords; }
142 static void WriteCoords(med_idt fid, const std::string& mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayIdType *famCoords, const DataArrayIdType *numCoords, const DataArrayAsciiChar *nameCoords, const DataArrayIdType *globalNumCoords);
143 static void LoadPartCoords(med_idt fid, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it, mcIdType nMin, mcIdType nMax,
144 MCAuto<DataArrayDouble>& _coords, MCAuto<PartDefinition>& _part_coords, MCAuto<DataArrayIdType>& _fam_coords, MCAuto<DataArrayIdType>& _num_coords, MCAuto<DataArrayAsciiChar>& _name_coords);
145 static void LoadPartCoordsArray(med_idt fid, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it, const DataArrayIdType *nodeIds,
146 MCAuto<DataArrayDouble>& _coords, MCAuto<DataArrayIdType>& _fam_coords, MCAuto<DataArrayIdType>& _num_coords, MCAuto<DataArrayAsciiChar>& _name_coords);
150 std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > > _per_type_mesh;
151 MCAuto<DataArrayDouble> _coords;
152 MCAuto<DataArrayIdType> _fam_coords;
153 MCAuto<DataArrayIdType> _num_coords;
154 MCAuto<DataArrayIdType> _global_num_coords;
155 MCAuto<DataArrayAsciiChar> _name_coords;
158 class MEDFileStrMeshL2 : public MEDFileMeshL2
162 class MEDFileCMeshL2 : public MEDFileStrMeshL2
166 std::string getClassName() const override { return std::string("MEDFileCMeshL2"); }
167 void loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it);
168 MEDCouplingCMesh *getMesh() { return _cmesh; }
169 MEDCoupling::MEDCouplingAxisType getAxisType() const { return _ax_type; }
171 static med_data_type GetDataTypeCorrespondingToSpaceId(int id);
173 MCAuto<MEDCouplingCMesh> _cmesh;
174 MEDCoupling::MEDCouplingAxisType _ax_type;
177 class MEDFileCLMeshL2 : public MEDFileStrMeshL2
181 std::string getClassName() const override { return std::string("MEDFileCLMeshL2"); }
182 void loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it);
183 MEDCouplingCurveLinearMesh *getMesh() { return _clmesh; }
185 MCAuto<MEDCouplingCurveLinearMesh> _clmesh;
189 class MEDFileUMeshSplitL1;
191 class MEDFileUMeshPermCompute : public BigMemoryObject
194 MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st);
195 std::string getClassName() const override { return std::string("MEDFileUMeshPermCompute"); }
196 operator MEDCouplingUMesh *() const;
197 void operator=(MEDCouplingUMesh *m);
198 void updateTime() const;
199 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
200 std::size_t getHeapMemorySizeWithoutChildren() const;
202 const MEDFileUMeshSplitL1 *_st;
203 mutable std::size_t _mpt_time;
204 mutable std::size_t _num_time;
205 mutable MCAuto<MEDCouplingUMesh> _m;
208 class MEDFileUMeshAggregateCompute : public BigMemoryObject
211 MEDFileUMeshAggregateCompute();
212 std::string getClassName() const override { return std::string("MEDFileUMeshAggregateCompute"); }
213 void setName(const std::string& name);
214 void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts);
215 void assignDefParts(const std::vector<const PartDefinition *>& partDefs);
216 void assignUMesh(MEDCouplingUMesh *m);
217 MEDCouplingUMesh *getUmesh() const;
218 mcIdType getNumberOfCells() const;
219 void highlightUsedNodes(std::vector<bool>& nodesToBeHighlighted) const;
220 std::vector<MEDCoupling1GTUMesh *> getParts() const;
221 std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes() const;
222 mcIdType getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const;
223 std::vector<MEDCoupling1GTUMesh *> retrievePartsWithoutComputation() const;
224 MEDCoupling1GTUMesh *retrievePartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const;
225 void getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, mcIdType& start, mcIdType& stop) const;
226 void renumberNodesInConnWithoutComputation(const mcIdType *newNodeNumbersO2N);
227 bool isStoredSplitByType() const;
228 std::size_t getTimeOfThis() const;
229 std::size_t getHeapMemorySizeWithoutChildren() const;
230 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
231 MEDFileUMeshAggregateCompute deepCopy(DataArrayDouble *coords) const;
232 void shallowCpyMeshes();
233 bool isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const;
234 void checkConsistency() const;
235 void clearNonDiscrAttributes() const;
236 void synchronizeTinyInfo(const MEDFileMesh& master) const;
238 int getMeshDimension() const;
239 std::vector<mcIdType> getDistributionOfTypes() const;
240 mcIdType getSize() const;
241 void setCoords(DataArrayDouble *coords);
242 void forceComputationOfPartsFromUMesh() const;
243 const PartDefinition *getPartDefOfWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const;
244 void serialize(std::vector<mcIdType>& tinyInt, std::vector< MCAuto<DataArrayIdType> >& bigArraysI) const;
245 void unserialize(const std::string& name, DataArrayDouble *coo, std::vector<mcIdType>& tinyInt, std::vector< MCAuto<DataArrayIdType> >& bigArraysI);
247 std::size_t getTimeOfParts() const;
248 std::size_t getTimeOfUMesh() const;
250 mutable std::vector< MCAuto<MEDCoupling1GTUMesh> > _m_parts;
251 mutable std::size_t _mp_time;
252 mutable std::size_t _m_time;
253 mutable MCAuto<MEDCouplingUMesh> _m;
254 mutable std::vector< MCAuto<PartDefinition> > _part_def;
257 class MEDFileUMeshSplitL1 : public RefCountObject
259 friend class MEDFileUMeshPermCompute;
260 friend class MEDFileUMesh;
262 MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other);
263 MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::string& mName, int id);
264 MEDFileUMeshSplitL1(MEDCoupling1GTUMesh *m);
265 MEDFileUMeshSplitL1(MEDCouplingUMesh *m);
266 MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld);
267 std::string getClassName() const override { return std::string("MEDFileUMeshSplitL1"); }
268 void setName(const std::string& name);
269 std::size_t getHeapMemorySizeWithoutChildren() const;
270 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
271 MEDFileUMeshSplitL1 *shallowCpyUsingCoords(DataArrayDouble *coords) const;
272 MEDFileUMeshSplitL1 *deepCopy(DataArrayDouble *coords) const;
273 void checkConsistency() const;
274 void setCoords(DataArrayDouble *coords);
275 bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const;
276 void clearNonDiscrAttributes() const;
277 void synchronizeTinyInfo(const MEDFileMesh& master) const;
278 void assignMesh(MEDCouplingUMesh *m, bool newOrOld);
279 void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts);
280 void forceComputationOfParts() const;
282 bool presenceOfOneFams(const std::vector<mcIdType>& ids) const;
283 int getMeshDimension() const;
284 void simpleRepr(std::ostream& oss) const;
285 mcIdType getSize() const;
286 MEDCouplingUMesh *getFamilyPart(const mcIdType *idsBg, const mcIdType *idsEnd, bool renum) const;
287 DataArrayIdType *getFamilyPartArr(const mcIdType *idsBg, const mcIdType *idsEnd, bool renum) const;
288 MEDCouplingUMesh *getWholeMesh(bool renum) const;
289 mcIdType getNumberOfCells() const;
290 bool isMeshStoredSplitByType() const { return _m_by_types.isStoredSplitByType(); }
291 std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes() const;
292 mcIdType getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const;
293 std::vector<MEDCoupling1GTUMesh *> getDirectUndergroundSingleGeoTypeMeshes() const { return _m_by_types.retrievePartsWithoutComputation(); }
294 MEDCoupling1GTUMesh *getDirectUndergroundSingleGeoTypeMesh(INTERP_KERNEL::NormalizedCellType gt) const { return _m_by_types.retrievePartWithoutComputation(gt); }
295 DataArrayIdType *extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const;
296 DataArrayIdType *extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const;
297 std::vector<mcIdType> getDistributionOfTypes() const { return _m_by_types.getDistributionOfTypes(); }
298 DataArrayIdType *getOrCreateAndGetFamilyField();
299 const DataArrayIdType *getFamilyField() const;
300 const DataArrayIdType *getNumberField() const;
301 const DataArrayAsciiChar *getNameField() const;
302 const DataArrayIdType *getRevNumberField() const;
303 void highlightUsedNodes(std::vector<bool>& nodesToBeHighlighted) const { _m_by_types.highlightUsedNodes(nodesToBeHighlighted); }
304 const PartDefinition *getPartDef(INTERP_KERNEL::NormalizedCellType gt) const;
305 void eraseFamilyField();
306 void setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,mcIdType>& familyIds,
307 std::map<std::string, std::vector<std::string> >& groups);
308 void checkCoordsConsistency(const DataArrayDouble *coords) const;
309 void write(med_idt fid, const std::string& mName, int mdim) const;
311 void setFamilyArr(DataArrayIdType *famArr);
312 DataArrayIdType *getFamilyField();
313 void setRenumArr(DataArrayIdType *renumArr);
314 void setNameArr(DataArrayAsciiChar *nameArr);
315 void changeFamilyIdArr(mcIdType oldId, mcIdType newId);
317 void renumberNodesInConn(const mcIdType *newNodeNumbersO2N);
319 void serialize(std::vector<mcIdType>& tinyInt, std::vector< MCAuto<DataArrayIdType> >& bigArraysI) const;
320 void unserialize(const std::string& name, DataArrayDouble *coo, std::vector<mcIdType>& tinyInt, std::vector< MCAuto<DataArrayIdType> >& bigArraysI);
322 static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp);
323 static std::vector<mcIdType> GetNewFamiliesNumber(mcIdType nb, const std::map<std::string,mcIdType>& families);
324 static void TraduceFamilyNumber(const std::vector< std::vector<mcIdType> >& fidsGrps, std::map<std::string,mcIdType>& familyIds,
325 std::map<mcIdType,mcIdType>& famIdTrad, std::map<mcIdType,std::string>& newfams);
326 static DataArrayIdType *Renumber(const DataArrayIdType *renum, const DataArrayIdType *da);
327 static MEDCouplingUMesh *Renumber2(const DataArrayIdType *renum, MEDCouplingUMesh *m, const mcIdType *cellIds);
328 static MEDFileUMeshSplitL1 *Unserialize(const std::string& name, DataArrayDouble *coo, std::vector<mcIdType>& tinyInt, std::vector< MCAuto<DataArrayIdType> >& bigArraysI);
330 MEDFileUMeshSplitL1();
331 void assignCommonPart();
332 MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const mcIdType *cellIds) const;
333 DataArrayIdType *renumIfNeededArr(const DataArrayIdType *da) const;
334 void computeRevNum() const;
336 MEDFileUMeshAggregateCompute _m_by_types;
337 MCAuto<DataArrayIdType> _fam;
338 MCAuto<DataArrayIdType> _num;
339 MCAuto<DataArrayIdType> _global_num;
340 MCAuto<DataArrayAsciiChar> _names;
341 mutable MCAuto<DataArrayIdType> _rev_num;
342 MEDFileUMeshPermCompute _m;
345 class MEDFileEltStruct4Mesh : public RefCountObject
348 static MEDFileEltStruct4Mesh *New(med_idt fid, const std::string& mName, int dt, int it, int iterOnStEltOfMesh, MEDFileMeshReadSelector *mrs);
349 std::string getClassName() const override { return std::string("MEDFileEltStruct4Mesh"); }
350 std::string getGeoTypeName() const { return _geo_type_name; }
351 MCAuto<DataArrayIdType> getConn() const { return _conn; }
352 MCAuto<MEDFileUMeshPerTypeCommon> getMeshDef() const { return _common; }
353 const std::vector< MCAuto<DataArray> >& getVars() const { return _vars; }
355 std::size_t getHeapMemorySizeWithoutChildren() const;
356 std::vector<const MEDCoupling::BigMemoryObject*> getDirectChildrenWithNull() const;
358 ~MEDFileEltStruct4Mesh() { }
360 MEDFileEltStruct4Mesh(med_idt fid, const std::string& mName, int dt, int it, int iterOnStEltOfMesh, MEDFileMeshReadSelector *mrs);
362 std::string _geo_type_name;
364 MCAuto<DataArrayIdType> _conn;
365 MCAuto<MEDFileUMeshPerTypeCommon> _common;
366 std::vector< MCAuto<DataArray> > _vars;