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