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