1 // Copyright (C) 2007-2015 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"
32 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
40 class MEDFileMeshReadSelector;
42 class MEDFileMeshL2 : public RefCountObject
46 std::size_t getHeapMemorySizeWithoutChildren() const;
47 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
48 const char *getName() const { return _name.getReprForWrite(); }
49 const char *getDescription() const { return _description.getReprForWrite(); }
50 const char *getUnivName() const { return _univ_name.getReprForWrite(); }
51 const char *getTimeUnit() const { return _dt_unit.getReprForWrite(); }
52 int getIteration() const { return _iteration; }
53 int getOrder() const { return _order; }
54 double getTime() const { return _time; }
55 MEDCouplingAutoRefCountObjectPtr<PartDefinition> getPartDefOfCoo() const { return _part_coords; }
56 std::vector<std::string> getAxisInfoOnMesh(med_idt fid, int mId, const std::string& mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim);
57 static int GetMeshIdFromName(med_idt fid, const std::string& mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1);
58 static double CheckMeshTimeStep(med_idt fid, const std::string& mname, int nstep, int dt, int it);
59 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);
60 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);
61 static bool RenameFamiliesFromFileToMem(std::vector< std::string >& famNames);
62 static bool RenameFamiliesFromMemToFile(std::vector< std::string >& famNames);
64 typedef bool (*RenameFamiliesPatternFunc)(std::vector< std::string >&);
65 static void RenameFamiliesPatternInternal(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >& crudeFams, RenameFamiliesPatternFunc func);
66 static void RenameFamiliesFromFileToMemInternal(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >& crudeFams);
67 static void RenameFamiliesFromMemToFileInternal(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >& crudeFams);
69 static const char ZE_SEP_FOR_FAMILY_KILLERS[];
70 static int ZE_SEP2_FOR_FAMILY_KILLERS;
73 MEDFileString _description;
74 MEDFileString _univ_name;
75 MEDFileString _dt_unit;
79 MEDCouplingAutoRefCountObjectPtr<PartDefinition> _part_coords;
82 class MEDFileUMeshL2 : public MEDFileMeshL2
86 std::vector<std::string> loadCommonPart(med_idt fid, int mId, const std::string& mName, int dt, int it, int& Mdim);
87 void loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs);
88 void loadPart(med_idt fid, int mId, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<int>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs);
89 void loadConnectivity(med_idt fid, int mdim, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs);
90 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);
91 void loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it);
92 void loadPartCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it, int nMin, int nMax);
93 int getNumberOfLevels() const { return _per_type_mesh.size(); }
94 bool emptyLev(int levId) const { return _per_type_mesh[levId].empty(); }
95 const std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& getLev(int levId) const { return _per_type_mesh[levId]; }
96 bool isFamDefinedOnLev(int levId) const;
97 bool isNumDefinedOnLev(int levId) const;
98 bool isNamesDefinedOnLev(int levId) const;
99 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> getCoords() const { return _coords; }
100 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsFamily() const { return _fam_coords; }
101 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsNum() const { return _num_coords; }
102 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> getCoordsName() const { return _name_coords; }
103 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);
107 std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > > _per_type_mesh;
108 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
109 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_coords;
110 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_coords;
111 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _name_coords;
114 class MEDFileStrMeshL2 : public MEDFileMeshL2
118 class MEDFileCMeshL2 : public MEDFileStrMeshL2
122 void loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it);
123 MEDCouplingCMesh *getMesh() { return _cmesh; }
125 static med_data_type GetDataTypeCorrespondingToSpaceId(int id);
127 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> _cmesh;
130 class MEDFileCLMeshL2 : public MEDFileStrMeshL2
134 void loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it);
135 MEDCouplingCurveLinearMesh *getMesh() { return _clmesh; }
137 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> _clmesh;
141 class MEDFileUMeshSplitL1;
143 class MEDFileUMeshPermCompute : public BigMemoryObject
146 MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st);
147 operator MEDCouplingUMesh *() const;
148 void operator=(MEDCouplingUMesh *m);
149 void updateTime() const;
150 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
151 std::size_t getHeapMemorySizeWithoutChildren() const;
153 const MEDFileUMeshSplitL1 *_st;
154 mutable std::size_t _mpt_time;
155 mutable std::size_t _num_time;
156 mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
159 class MEDFileUMeshAggregateCompute : public BigMemoryObject
162 MEDFileUMeshAggregateCompute();
163 void setName(const std::string& name);
164 void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts);
165 void assignDefParts(const std::vector<const PartDefinition *>& partDefs);
166 void assignUMesh(MEDCouplingUMesh *m);
167 MEDCouplingUMesh *getUmesh() const;
168 int getNumberOfCells() const;
169 std::vector<MEDCoupling1GTUMesh *> getParts() const;
170 std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes() const;
171 int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const;
172 std::vector<MEDCoupling1GTUMesh *> retrievePartsWithoutComputation() const;
173 MEDCoupling1GTUMesh *retrievePartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const;
174 void getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, int& start, int& stop) const;
175 void renumberNodesInConnWithoutComputation(const int *newNodeNumbersO2N);
176 bool isStoredSplitByType() const;
177 std::size_t getTimeOfThis() const;
178 std::size_t getHeapMemorySizeWithoutChildren() const;
179 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
180 MEDFileUMeshAggregateCompute deepCpy(DataArrayDouble *coords) const;
181 bool isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const;
182 void clearNonDiscrAttributes() const;
183 void synchronizeTinyInfo(const MEDFileMesh& master) const;
185 int getMeshDimension() const;
186 std::vector<int> getDistributionOfTypes() const;
188 void setCoords(DataArrayDouble *coords);
189 void forceComputationOfPartsFromUMesh() const;
190 const PartDefinition *getPartDefOfWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const;
191 void serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const;
192 void unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI);
194 std::size_t getTimeOfParts() const;
195 std::size_t getTimeOfUMesh() const;
197 mutable std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> > _m_parts;
198 mutable std::size_t _mp_time;
199 mutable std::size_t _m_time;
200 mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
201 mutable std::vector< MEDCouplingAutoRefCountObjectPtr<PartDefinition> > _part_def;
204 class MEDFileUMeshSplitL1 : public RefCountObject
206 friend class MEDFileUMeshPermCompute;
208 MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other);
209 MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::string& mName, int id);
210 MEDFileUMeshSplitL1(MEDCoupling1GTUMesh *m);
211 MEDFileUMeshSplitL1(MEDCouplingUMesh *m);
212 MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld);
213 void setName(const std::string& name);
214 std::size_t getHeapMemorySizeWithoutChildren() const;
215 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
216 MEDFileUMeshSplitL1 *deepCpy(DataArrayDouble *coords) const;
217 void setCoords(DataArrayDouble *coords);
218 bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const;
219 void clearNonDiscrAttributes() const;
220 void synchronizeTinyInfo(const MEDFileMesh& master) const;
221 void assignMesh(MEDCouplingUMesh *m, bool newOrOld);
222 void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts);
223 void forceComputationOfParts() const;
225 bool presenceOfOneFams(const std::vector<int>& ids) const;
226 int getMeshDimension() const;
227 void simpleRepr(std::ostream& oss) const;
229 MEDCouplingUMesh *getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const;
230 DataArrayInt *getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const;
231 MEDCouplingUMesh *getWholeMesh(bool renum) const;
232 int getNumberOfCells() const;
233 bool isMeshStoredSplitByType() const { return _m_by_types.isStoredSplitByType(); }
234 std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes() const;
235 int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const;
236 std::vector<MEDCoupling1GTUMesh *> getDirectUndergroundSingleGeoTypeMeshes() const { return _m_by_types.retrievePartsWithoutComputation(); }
237 MEDCoupling1GTUMesh *getDirectUndergroundSingleGeoTypeMesh(INTERP_KERNEL::NormalizedCellType gt) const { return _m_by_types.retrievePartWithoutComputation(gt); }
238 DataArrayInt *extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const;
239 DataArrayInt *extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const;
240 std::vector<int> getDistributionOfTypes() const { return _m_by_types.getDistributionOfTypes(); }
241 DataArrayInt *getOrCreateAndGetFamilyField();
242 const DataArrayInt *getFamilyField() const;
243 const DataArrayInt *getNumberField() const;
244 const DataArrayAsciiChar *getNameField() const;
245 const DataArrayInt *getRevNumberField() const;
246 const PartDefinition *getPartDef(INTERP_KERNEL::NormalizedCellType gt) const;
247 void eraseFamilyField();
248 void setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
249 std::map<std::string, std::vector<std::string> >& groups);
250 void write(med_idt fid, const std::string& mName, int mdim) const;
252 void setFamilyArr(DataArrayInt *famArr);
253 DataArrayInt *getFamilyField();
254 void setRenumArr(DataArrayInt *renumArr);
255 void setNameArr(DataArrayAsciiChar *nameArr);
256 void changeFamilyIdArr(int oldId, int newId);
258 void renumberNodesInConn(const int *newNodeNumbersO2N);
260 void serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const;
261 void unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI);
263 static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp);
264 static std::vector<int> GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
265 static void TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
266 std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams);
267 static DataArrayInt *Renumber(const DataArrayInt *renum, const DataArrayInt *da);
268 static MEDCouplingUMesh *Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds);
269 static MEDFileUMeshSplitL1 *Unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI);
271 MEDFileUMeshSplitL1();
272 void assignCommonPart();
273 MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
274 DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const;
275 void computeRevNum() const;
277 MEDFileUMeshAggregateCompute _m_by_types;
278 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam;
279 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num;
280 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _names;
281 mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num;
282 MEDFileUMeshPermCompute _m;