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);
63 MEDFileString _description;
64 MEDFileString _univ_name;
65 MEDFileString _dt_unit;
69 MEDCouplingAutoRefCountObjectPtr<PartDefinition> _part_coords;
72 class MEDFileUMeshL2 : public MEDFileMeshL2
76 std::vector<std::string> loadCommonPart(med_idt fid, int mId, const std::string& mName, int dt, int it, int& Mdim);
77 void loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs);
78 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);
79 void loadConnectivity(med_idt fid, int mdim, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs);
80 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);
81 void loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it);
82 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);
83 int getNumberOfLevels() const { return _per_type_mesh.size(); }
84 bool emptyLev(int levId) const { return _per_type_mesh[levId].empty(); }
85 const std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& getLev(int levId) const { return _per_type_mesh[levId]; }
86 bool isFamDefinedOnLev(int levId) const;
87 bool isNumDefinedOnLev(int levId) const;
88 bool isNamesDefinedOnLev(int levId) const;
89 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> getCoords() const { return _coords; }
90 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsFamily() const { return _fam_coords; }
91 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsNum() const { return _num_coords; }
92 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> getCoordsName() const { return _name_coords; }
93 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);
97 std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > > _per_type_mesh;
98 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
99 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_coords;
100 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_coords;
101 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _name_coords;
104 class MEDFileStrMeshL2 : public MEDFileMeshL2
108 class MEDFileCMeshL2 : public MEDFileStrMeshL2
112 void loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it);
113 MEDCouplingCMesh *getMesh() { return _cmesh; }
115 static med_data_type GetDataTypeCorrespondingToSpaceId(int id);
117 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> _cmesh;
120 class MEDFileCLMeshL2 : public MEDFileStrMeshL2
124 void loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it);
125 MEDCouplingCurveLinearMesh *getMesh() { return _clmesh; }
127 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> _clmesh;
131 class MEDFileUMeshSplitL1;
133 class MEDFileUMeshPermCompute : public BigMemoryObject
136 MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st);
137 operator MEDCouplingUMesh *() const;
138 void operator=(MEDCouplingUMesh *m);
139 void updateTime() const;
140 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
141 std::size_t getHeapMemorySizeWithoutChildren() const;
143 const MEDFileUMeshSplitL1 *_st;
144 mutable std::size_t _mpt_time;
145 mutable std::size_t _num_time;
146 mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
149 class MEDFileUMeshAggregateCompute : public BigMemoryObject
152 MEDFileUMeshAggregateCompute();
153 void setName(const std::string& name);
154 void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts);
155 void assignDefParts(const std::vector<const PartDefinition *>& partDefs);
156 void assignUMesh(MEDCouplingUMesh *m);
157 MEDCouplingUMesh *getUmesh() const;
158 int getNumberOfCells() const;
159 std::vector<MEDCoupling1GTUMesh *> getParts() const;
160 std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes() const;
161 std::vector<MEDCoupling1GTUMesh *> retrievePartsWithoutComputation() const;
162 MEDCoupling1GTUMesh *retrievePartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const;
163 void getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, int& start, int& stop) const;
164 void renumberNodesInConnWithoutComputation(const int *newNodeNumbersO2N);
165 bool isStoredSplitByType() const;
166 std::size_t getTimeOfThis() const;
167 std::size_t getHeapMemorySizeWithoutChildren() const;
168 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
169 MEDFileUMeshAggregateCompute deepCpy(DataArrayDouble *coords) const;
170 bool isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const;
171 void clearNonDiscrAttributes() const;
172 void synchronizeTinyInfo(const MEDFileMesh& master) const;
174 int getMeshDimension() const;
175 std::vector<int> getDistributionOfTypes() const;
177 void setCoords(DataArrayDouble *coords);
178 void forceComputationOfPartsFromUMesh() const;
179 const PartDefinition *getPartDefOfWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const;
180 void serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const;
181 void unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI);
183 std::size_t getTimeOfParts() const;
184 std::size_t getTimeOfUMesh() const;
186 mutable std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> > _m_parts;
187 mutable std::size_t _mp_time;
188 mutable std::size_t _m_time;
189 mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
190 mutable std::vector< MEDCouplingAutoRefCountObjectPtr<PartDefinition> > _part_def;
193 class MEDFileUMeshSplitL1 : public RefCountObject
195 friend class MEDFileUMeshPermCompute;
197 MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other);
198 MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::string& mName, int id);
199 MEDFileUMeshSplitL1(MEDCoupling1GTUMesh *m);
200 MEDFileUMeshSplitL1(MEDCouplingUMesh *m);
201 MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld);
202 void setName(const std::string& name);
203 std::size_t getHeapMemorySizeWithoutChildren() const;
204 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
205 MEDFileUMeshSplitL1 *deepCpy(DataArrayDouble *coords) const;
206 void setCoords(DataArrayDouble *coords);
207 bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const;
208 void clearNonDiscrAttributes() const;
209 void synchronizeTinyInfo(const MEDFileMesh& master) const;
210 void assignMesh(MEDCouplingUMesh *m, bool newOrOld);
211 void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts);
212 void forceComputationOfParts() const;
214 bool presenceOfOneFams(const std::vector<int>& ids) const;
215 int getMeshDimension() const;
216 void simpleRepr(std::ostream& oss) const;
218 MEDCouplingUMesh *getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const;
219 DataArrayInt *getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const;
220 MEDCouplingUMesh *getWholeMesh(bool renum) const;
221 int getNumberOfCells() const;
222 bool isMeshStoredSplitByType() const { return _m_by_types.isStoredSplitByType(); }
223 std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes() const;
224 std::vector<MEDCoupling1GTUMesh *> getDirectUndergroundSingleGeoTypeMeshes() const { return _m_by_types.retrievePartsWithoutComputation(); }
225 MEDCoupling1GTUMesh *getDirectUndergroundSingleGeoTypeMesh(INTERP_KERNEL::NormalizedCellType gt) const { return _m_by_types.retrievePartWithoutComputation(gt); }
226 DataArrayInt *extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const;
227 DataArrayInt *extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const;
228 std::vector<int> getDistributionOfTypes() const { return _m_by_types.getDistributionOfTypes(); }
229 DataArrayInt *getOrCreateAndGetFamilyField();
230 const DataArrayInt *getFamilyField() const;
231 const DataArrayInt *getNumberField() const;
232 const DataArrayAsciiChar *getNameField() const;
233 const DataArrayInt *getRevNumberField() const;
234 const PartDefinition *getPartDef(INTERP_KERNEL::NormalizedCellType gt) const;
235 void eraseFamilyField();
236 void setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
237 std::map<std::string, std::vector<std::string> >& groups);
238 void write(med_idt fid, const std::string& mName, int mdim) const;
240 void setFamilyArr(DataArrayInt *famArr);
241 DataArrayInt *getFamilyField();
242 void setRenumArr(DataArrayInt *renumArr);
243 void setNameArr(DataArrayAsciiChar *nameArr);
244 void changeFamilyIdArr(int oldId, int newId);
246 void renumberNodesInConn(const int *newNodeNumbersO2N);
248 void serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const;
249 void unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI);
251 static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp);
252 static std::vector<int> GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
253 static void TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
254 std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams);
255 static DataArrayInt *Renumber(const DataArrayInt *renum, const DataArrayInt *da);
256 static MEDCouplingUMesh *Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds);
257 static MEDFileUMeshSplitL1 *Unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI);
259 MEDFileUMeshSplitL1();
260 void assignCommonPart();
261 MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
262 DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const;
263 void computeRevNum() const;
265 MEDFileUMeshAggregateCompute _m_by_types;
266 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam;
267 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num;
268 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _names;
269 mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num;
270 MEDFileUMeshPermCompute _m;