1 // Copyright (C) 2007-2016 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 int getID() const { return _mid; }
50 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;
51 virtual double checkMeshTimeStep(med_idt fid, const std::string& mName, int nstep, int dt, int it) const = 0;
56 class MeshCls : public MeshOrStructMeshCls
59 MeshCls(int mid):MeshOrStructMeshCls(mid) { }
60 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;
61 double checkMeshTimeStep(med_idt fid, const std::string& mName, int nstep, int dt, int it) const;
64 class StructMeshCls : public MeshOrStructMeshCls
67 StructMeshCls(int mid):MeshOrStructMeshCls(mid) { }
68 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;
69 double checkMeshTimeStep(med_idt fid, const std::string& mName, int nstep, int dt, int it) const;
72 class MEDFileMeshL2 : public RefCountObject
76 std::size_t getHeapMemorySizeWithoutChildren() const;
77 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
78 const char *getName() const { return _name.getReprForWrite(); }
79 const char *getDescription() const { return _description.getReprForWrite(); }
80 const char *getUnivName() const { return _univ_name.getReprForWrite(); }
81 const char *getTimeUnit() const { return _dt_unit.getReprForWrite(); }
82 int getIteration() const { return _iteration; }
83 int getOrder() const { return _order; }
84 double getTime() const { return _time; }
85 MCAuto<PartDefinition> getPartDefOfCoo() const { return _part_coords; }
86 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);
87 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);
88 static void ReadFamiliesAndGrps(med_idt fid, const std::string& mname, std::map<std::string,int>& fams, std::map<std::string, std::vector<std::string> >& grps, MEDFileMeshReadSelector *mrs);
89 static void WriteFamiliesAndGrps(med_idt fid, const std::string& mname, const std::map<std::string,int>& fams, const std::map<std::string, std::vector<std::string> >& grps, int tooLongStrPol);
90 static bool RenameFamiliesFromFileToMem(std::vector< std::string >& famNames);
91 static bool RenameFamiliesFromMemToFile(std::vector< std::string >& famNames);
92 static MEDCoupling::MEDCouplingAxisType TraduceAxisType(med_axis_type at);
93 static MEDCoupling::MEDCouplingAxisType TraduceAxisTypeStruct(med_grid_type gt);
94 static med_axis_type TraduceAxisTypeRev(MEDCoupling::MEDCouplingAxisType at);
95 static med_grid_type TraduceAxisTypeRevStruct(MEDCoupling::MEDCouplingAxisType at);
97 typedef bool (*RenameFamiliesPatternFunc)(std::vector< std::string >&);
98 static void RenameFamiliesPatternInternal(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >& crudeFams, RenameFamiliesPatternFunc func);
99 static void RenameFamiliesFromFileToMemInternal(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >& crudeFams);
100 static void RenameFamiliesFromMemToFileInternal(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >& crudeFams);
102 static const char ZE_SEP_FOR_FAMILY_KILLERS[];
103 static int ZE_SEP2_FOR_FAMILY_KILLERS;
106 MEDFileString _description;
107 MEDFileString _univ_name;
108 MEDFileString _dt_unit;
112 MCAuto<PartDefinition> _part_coords;
115 class MEDFileUMeshL2 : public MEDFileMeshL2
119 std::vector<std::string> loadCommonPart(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it, int& Mdim);
120 void loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs);
121 void loadPart(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<int>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs);
122 void loadConnectivity(med_idt fid, int mdim, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs);
123 void loadPartOfConnectivity(med_idt fid, int mdim, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<int>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs);
124 void loadCoords(med_idt fid, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it);
125 void loadPartCoords(med_idt fid, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it, int nMin, int nMax);
126 int getNumberOfLevels() const { return _per_type_mesh.size(); }
127 bool emptyLev(int levId) const { return _per_type_mesh[levId].empty(); }
128 const std::vector< MCAuto<MEDFileUMeshPerType> >& getLev(int levId) const { return _per_type_mesh[levId]; }
129 bool isFamDefinedOnLev(int levId) const;
130 bool isNumDefinedOnLev(int levId) const;
131 bool isNamesDefinedOnLev(int levId) const;
132 MCAuto<DataArrayDouble> getCoords() const { return _coords; }
133 MCAuto<DataArrayInt> getCoordsFamily() const { return _fam_coords; }
134 MCAuto<DataArrayInt> getCoordsNum() const { return _num_coords; }
135 MCAuto<DataArrayAsciiChar> getCoordsName() const { return _name_coords; }
136 static void WriteCoords(med_idt fid, const std::string& mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords, const DataArrayAsciiChar *nameCoords);
140 std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > > _per_type_mesh;
141 MCAuto<DataArrayDouble> _coords;
142 MCAuto<DataArrayInt> _fam_coords;
143 MCAuto<DataArrayInt> _num_coords;
144 MCAuto<DataArrayAsciiChar> _name_coords;
147 class MEDFileStrMeshL2 : public MEDFileMeshL2
151 class MEDFileCMeshL2 : public MEDFileStrMeshL2
155 void loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it);
156 MEDCouplingCMesh *getMesh() { return _cmesh; }
157 MEDCoupling::MEDCouplingAxisType getAxisType() const { return _ax_type; }
159 static med_data_type GetDataTypeCorrespondingToSpaceId(int id);
161 MCAuto<MEDCouplingCMesh> _cmesh;
162 MEDCoupling::MEDCouplingAxisType _ax_type;
165 class MEDFileCLMeshL2 : public MEDFileStrMeshL2
169 void loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it);
170 MEDCouplingCurveLinearMesh *getMesh() { return _clmesh; }
172 MCAuto<MEDCouplingCurveLinearMesh> _clmesh;
176 class MEDFileUMeshSplitL1;
178 class MEDFileUMeshPermCompute : public BigMemoryObject
181 MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st);
182 operator MEDCouplingUMesh *() const;
183 void operator=(MEDCouplingUMesh *m);
184 void updateTime() const;
185 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
186 std::size_t getHeapMemorySizeWithoutChildren() const;
188 const MEDFileUMeshSplitL1 *_st;
189 mutable std::size_t _mpt_time;
190 mutable std::size_t _num_time;
191 mutable MCAuto<MEDCouplingUMesh> _m;
194 class MEDFileUMeshAggregateCompute : public BigMemoryObject
197 MEDFileUMeshAggregateCompute();
198 void setName(const std::string& name);
199 void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts);
200 void assignDefParts(const std::vector<const PartDefinition *>& partDefs);
201 void assignUMesh(MEDCouplingUMesh *m);
202 MEDCouplingUMesh *getUmesh() const;
203 int getNumberOfCells() const;
204 std::vector<MEDCoupling1GTUMesh *> getParts() const;
205 std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes() const;
206 int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const;
207 std::vector<MEDCoupling1GTUMesh *> retrievePartsWithoutComputation() const;
208 MEDCoupling1GTUMesh *retrievePartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const;
209 void getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, int& start, int& stop) const;
210 void renumberNodesInConnWithoutComputation(const int *newNodeNumbersO2N);
211 bool isStoredSplitByType() const;
212 std::size_t getTimeOfThis() const;
213 std::size_t getHeapMemorySizeWithoutChildren() const;
214 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
215 MEDFileUMeshAggregateCompute deepCopy(DataArrayDouble *coords) const;
216 void shallowCpyMeshes();
217 bool isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const;
218 void checkConsistency() const;
219 void clearNonDiscrAttributes() const;
220 void synchronizeTinyInfo(const MEDFileMesh& master) const;
222 int getMeshDimension() const;
223 std::vector<int> getDistributionOfTypes() const;
225 void setCoords(DataArrayDouble *coords);
226 void forceComputationOfPartsFromUMesh() const;
227 const PartDefinition *getPartDefOfWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const;
228 void serialize(std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI) const;
229 void unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI);
231 std::size_t getTimeOfParts() const;
232 std::size_t getTimeOfUMesh() const;
234 mutable std::vector< MCAuto<MEDCoupling1GTUMesh> > _m_parts;
235 mutable std::size_t _mp_time;
236 mutable std::size_t _m_time;
237 mutable MCAuto<MEDCouplingUMesh> _m;
238 mutable std::vector< MCAuto<PartDefinition> > _part_def;
241 class MEDFileUMeshSplitL1 : public RefCountObject
243 friend class MEDFileUMeshPermCompute;
244 friend class MEDFileUMesh;
246 MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other);
247 MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::string& mName, int id);
248 MEDFileUMeshSplitL1(MEDCoupling1GTUMesh *m);
249 MEDFileUMeshSplitL1(MEDCouplingUMesh *m);
250 MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld);
251 void setName(const std::string& name);
252 std::size_t getHeapMemorySizeWithoutChildren() const;
253 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
254 MEDFileUMeshSplitL1 *shallowCpyUsingCoords(DataArrayDouble *coords) const;
255 MEDFileUMeshSplitL1 *deepCopy(DataArrayDouble *coords) const;
256 void checkConsistency() const;
257 void setCoords(DataArrayDouble *coords);
258 bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const;
259 void clearNonDiscrAttributes() const;
260 void synchronizeTinyInfo(const MEDFileMesh& master) const;
261 void assignMesh(MEDCouplingUMesh *m, bool newOrOld);
262 void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts);
263 void forceComputationOfParts() const;
265 bool presenceOfOneFams(const std::vector<int>& ids) const;
266 int getMeshDimension() const;
267 void simpleRepr(std::ostream& oss) const;
269 MEDCouplingUMesh *getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const;
270 DataArrayInt *getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const;
271 MEDCouplingUMesh *getWholeMesh(bool renum) const;
272 int getNumberOfCells() const;
273 bool isMeshStoredSplitByType() const { return _m_by_types.isStoredSplitByType(); }
274 std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes() const;
275 int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const;
276 std::vector<MEDCoupling1GTUMesh *> getDirectUndergroundSingleGeoTypeMeshes() const { return _m_by_types.retrievePartsWithoutComputation(); }
277 MEDCoupling1GTUMesh *getDirectUndergroundSingleGeoTypeMesh(INTERP_KERNEL::NormalizedCellType gt) const { return _m_by_types.retrievePartWithoutComputation(gt); }
278 DataArrayInt *extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const;
279 DataArrayInt *extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const;
280 std::vector<int> getDistributionOfTypes() const { return _m_by_types.getDistributionOfTypes(); }
281 DataArrayInt *getOrCreateAndGetFamilyField();
282 const DataArrayInt *getFamilyField() const;
283 const DataArrayInt *getNumberField() const;
284 const DataArrayAsciiChar *getNameField() const;
285 const DataArrayInt *getRevNumberField() const;
286 const PartDefinition *getPartDef(INTERP_KERNEL::NormalizedCellType gt) const;
287 void eraseFamilyField();
288 void setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
289 std::map<std::string, std::vector<std::string> >& groups);
290 void write(med_idt fid, const std::string& mName, int mdim) const;
292 void setFamilyArr(DataArrayInt *famArr);
293 DataArrayInt *getFamilyField();
294 void setRenumArr(DataArrayInt *renumArr);
295 void setNameArr(DataArrayAsciiChar *nameArr);
296 void changeFamilyIdArr(int oldId, int newId);
298 void renumberNodesInConn(const int *newNodeNumbersO2N);
300 void serialize(std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI) const;
301 void unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI);
303 static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp);
304 static std::vector<int> GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
305 static void TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
306 std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams);
307 static DataArrayInt *Renumber(const DataArrayInt *renum, const DataArrayInt *da);
308 static MEDCouplingUMesh *Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds);
309 static MEDFileUMeshSplitL1 *Unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI);
311 MEDFileUMeshSplitL1();
312 void assignCommonPart();
313 MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
314 DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const;
315 void computeRevNum() const;
317 MEDFileUMeshAggregateCompute _m_by_types;
318 MCAuto<DataArrayInt> _fam;
319 MCAuto<DataArrayInt> _num;
320 MCAuto<DataArrayAsciiChar> _names;
321 mutable MCAuto<DataArrayInt> _rev_num;
322 MEDFileUMeshPermCompute _m;
325 class MEDFileEltStruct4Mesh : public RefCountObject
328 static MEDFileEltStruct4Mesh *New(med_idt fid, const std::string& mName, int dt, int it, int iterOnStEltOfMesh, MEDFileMeshReadSelector *mrs);
330 std::size_t getHeapMemorySizeWithoutChildren() const;
331 std::vector<const MEDCoupling::BigMemoryObject*> getDirectChildrenWithNull() const;
333 ~MEDFileEltStruct4Mesh() { }
335 MEDFileEltStruct4Mesh(med_idt fid, const std::string& mName, int dt, int it, int iterOnStEltOfMesh, MEDFileMeshReadSelector *mrs);
337 std::string _geo_type_name;
339 MCAuto<DataArrayInt> _conn;
340 MCAuto<MEDFileUMeshPerTypeCommon> _common;
341 std::vector< MCAuto<DataArray> > _vars;