1 // Copyright (C) 2007-2014 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 "MEDCouplingCurveLinearMesh.hxx"
31 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
39 class MEDFileMeshReadSelector;
41 class MEDFileMeshL2 : public RefCountObject
45 std::size_t getHeapMemorySizeWithoutChildren() const;
46 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
47 const char *getName() const { return _name.getReprForWrite(); }
48 const char *getDescription() const { return _description.getReprForWrite(); }
49 const char *getUnivName() const { return _univ_name.getReprForWrite(); }
50 const char *getTimeUnit() const { return _dt_unit.getReprForWrite(); }
51 int getIteration() const { return _iteration; }
52 int getOrder() const { return _order; }
53 double getTime() const { return _time; }
54 std::vector<std::string> getAxisInfoOnMesh(med_idt fid, int mId, const std::string& mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim);
55 static int GetMeshIdFromName(med_idt fid, const std::string& mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1);
56 static double CheckMeshTimeStep(med_idt fid, const std::string& mname, int nstep, int dt, int it);
57 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);
58 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 MEDFileString _description;
62 MEDFileString _univ_name;
63 MEDFileString _dt_unit;
69 class MEDFileUMeshL2 : public MEDFileMeshL2
73 std::vector<std::string> loadCommonPart(med_idt fid, int mId, const std::string& mName, int dt, int it, int& Mdim);
74 void loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs);
75 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);
76 void loadConnectivity(med_idt fid, int mdim, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs);
77 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);
78 void loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it);
79 void loadPartCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it, DataArrayInt *n2o);
80 int getNumberOfLevels() const { return _per_type_mesh.size(); }
81 bool emptyLev(int levId) const { return _per_type_mesh[levId].empty(); }
82 const std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& getLev(int levId) const { return _per_type_mesh[levId]; }
83 bool isFamDefinedOnLev(int levId) const;
84 bool isNumDefinedOnLev(int levId) const;
85 bool isNamesDefinedOnLev(int levId) const;
86 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> getCoords() const { return _coords; }
87 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsFamily() const { return _fam_coords; }
88 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsNum() const { return _num_coords; }
89 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> getCoordsName() const { return _name_coords; }
90 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);
94 std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > > _per_type_mesh;
95 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
96 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_coords;
97 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_coords;
98 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _name_coords;
101 class MEDFileStrMeshL2 : public MEDFileMeshL2
105 class MEDFileCMeshL2 : public MEDFileStrMeshL2
109 void loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it);
110 MEDCouplingCMesh *getMesh() { return _cmesh; }
112 static med_data_type GetDataTypeCorrespondingToSpaceId(int id);
114 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> _cmesh;
117 class MEDFileCLMeshL2 : public MEDFileStrMeshL2
121 void loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it);
122 MEDCouplingCurveLinearMesh *getMesh() { return _clmesh; }
124 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> _clmesh;
128 class MEDFileUMeshSplitL1;
130 class MEDFileUMeshPermCompute : public BigMemoryObject
133 MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st);
134 operator MEDCouplingUMesh *() const;
135 void operator=(MEDCouplingUMesh *m);
136 void updateTime() const;
137 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
138 std::size_t getHeapMemorySizeWithoutChildren() const;
140 const MEDFileUMeshSplitL1 *_st;
141 mutable std::size_t _mpt_time;
142 mutable std::size_t _num_time;
143 mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
146 class MEDFileUMeshAggregateCompute : public BigMemoryObject
149 MEDFileUMeshAggregateCompute();
150 void setName(const std::string& name);
151 void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts);
152 void assignUMesh(MEDCouplingUMesh *m);
153 MEDCouplingUMesh *getUmesh() const;
154 std::vector<MEDCoupling1GTUMesh *> getParts() const;
155 std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes() const;
156 std::vector<MEDCoupling1GTUMesh *> getPartsWithoutComputation() const;
157 MEDCoupling1GTUMesh *getPartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const;
158 void getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, int& start, int& stop) const;
159 std::size_t getTimeOfThis() const;
160 std::size_t getHeapMemorySizeWithoutChildren() const;
161 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
162 MEDFileUMeshAggregateCompute deepCpy(DataArrayDouble *coords) const;
163 bool isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const;
164 void clearNonDiscrAttributes() const;
165 void synchronizeTinyInfo(const MEDFileMesh& master) const;
167 int getMeshDimension() const;
168 std::vector<int> getDistributionOfTypes() const;
170 void setCoords(DataArrayDouble *coords);
171 void forceComputationOfPartsFromUMesh() const;
173 std::size_t getTimeOfParts() const;
174 std::size_t getTimeOfUMesh() const;
176 mutable std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> > _m_parts;
177 mutable std::size_t _mp_time;
178 mutable std::size_t _m_time;
179 mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
182 class MEDFileUMeshSplitL1 : public RefCountObject
184 friend class MEDFileUMeshPermCompute;
186 MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other);
187 MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::string& mName, int id);
188 MEDFileUMeshSplitL1(MEDCoupling1GTUMesh *m);
189 MEDFileUMeshSplitL1(MEDCouplingUMesh *m);
190 MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld);
191 void setName(const std::string& name);
192 std::size_t getHeapMemorySizeWithoutChildren() const;
193 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
194 MEDFileUMeshSplitL1 *deepCpy(DataArrayDouble *coords) const;
195 void setCoords(DataArrayDouble *coords);
196 bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const;
197 void clearNonDiscrAttributes() const;
198 void synchronizeTinyInfo(const MEDFileMesh& master) const;
199 void assignMesh(MEDCouplingUMesh *m, bool newOrOld);
200 void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts);
201 void forceComputationOfParts() const;
203 bool presenceOfOneFams(const std::vector<int>& ids) const;
204 int getMeshDimension() const;
205 void simpleRepr(std::ostream& oss) const;
207 MEDCouplingUMesh *getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const;
208 DataArrayInt *getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const;
209 MEDCouplingUMesh *getWholeMesh(bool renum) const;
210 std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes() const;
211 std::vector<MEDCoupling1GTUMesh *> getDirectUndergroundSingleGeoTypeMeshes() const { return _m_by_types.getPartsWithoutComputation(); }
212 MEDCoupling1GTUMesh *getDirectUndergroundSingleGeoTypeMesh(INTERP_KERNEL::NormalizedCellType gt) const { return _m_by_types.getPartWithoutComputation(gt); }
213 DataArrayInt *extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const;
214 DataArrayInt *extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const;
215 std::vector<int> getDistributionOfTypes() const { return _m_by_types.getDistributionOfTypes(); }
216 DataArrayInt *getOrCreateAndGetFamilyField();
217 const DataArrayInt *getFamilyField() const;
218 const DataArrayInt *getNumberField() const;
219 const DataArrayAsciiChar *getNameField() const;
220 const DataArrayInt *getRevNumberField() const;
221 void eraseFamilyField();
222 void setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
223 std::map<std::string, std::vector<std::string> >& groups);
224 void write(med_idt fid, const std::string& mName, int mdim) const;
226 void setFamilyArr(DataArrayInt *famArr);
227 void setRenumArr(DataArrayInt *renumArr);
228 void setNameArr(DataArrayAsciiChar *nameArr);
229 void changeFamilyIdArr(int oldId, int newId);
231 void renumberNodesInConn(const int *newNodeNumbersO2N);
233 static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp);
234 static std::vector<int> GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
235 static void TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
236 std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams);
237 static DataArrayInt *Renumber(const DataArrayInt *renum, const DataArrayInt *da);
238 static MEDCouplingUMesh *Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds);
240 void assignCommonPart();
241 MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
242 DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const;
243 void computeRevNum() const;
245 MEDFileUMeshAggregateCompute _m_by_types;
246 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam;
247 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num;
248 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _names;
249 mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num;
250 MEDFileUMeshPermCompute _m;