Salome HOME
On the road of reimplementation of basic MEDLoader API with advanced one.
[modules/med.git] / src / MEDLoader / MEDFileMesh.hxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #ifndef __MEDFILEMESH_HXX__
22 #define __MEDFILEMESH_HXX__
23
24 #include "MEDLoaderDefines.hxx"
25 #include "MEDFileMeshLL.hxx"
26 #include "MEDFileUtilities.hxx"
27
28 #include <map>
29 #include <list>
30
31 namespace ParaMEDMEM
32 {
33   class MEDLOADER_EXPORT MEDFileMesh : public RefCountObject, public MEDFileWritable
34   {
35   public:
36     static MEDFileMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception);
37     static MEDFileMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception);
38     std::size_t getHeapMemorySize() const;
39     virtual MEDFileMesh *createNewEmpty() const throw(INTERP_KERNEL::Exception) = 0;
40     virtual MEDFileMesh *deepCpy() const throw(INTERP_KERNEL::Exception) = 0;
41     virtual MEDFileMesh *shallowCpy() const throw(INTERP_KERNEL::Exception) = 0;
42     virtual bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const;
43     virtual void clearNonDiscrAttributes() const;
44     void setName(const char *name) { _name=name; }
45     bool changeNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception);
46     const char *getName() const { return _name.c_str(); }
47     const char *getUnivName() const { return _univ_name.c_str(); }
48     bool getUnivNameWrStatus() const { return _univ_wr_status; }
49     void setUnivNameWrStatus(bool newStatus) { _univ_wr_status=newStatus; }
50     void setDescription(const char *name) { _desc_name=name; }
51     const char *getDescription() const { return _desc_name.c_str(); }
52     void setOrder(int order) { _order=order; }
53     int getOrder() const { return _order; }
54     void setIteration(int it) { _iteration=it; }
55     int getIteration() const { return _iteration; }
56     void setTimeValue(double time) { _time=time; }
57     void setTime(int dt, int it, double time) { _time=time; _iteration=dt; _order=it; }
58     double getTime(int& dt, int& it) { dt=_iteration; it=_order; return _time; }
59     double getTimeValue() const { return _time; }
60     void setTimeUnit(const char *unit) { _dt_unit=unit; }
61     const char *getTimeUnit() const { return _dt_unit.c_str(); }
62     virtual int getNumberOfNodes() const throw(INTERP_KERNEL::Exception) = 0;
63     virtual std::vector<int> getNonEmptyLevels() const = 0;
64     virtual std::vector<int> getNonEmptyLevelsExt() const = 0;
65     virtual std::vector<int> getFamArrNonEmptyLevelsExt() const = 0;
66     virtual std::vector<int> getNumArrNonEmptyLevelsExt() const = 0;
67     virtual std::vector<int> getNameArrNonEmptyLevelsExt() const = 0;
68     virtual void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
69     virtual void write(med_idt fid) const throw(INTERP_KERNEL::Exception);
70     virtual int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0;
71     virtual MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax, bool renum=false) const throw(INTERP_KERNEL::Exception) = 0;
72     //
73     bool areFamsEqual(const MEDFileMesh *other, std::string& what) const;
74     bool areGrpsEqual(const MEDFileMesh *other, std::string& what) const;
75     bool existsGroup(const char *groupName) const;
76     bool existsFamily(int famId) const;
77     bool existsFamily(const char *familyName) const;
78     void setFamilyId(const char *familyName, int id);
79     void setFamilyIdUnique(const char *familyName, int id) throw(INTERP_KERNEL::Exception);
80     virtual void addFamily(const char *familyName, int id) throw(INTERP_KERNEL::Exception);
81     virtual void createGroupOnAll(int meshDimRelToMaxExt, const char *groupName) throw(INTERP_KERNEL::Exception);
82     virtual bool keepFamIdsOnlyOnLevs(const std::vector<int>& famIds, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception);
83     void addFamilyOnGrp(const char *grpName, const char *famName) throw(INTERP_KERNEL::Exception);
84     std::string findOrCreateAndGiveFamilyWithId(int id, bool& created) throw(INTERP_KERNEL::Exception);
85     void setFamilyInfo(const std::map<std::string,int>& info);
86     void setGroupInfo(const std::map<std::string, std::vector<std::string> >&info);
87     void copyFamGrpMapsFrom(const MEDFileMesh& other);
88     const std::map<std::string,int>& getFamilyInfo() const { return _families; }
89     const std::map<std::string, std::vector<std::string> >& getGroupInfo() const { return _groups; }
90     std::vector<std::string> getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception);
91     std::vector<std::string> getFamiliesOnGroups(const std::vector<std::string>& grps) const throw(INTERP_KERNEL::Exception);
92     std::vector<int> getFamiliesIdsOnGroup(const char *name) const throw(INTERP_KERNEL::Exception);
93     void setFamiliesOnGroup(const char *name, const std::vector<std::string>& fams) throw(INTERP_KERNEL::Exception);
94     void setFamiliesIdsOnGroup(const char *name, const std::vector<int>& famIds) throw(INTERP_KERNEL::Exception);
95     std::vector<std::string> getGroupsOnFamily(const char *name) const throw(INTERP_KERNEL::Exception);
96     void setGroupsOnFamily(const char *famName, const std::vector<std::string>& grps) throw(INTERP_KERNEL::Exception);
97     std::vector<std::string> getGroupsNames() const;
98     std::vector<std::string> getFamiliesNames() const;
99     void assignFamilyNameWithGroupName() throw(INTERP_KERNEL::Exception);
100     std::vector<std::string> removeEmptyGroups() throw(INTERP_KERNEL::Exception);
101     void removeGroup(const char *name) throw(INTERP_KERNEL::Exception);
102     void removeFamily(const char *name) throw(INTERP_KERNEL::Exception);
103     std::vector<std::string> removeOrphanGroups() throw(INTERP_KERNEL::Exception);
104     std::vector<std::string> removeOrphanFamilies() throw(INTERP_KERNEL::Exception);
105     void changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception);
106     void changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception);
107     void changeFamilyId(int oldId, int newId) throw(INTERP_KERNEL::Exception);
108     void changeAllGroupsContainingFamily(const char *familyNameToChange, const std::vector<std::string>& newFamiliesNames) throw(INTERP_KERNEL::Exception);
109     int getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception);
110     int getMaxAbsFamilyId() const throw(INTERP_KERNEL::Exception);
111     int getMaxFamilyId() const throw(INTERP_KERNEL::Exception);
112     int getMinFamilyId() const throw(INTERP_KERNEL::Exception);
113     int getTheMaxAbsFamilyId() const throw(INTERP_KERNEL::Exception);
114     int getTheMaxFamilyId() const throw(INTERP_KERNEL::Exception);
115     int getTheMinFamilyId() const throw(INTERP_KERNEL::Exception);
116     virtual int getMaxAbsFamilyIdInArrays() const throw(INTERP_KERNEL::Exception) = 0;
117     virtual int getMaxFamilyIdInArrays() const throw(INTERP_KERNEL::Exception) = 0;
118     virtual int getMinFamilyIdInArrays() const throw(INTERP_KERNEL::Exception) = 0;
119     DataArrayInt *getAllFamiliesIdsReferenced() const throw(INTERP_KERNEL::Exception);
120     DataArrayInt *computeAllFamilyIdsInUse() const throw(INTERP_KERNEL::Exception);
121     std::vector<int> getFamiliesIds(const std::vector<std::string>& famNames) const throw(INTERP_KERNEL::Exception);
122     std::string getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception);
123     bool ensureDifferentFamIdsPerLevel() throw(INTERP_KERNEL::Exception);
124     void normalizeFamIdsTrio() throw(INTERP_KERNEL::Exception);
125     void normalizeFamIdsMEDFile() throw(INTERP_KERNEL::Exception);
126     virtual int getMeshDimension() const throw(INTERP_KERNEL::Exception) = 0;
127     virtual std::string simpleRepr() const;
128     virtual std::string advancedRepr() const = 0;
129     //
130     virtual void setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector<const DataArrayInt *>& grps, bool renum=false) throw(INTERP_KERNEL::Exception);
131     virtual void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception) = 0;
132     virtual void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception) = 0;
133     virtual void setNameFieldAtLevel(int meshDimRelToMaxExt, DataArrayAsciiChar *nameArr) throw(INTERP_KERNEL::Exception) = 0;
134     virtual const DataArrayInt *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0;
135     virtual const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0;
136     virtual const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0;
137     virtual const DataArrayAsciiChar *getNameFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0;
138     virtual DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception) = 0;
139     virtual DataArrayInt *getGroupsArr(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
140     virtual DataArrayInt *getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
141     virtual DataArrayInt *getFamilyArr(int meshDimRelToMaxExt, const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
142     virtual DataArrayInt *getNodeGroupArr(const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
143     virtual DataArrayInt *getNodeGroupsArr(const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
144     virtual DataArrayInt *getNodeFamilyArr(const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
145     virtual DataArrayInt *getNodeFamiliesArr(const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
146     // tools
147     virtual bool unPolyze(std::vector<int>& oldCode, std::vector<int>& newCode, DataArrayInt *& o2nRenumCell) throw(INTERP_KERNEL::Exception) = 0;
148   protected:
149     MEDFileMesh();
150     //! protected because no way in MED file API to specify this name
151     void setUnivName(const char *name) { _univ_name=name; }
152     void addFamilyOnAllGroupsHaving(const char *famName, const char *otherFamName) throw(INTERP_KERNEL::Exception);
153     virtual void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception) = 0;
154     void dealWithTinyInfo(const MEDCouplingMesh *m) throw(INTERP_KERNEL::Exception);
155     virtual void synchronizeTinyInfoOnLeaves() const = 0;
156     void getFamilyRepr(std::ostream& oss) const;
157     virtual void appendFamilyEntries(const DataArrayInt *famIds, const std::vector< std::vector<int> >& fidsOfGrps, const std::vector<std::string>& grpNames);
158     virtual void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception) = 0;
159     static void TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector<int> >& famIdsPerGrp);
160     static void ChangeAllGroupsContainingFamily(std::map<std::string, std::vector<std::string> >& groups, const char *familyNameToChange, const std::vector<std::string>& newFamiliesNames) throw(INTERP_KERNEL::Exception);
161     static std::string FindOrCreateAndGiveFamilyWithId(std::map<std::string,int>& families, int id, bool& created) throw(INTERP_KERNEL::Exception);
162     static std::string CreateNameNotIn(const std::string& nameTry, const std::vector<std::string>& namesToAvoid) throw(INTERP_KERNEL::Exception);
163     static int PutInThirdComponentOfCodeOffset(std::vector<int>& code, int strt) throw(INTERP_KERNEL::Exception);
164   protected:
165     int _order;
166     int _iteration;
167     double _time;
168     std::string _dt_unit;
169     std::string _name;
170     //! this attribute do not impact the state of instance -> mutable
171     mutable std::string _univ_name;
172     bool _univ_wr_status;
173     std::string _desc_name;
174   protected:
175     std::map<std::string, std::vector<std::string> > _groups;
176     std::map<std::string,int> _families;
177   public:
178     static const char DFT_FAM_NAME[];
179   };
180
181   class MEDLOADER_EXPORT MEDFileUMesh : public MEDFileMesh
182   {
183     friend class MEDFileMesh;
184   public:
185     static MEDFileUMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception);
186     static MEDFileUMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception);
187     static MEDFileUMesh *New();
188     std::size_t getHeapMemorySize() const;
189     MEDFileMesh *createNewEmpty() const throw(INTERP_KERNEL::Exception);
190     MEDFileMesh *deepCpy() const throw(INTERP_KERNEL::Exception);
191     MEDFileMesh *shallowCpy() const throw(INTERP_KERNEL::Exception);
192     bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const;
193     void clearNonDiscrAttributes() const;
194     ~MEDFileUMesh();
195     //
196     int getMaxAbsFamilyIdInArrays() const throw(INTERP_KERNEL::Exception);
197     int getMaxFamilyIdInArrays() const throw(INTERP_KERNEL::Exception);
198     int getMinFamilyIdInArrays() const throw(INTERP_KERNEL::Exception);
199     int getMeshDimension() const throw(INTERP_KERNEL::Exception);
200     int getSpaceDimension() const throw(INTERP_KERNEL::Exception);
201     std::string simpleRepr() const;
202     std::string advancedRepr() const;
203     int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
204     const DataArrayInt *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
205     const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
206     const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
207     const DataArrayAsciiChar *getNameFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
208     int getNumberOfNodes() const throw(INTERP_KERNEL::Exception);
209     std::vector<int> getNonEmptyLevels() const;
210     std::vector<int> getNonEmptyLevelsExt() const;
211     std::vector<int> getFamArrNonEmptyLevelsExt() const;
212     std::vector<int> getNumArrNonEmptyLevelsExt() const;
213     std::vector<int> getNameArrNonEmptyLevelsExt() const;
214     std::vector<int> getGrpNonEmptyLevels(const char *grp) const throw(INTERP_KERNEL::Exception);
215     std::vector<int> getGrpNonEmptyLevelsExt(const char *grp) const throw(INTERP_KERNEL::Exception);
216     std::vector<int> getFamNonEmptyLevels(const char *fam) const throw(INTERP_KERNEL::Exception);
217     std::vector<int> getFamNonEmptyLevelsExt(const char *fam) const throw(INTERP_KERNEL::Exception);
218     std::vector<int> getGrpsNonEmptyLevels(const std::vector<std::string>& grps) const throw(INTERP_KERNEL::Exception);
219     std::vector<int> getGrpsNonEmptyLevelsExt(const std::vector<std::string>& grps) const throw(INTERP_KERNEL::Exception);
220     std::vector<int> getFamsNonEmptyLevels(const std::vector<std::string>& fams) const throw(INTERP_KERNEL::Exception);
221     std::vector<int> getFamsNonEmptyLevelsExt(const std::vector<std::string>& fams) const throw(INTERP_KERNEL::Exception);
222     std::vector<std::string> getGroupsOnSpecifiedLev(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
223     DataArrayDouble *getCoords() const;
224     MEDCouplingUMesh *getGroup(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
225     MEDCouplingUMesh *getGroups(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
226     MEDCouplingUMesh *getFamily(int meshDimRelToMaxExt, const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
227     MEDCouplingUMesh *getFamilies(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
228     DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
229     MEDCouplingUMesh *getMeshAtLevel(int meshDimRelToMaxExt, bool renum=false) const throw(INTERP_KERNEL::Exception);
230     MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax, bool renum=false) const throw(INTERP_KERNEL::Exception);
231     MEDCouplingUMesh *getLevel0Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
232     MEDCouplingUMesh *getLevelM1Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
233     MEDCouplingUMesh *getLevelM2Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
234     MEDCouplingUMesh *getLevelM3Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
235     //
236     void setFamilyNameAttachedOnId(int id, const std::string& newFamName) throw(INTERP_KERNEL::Exception);
237     void setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception);
238     void eraseGroupsAtLevel(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception);
239     void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception);
240     void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception);
241     void setNameFieldAtLevel(int meshDimRelToMaxExt, DataArrayAsciiChar *nameArr) throw(INTERP_KERNEL::Exception);
242     void addNodeGroup(const DataArrayInt *ids) throw(INTERP_KERNEL::Exception);
243     void addGroup(int meshDimRelToMaxExt, const DataArrayInt *ids) throw(INTERP_KERNEL::Exception);
244     void removeMeshAtLevel(int meshDimRelToMax) throw(INTERP_KERNEL::Exception);
245     void setMeshAtLevel(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld=false) throw(INTERP_KERNEL::Exception);
246     void setMeshes(const std::vector<const MEDCouplingUMesh *>& ms, bool renum=false) throw(INTERP_KERNEL::Exception);
247     void setGroupsFromScratch(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms, bool renum=false) throw(INTERP_KERNEL::Exception);
248     void setGroupsOnSetMesh(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms, bool renum=false) throw(INTERP_KERNEL::Exception);
249     void optimizeFamilies() throw(INTERP_KERNEL::Exception);
250     // tools
251     void duplicateNodesOnM1Group(const char *grpNameM1, DataArrayInt *&nodesDuplicated, DataArrayInt *&cellsModified, DataArrayInt *&cellsNotModified) throw(INTERP_KERNEL::Exception);
252     bool unPolyze(std::vector<int>& oldCode, std::vector<int>& newCode, DataArrayInt *& o2nRenumCell) throw(INTERP_KERNEL::Exception);
253     DataArrayInt *zipCoords() throw(INTERP_KERNEL::Exception);
254   private:
255     void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception);
256     MEDFileUMesh();
257     MEDFileUMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
258     void loadUMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
259     const MEDFileUMeshSplitL1 *getMeshAtLevSafe(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
260     MEDFileUMeshSplitL1 *getMeshAtLevSafe(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception);
261     void checkMeshDimCoherency(int meshDim, int meshDimRelToMax) const throw(INTERP_KERNEL::Exception);
262     DataArrayDouble *checkMultiMesh(const std::vector<const MEDCouplingUMesh *>& ms) const throw(INTERP_KERNEL::Exception);
263     void computeRevNum() const;
264     void synchronizeTinyInfoOnLeaves() const;
265     void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception);
266     std::list< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > getAllNonNullFamilyIds() const;
267     void addGroupUnderground(bool isNodeGroup, const DataArrayInt *ids, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception);
268   private:
269     std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> > _ms;
270     MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
271     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_coords;
272     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_coords;
273     MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _name_coords;
274     mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num_coords;
275   };
276
277   class MEDLOADER_EXPORT MEDFileStructuredMesh : public MEDFileMesh
278   {
279     friend class MEDFileMesh;
280   public:
281     std::size_t getHeapMemorySize() const;
282     int getMaxAbsFamilyIdInArrays() const throw(INTERP_KERNEL::Exception);
283     int getMaxFamilyIdInArrays() const throw(INTERP_KERNEL::Exception);
284     int getMinFamilyIdInArrays() const throw(INTERP_KERNEL::Exception);
285     bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const;
286     void clearNonDiscrAttributes() const;
287     DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
288     const DataArrayInt *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
289     void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception);
290     void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception);
291     void setNameFieldAtLevel(int meshDimRelToMaxExt, DataArrayAsciiChar *nameArr) throw(INTERP_KERNEL::Exception);
292     const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
293     const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
294     const DataArrayAsciiChar *getNameFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
295     std::vector<int> getNonEmptyLevels() const;
296     std::vector<int> getNonEmptyLevelsExt() const;
297     std::vector<int> getFamArrNonEmptyLevelsExt() const;
298     std::vector<int> getNumArrNonEmptyLevelsExt() const;
299     std::vector<int> getNameArrNonEmptyLevelsExt() const;
300     MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax, bool renum=false) const throw(INTERP_KERNEL::Exception);
301     int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
302     int getNumberOfNodes() const throw(INTERP_KERNEL::Exception);
303     // tools
304     bool unPolyze(std::vector<int>& oldCode, std::vector<int>& newCode, DataArrayInt *& o2nRenumCell) throw(INTERP_KERNEL::Exception);
305   protected:
306     void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception);
307     void deepCpyAttributes() throw(INTERP_KERNEL::Exception);
308     void loadStrMeshFromFile(MEDFileStrMeshL2 *strm, med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
309     void writeStructuredLL(med_idt fid, const char *maa) const throw(INTERP_KERNEL::Exception);
310     virtual const MEDCouplingStructuredMesh *getStructuredMesh() const = 0;
311     static med_geometry_type GetGeoTypeFromMeshDim(int meshDim) throw(INTERP_KERNEL::Exception);
312   private:
313     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_nodes;
314     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_nodes;
315     MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _names_nodes;
316     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_cells;
317     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_cells;
318     MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _names_cells;
319     mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num_nodes;
320     mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num_cells;
321   };
322
323   class MEDLOADER_EXPORT MEDFileCMesh : public MEDFileStructuredMesh
324   {
325     friend class MEDFileMesh;
326   public:
327     static MEDFileCMesh *New();
328     static MEDFileCMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception);
329     static MEDFileCMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception);
330     std::size_t getHeapMemorySize() const;
331     MEDFileMesh *createNewEmpty() const throw(INTERP_KERNEL::Exception);
332     MEDFileMesh *deepCpy() const throw(INTERP_KERNEL::Exception);
333     MEDFileMesh *shallowCpy() const throw(INTERP_KERNEL::Exception);
334     bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const;
335     int getMeshDimension() const throw(INTERP_KERNEL::Exception);
336     std::string simpleRepr() const;
337     std::string advancedRepr() const;
338     void clearNonDiscrAttributes() const;
339     const MEDCouplingCMesh *getMesh() const;
340     void setMesh(MEDCouplingCMesh *m) throw(INTERP_KERNEL::Exception);
341   private:
342     const MEDCouplingStructuredMesh *getStructuredMesh() const;
343     void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception);
344     MEDFileCMesh();
345     void synchronizeTinyInfoOnLeaves() const;
346     MEDFileCMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
347     void loadCMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
348   private:
349     MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> _cmesh;
350   };
351
352   class MEDLOADER_EXPORT MEDFileCurveLinearMesh : public MEDFileStructuredMesh
353   {
354     friend class MEDFileMesh;
355   public:
356     static MEDFileCurveLinearMesh *New();
357     static MEDFileCurveLinearMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception);
358     static MEDFileCurveLinearMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception);
359     std::size_t getHeapMemorySize() const;
360     MEDFileMesh *createNewEmpty() const throw(INTERP_KERNEL::Exception);
361     MEDFileMesh *deepCpy() const throw(INTERP_KERNEL::Exception);
362     MEDFileMesh *shallowCpy() const throw(INTERP_KERNEL::Exception);
363     bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const;
364     int getMeshDimension() const throw(INTERP_KERNEL::Exception);
365     std::string simpleRepr() const;
366     std::string advancedRepr() const;
367     void clearNonDiscrAttributes() const;
368     const MEDCouplingCurveLinearMesh *getMesh() const;
369     void setMesh(MEDCouplingCurveLinearMesh *m) throw(INTERP_KERNEL::Exception);
370   private:
371     MEDFileCurveLinearMesh();
372     MEDFileCurveLinearMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
373     const MEDCouplingStructuredMesh *getStructuredMesh() const;
374     void synchronizeTinyInfoOnLeaves() const;
375     void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception);
376     void loadCLMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);//to imp
377   private:
378     MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> _clmesh;
379   };
380
381   class MEDLOADER_EXPORT MEDFileMeshMultiTS : public RefCountObject, public MEDFileWritable
382   {
383   public:
384     static MEDFileMeshMultiTS *New();
385     static MEDFileMeshMultiTS *New(const char *fileName) throw(INTERP_KERNEL::Exception);
386     static MEDFileMeshMultiTS *New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception);
387     MEDFileMeshMultiTS *deepCpy() const throw(INTERP_KERNEL::Exception);
388     std::size_t getHeapMemorySize() const;
389     const char *getName() const throw(INTERP_KERNEL::Exception);
390     void setName(const char *newMeshName) throw(INTERP_KERNEL::Exception);
391     bool changeNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception);
392     MEDFileMesh *getOneTimeStep() const throw(INTERP_KERNEL::Exception);
393     void write(med_idt fid) const throw(INTERP_KERNEL::Exception);
394     void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
395     void setOneTimeStep(MEDFileMesh *mesh1TimeStep) throw(INTERP_KERNEL::Exception);
396   private:
397     void loadFromFile(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception);
398     MEDFileMeshMultiTS();
399     MEDFileMeshMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception);
400     MEDFileMeshMultiTS(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception);
401   private:
402     std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> > _mesh_one_ts;
403   };
404
405   class MEDFileMeshesIterator;
406
407   class MEDLOADER_EXPORT MEDFileMeshes : public RefCountObject, public MEDFileWritable
408   {
409   public:
410     static MEDFileMeshes *New();
411     static MEDFileMeshes *New(const char *fileName) throw(INTERP_KERNEL::Exception);
412     MEDFileMeshes *deepCpy() const throw(INTERP_KERNEL::Exception);
413     std::size_t getHeapMemorySize() const;
414     std::string simpleRepr() const;
415     void simpleReprWithoutHeader(std::ostream& oss) const;
416     void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
417     void write(med_idt fid) const throw(INTERP_KERNEL::Exception);
418     int getNumberOfMeshes() const throw(INTERP_KERNEL::Exception);
419     MEDFileMeshesIterator *iterator() throw(INTERP_KERNEL::Exception);
420     MEDFileMesh *getMeshAtPos(int i) const throw(INTERP_KERNEL::Exception);
421     MEDFileMesh *getMeshWithName(const char *mname) const throw(INTERP_KERNEL::Exception);
422     std::vector<std::string> getMeshesNames() const throw(INTERP_KERNEL::Exception);
423     bool changeNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception);
424     //
425     void resize(int newSize) throw(INTERP_KERNEL::Exception);
426     void pushMesh(MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception);
427     void setMeshAtPos(int i, MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception);
428     void destroyMeshAtPos(int i) throw(INTERP_KERNEL::Exception);
429   private:
430     void checkCoherency() const throw(INTERP_KERNEL::Exception);
431     void loadFromFile(const char *fileName) throw(INTERP_KERNEL::Exception);
432     MEDFileMeshes();
433     MEDFileMeshes(const char *fileName) throw(INTERP_KERNEL::Exception);
434   private:
435     std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> > _meshes;
436   };
437
438   class MEDCOUPLING_EXPORT MEDFileMeshesIterator
439   {
440   public:
441     MEDFileMeshesIterator(MEDFileMeshes *ms);
442     ~MEDFileMeshesIterator();
443     MEDFileMesh *nextt();
444   private:
445     MEDCouplingAutoRefCountObjectPtr<MEDFileMeshes> _ms;
446      int _iter_id;
447      int _nb_iter;
448   };
449 }
450
451 #endif