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