1 // Copyright (C) 2007-2013 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.
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 getHeapMemorySize() const { return 0; }
46 const char *getName() const { return _name.getReprForWrite(); }
47 const char *getDescription() const { return _description.getReprForWrite(); }
48 const char *getUnivName() const { return _univ_name.getReprForWrite(); }
49 const char *getTimeUnit() const { return _dt_unit.getReprForWrite(); }
50 int getIteration() const { return _iteration; }
51 int getOrder() const { return _order; }
52 double getTime() { return _time; }
53 std::vector<std::string> getAxisInfoOnMesh(med_idt fid, int mId, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim) throw(INTERP_KERNEL::Exception);
54 static int GetMeshIdFromName(med_idt fid, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1) throw(INTERP_KERNEL::Exception);
55 static double CheckMeshTimeStep(med_idt fid, const char *mname, int nstep, int dt, int it) throw(INTERP_KERNEL::Exception);
56 static void ReadFamiliesAndGrps(med_idt fid, const char *mname, std::map<std::string,int>& fams, std::map<std::string, std::vector<std::string> >& grps, MEDFileMeshReadSelector *mrs);
57 static void WriteFamiliesAndGrps(med_idt fid, const char *mname, const std::map<std::string,int>& fams, const std::map<std::string, std::vector<std::string> >& grps, int tooLongStrPol);
60 MEDFileString _description;
61 MEDFileString _univ_name;
62 MEDFileString _dt_unit;
68 class MEDFileUMeshL2 : public MEDFileMeshL2
72 void loadAll(med_idt fid, int mId, const char *mName, int dt, int it, MEDFileMeshReadSelector *mrs);
73 void loadConnectivity(med_idt fid, int mdim, const char *mName, int dt, int it, MEDFileMeshReadSelector *mrs);
74 void loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
75 int getNumberOfLevels() const { return _per_type_mesh.size(); }
76 bool emptyLev(int levId) const { return _per_type_mesh[levId].empty(); }
77 const std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& getLev(int levId) const { return _per_type_mesh[levId]; }
78 bool isFamDefinedOnLev(int levId) const;
79 bool isNumDefinedOnLev(int levId) const;
80 bool isNamesDefinedOnLev(int levId) const;
81 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> getCoords() const { return _coords; }
82 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsFamily() const { return _fam_coords; }
83 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsNum() const { return _num_coords; }
84 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> getCoordsName() const { return _name_coords; }
85 static void WriteCoords(med_idt fid, const char *mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords, const DataArrayAsciiChar *nameCoords);
89 std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > > _per_type_mesh;
90 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
91 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_coords;
92 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_coords;
93 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _name_coords;
96 class MEDFileStrMeshL2 : public MEDFileMeshL2
100 class MEDFileCMeshL2 : public MEDFileStrMeshL2
104 void loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
105 MEDCouplingCMesh *getMesh() { return _cmesh; }
107 static med_data_type GetDataTypeCorrespondingToSpaceId(int id) throw(INTERP_KERNEL::Exception);
109 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> _cmesh;
112 class MEDFileCLMeshL2 : public MEDFileStrMeshL2
116 void loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
117 MEDCouplingCurveLinearMesh *getMesh() { return _clmesh; }
119 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> _clmesh;
123 class MEDFileUMeshSplitL1;
125 class MEDFileUMeshPermCompute
128 MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st);
129 operator MEDCouplingUMesh *() const;
130 void operator=(MEDCouplingUMesh *m);
131 void updateTime() const;
133 const MEDFileUMeshSplitL1 *_st;
134 mutable std::size_t _mpt_time;
135 mutable std::size_t _num_time;
136 mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
139 class MEDFileUMeshAggregateCompute
142 MEDFileUMeshAggregateCompute();
143 void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts);
144 void assignUMesh(MEDCouplingUMesh *m);
145 MEDCouplingUMesh *getUmesh() const;
146 std::vector<MEDCoupling1GTUMesh *> getParts() const;
147 std::vector<MEDCoupling1GTUMesh *> getPartsWithoutComputation() const throw(INTERP_KERNEL::Exception);
148 MEDCoupling1GTUMesh *getPartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const throw(INTERP_KERNEL::Exception);
149 std::size_t getTimeOfThis() const;
150 std::size_t getHeapMemorySize() const;
151 MEDFileUMeshAggregateCompute deepCpy(DataArrayDouble *coords) const;
152 bool isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const;
153 void clearNonDiscrAttributes() const;
154 void synchronizeTinyInfo(const MEDFileMesh& master) const;
156 int getMeshDimension() const;
157 std::vector<int> getDistributionOfTypes() const throw(INTERP_KERNEL::Exception);
158 int getSize() const throw(INTERP_KERNEL::Exception);
159 void setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception);
161 void forceComputationOfPartsFromUMesh() const;
162 std::size_t getTimeOfParts() const;
163 std::size_t getTimeOfUMesh() const;
165 mutable std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> > _m_parts;
166 mutable std::size_t _mp_time;
167 mutable std::size_t _m_time;
168 mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
171 class MEDFileUMeshSplitL1 : public RefCountObject
173 friend class MEDFileUMeshPermCompute;
175 MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other);
176 MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id);
177 MEDFileUMeshSplitL1(MEDCouplingUMesh *m);
178 MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld);
179 std::size_t getHeapMemorySize() const;
180 MEDFileUMeshSplitL1 *deepCpy(DataArrayDouble *coords) const;
181 void setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception);
182 bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const;
183 void clearNonDiscrAttributes() const;
184 void synchronizeTinyInfo(const MEDFileMesh& master) const;
185 void assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception);
187 bool presenceOfOneFams(const std::vector<int>& ids) const;
188 int getMeshDimension() const;
189 void simpleRepr(std::ostream& oss) const;
190 int getSize() const throw(INTERP_KERNEL::Exception);
191 MEDCouplingUMesh *getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const;
192 DataArrayInt *getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const;
193 MEDCouplingUMesh *getWholeMesh(bool renum) const;
194 std::vector<MEDCoupling1GTUMesh *> getDirectUndergroundSingleGeoTypeMeshes() const throw(INTERP_KERNEL::Exception) { return _m_by_types.getPartsWithoutComputation(); }
195 MEDCoupling1GTUMesh *getDirectUndergroundSingleGeoTypeMesh(INTERP_KERNEL::NormalizedCellType gt) const throw(INTERP_KERNEL::Exception) { return _m_by_types.getPartWithoutComputation(gt); }
196 std::vector<int> getDistributionOfTypes() const throw(INTERP_KERNEL::Exception) { return _m_by_types.getDistributionOfTypes(); }
197 DataArrayInt *getOrCreateAndGetFamilyField() throw(INTERP_KERNEL::Exception);
198 const DataArrayInt *getFamilyField() const;
199 const DataArrayInt *getNumberField() const;
200 const DataArrayAsciiChar *getNameField() const;
201 const DataArrayInt *getRevNumberField() const;
202 void eraseFamilyField();
203 void setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
204 std::map<std::string, std::vector<std::string> >& groups) throw(INTERP_KERNEL::Exception);
205 void write(med_idt fid, const char *mName, int mdim) const;
207 void setFamilyArr(DataArrayInt *famArr);
208 void setRenumArr(DataArrayInt *renumArr);
209 void setNameArr(DataArrayAsciiChar *nameArr);
210 void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception);
212 void renumberNodesInConn(const int *newNodeNumbersO2N) throw(INTERP_KERNEL::Exception);
214 static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp);
215 static std::vector<int> GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
216 static void TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
217 std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams);
218 static DataArrayInt *Renumber(const DataArrayInt *renum, const DataArrayInt *da);
219 static MEDCouplingUMesh *Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds);
221 MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
222 DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const;
223 void computeRevNum() const;
225 MEDFileUMeshAggregateCompute _m_by_types;
226 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam;
227 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num;
228 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _names;
229 mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num;
230 MEDFileUMeshPermCompute _m;