Salome HOME
Doc fix and enhancement.
[tools/medcoupling.git] / src / MEDLoader / MEDFileMeshLL.hxx
1 // Copyright (C) 2007-2015  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 __MEDFILEMESHLL_HXX__
22 #define __MEDFILEMESHLL_HXX__
23
24 #include "MEDFileBasis.hxx"
25 #include "MEDFileMeshElt.hxx"
26
27 #include "MEDCouplingUMesh.hxx"
28 #include "MEDCouplingCMesh.hxx"
29 #include "MEDCoupling1GTUMesh.hxx"
30 #include "MEDCouplingPartDefinition.hxx"
31 #include "MEDCouplingCurveLinearMesh.hxx"
32 #include "MCAuto.hxx"
33
34 #include "med.h"
35
36 #include <map>
37
38 namespace MEDCoupling
39 {
40   class MEDFileMeshReadSelector;
41
42   class MEDFileMeshL2 : public RefCountObject
43   {
44   public:
45     MEDFileMeshL2();
46     std::size_t getHeapMemorySizeWithoutChildren() const;
47     std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
48     const char *getName() const { return _name.getReprForWrite(); }
49     const char *getDescription() const { return _description.getReprForWrite(); }
50     const char *getUnivName() const { return _univ_name.getReprForWrite(); }
51     const char *getTimeUnit() const { return _dt_unit.getReprForWrite(); }
52     int getIteration() const { return _iteration; }
53     int getOrder() const { return _order; }
54     double getTime() const { return _time; }
55     MCAuto<PartDefinition> getPartDefOfCoo() const { return _part_coords; }
56     std::vector<std::string> getAxisInfoOnMesh(med_idt fid, int mId, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& nstep, int& Mdim);
57     static int GetMeshIdFromName(med_idt fid, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& dt, int& it, std::string& dtunit1);
58     static double CheckMeshTimeStep(med_idt fid, const std::string& mname, int nstep, int dt, int it);
59     static void ReadFamiliesAndGrps(med_idt fid, const std::string& mname, std::map<std::string,int>& fams, std::map<std::string, std::vector<std::string> >& grps, MEDFileMeshReadSelector *mrs);
60     static void WriteFamiliesAndGrps(med_idt fid, const std::string& mname, const std::map<std::string,int>& fams, const std::map<std::string, std::vector<std::string> >& grps, int tooLongStrPol);
61     static bool RenameFamiliesFromFileToMem(std::vector< std::string >& famNames);
62     static bool RenameFamiliesFromMemToFile(std::vector< std::string >& famNames);
63     static MEDCoupling::MEDCouplingAxisType TraduceAxisType(med_axis_type at);
64     static MEDCoupling::MEDCouplingAxisType TraduceAxisTypeStruct(med_grid_type gt);
65     static med_axis_type TraduceAxisTypeRev(MEDCoupling::MEDCouplingAxisType at);
66     static med_grid_type TraduceAxisTypeRevStruct(MEDCoupling::MEDCouplingAxisType at);
67   private:
68     typedef bool (*RenameFamiliesPatternFunc)(std::vector< std::string >&);
69     static void RenameFamiliesPatternInternal(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >& crudeFams, RenameFamiliesPatternFunc func);
70     static void RenameFamiliesFromFileToMemInternal(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >& crudeFams);
71     static void RenameFamiliesFromMemToFileInternal(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >& crudeFams);
72   public:
73     static const char ZE_SEP_FOR_FAMILY_KILLERS[];
74     static int ZE_SEP2_FOR_FAMILY_KILLERS;
75   protected:
76     MEDFileString _name;
77     MEDFileString _description;
78     MEDFileString _univ_name;
79     MEDFileString _dt_unit;
80     int _iteration;
81     int _order;
82     double _time;
83     MCAuto<PartDefinition> _part_coords;
84   };
85
86   class MEDFileUMeshL2 : public MEDFileMeshL2
87   {
88   public:
89     MEDFileUMeshL2();
90     std::vector<std::string> loadCommonPart(med_idt fid, int mId, const std::string& mName, int dt, int it, int& Mdim);
91     void loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs);
92     void loadPart(med_idt fid, int mId, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<int>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs);
93     void loadConnectivity(med_idt fid, int mdim, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs);
94     void loadPartOfConnectivity(med_idt fid, int mdim, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<int>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs);
95     void loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it);
96     void loadPartCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it, int nMin, int nMax);
97     int getNumberOfLevels() const { return _per_type_mesh.size(); }
98     bool emptyLev(int levId) const { return _per_type_mesh[levId].empty(); }
99     const std::vector< MCAuto<MEDFileUMeshPerType> >& getLev(int levId) const { return _per_type_mesh[levId]; }
100     bool isFamDefinedOnLev(int levId) const;
101     bool isNumDefinedOnLev(int levId) const;
102     bool isNamesDefinedOnLev(int levId) const;
103     MCAuto<DataArrayDouble> getCoords() const { return _coords; }
104     MCAuto<DataArrayInt> getCoordsFamily() const { return _fam_coords; }
105     MCAuto<DataArrayInt> getCoordsNum() const { return _num_coords; }
106     MCAuto<DataArrayAsciiChar> getCoordsName() const { return _name_coords; }
107     static void WriteCoords(med_idt fid, const std::string& mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords, const DataArrayAsciiChar *nameCoords);
108   private:
109     void sortTypes();
110   private:
111     std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > > _per_type_mesh;
112     MCAuto<DataArrayDouble> _coords;
113     MCAuto<DataArrayInt> _fam_coords;
114     MCAuto<DataArrayInt> _num_coords;
115     MCAuto<DataArrayAsciiChar> _name_coords;
116   };
117
118   class MEDFileStrMeshL2 : public MEDFileMeshL2
119   {
120   };
121
122   class MEDFileCMeshL2 : public MEDFileStrMeshL2
123   {
124   public:
125     MEDFileCMeshL2();
126     void loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it);
127     MEDCouplingCMesh *getMesh() { return _cmesh; }
128     MEDCoupling::MEDCouplingAxisType getAxisType() const { return _ax_type; }
129   private:
130     static med_data_type GetDataTypeCorrespondingToSpaceId(int id);
131   private:
132     MCAuto<MEDCouplingCMesh> _cmesh;
133     MEDCoupling::MEDCouplingAxisType _ax_type;
134   };
135
136   class MEDFileCLMeshL2 : public MEDFileStrMeshL2
137   {
138   public:
139     MEDFileCLMeshL2();
140     void loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it);
141     MEDCouplingCurveLinearMesh *getMesh() { return _clmesh; }
142   private:
143     MCAuto<MEDCouplingCurveLinearMesh> _clmesh;
144   };
145
146   class MEDFileMesh;
147   class MEDFileUMeshSplitL1;
148
149   class MEDFileUMeshPermCompute : public BigMemoryObject
150   {
151   public:
152     MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st);
153     operator MEDCouplingUMesh *() const;
154     void operator=(MEDCouplingUMesh *m);
155     void updateTime() const;
156     std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
157     std::size_t getHeapMemorySizeWithoutChildren() const;
158   private:
159     const MEDFileUMeshSplitL1 *_st;
160     mutable std::size_t _mpt_time;
161     mutable std::size_t _num_time;
162     mutable MCAuto<MEDCouplingUMesh> _m;
163   };
164
165   class MEDFileUMeshAggregateCompute : public BigMemoryObject
166   {
167   public:
168     MEDFileUMeshAggregateCompute();
169     void setName(const std::string& name);
170     void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts);
171     void assignDefParts(const std::vector<const PartDefinition *>& partDefs);
172     void assignUMesh(MEDCouplingUMesh *m);
173     MEDCouplingUMesh *getUmesh() const;
174     int getNumberOfCells() const;
175     std::vector<MEDCoupling1GTUMesh *> getParts() const;
176     std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes() const;
177     int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const;
178     std::vector<MEDCoupling1GTUMesh *> retrievePartsWithoutComputation() const;
179     MEDCoupling1GTUMesh *retrievePartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const;
180     void getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, int& start, int& stop) const;
181     void renumberNodesInConnWithoutComputation(const int *newNodeNumbersO2N);
182     bool isStoredSplitByType() const;
183     std::size_t getTimeOfThis() const;
184     std::size_t getHeapMemorySizeWithoutChildren() const;
185     std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
186     MEDFileUMeshAggregateCompute deepCopy(DataArrayDouble *coords) const;
187     void shallowCpyMeshes();
188     bool isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const;
189     void checkConsistency() const;
190     void clearNonDiscrAttributes() const;
191     void synchronizeTinyInfo(const MEDFileMesh& master) const;
192     bool empty() const;
193     int getMeshDimension() const;
194     std::vector<int> getDistributionOfTypes() const;
195     int getSize() const;
196     void setCoords(DataArrayDouble *coords);
197     void forceComputationOfPartsFromUMesh() const;
198     const PartDefinition *getPartDefOfWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const;
199     void serialize(std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI) const;
200     void unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI);
201   private:
202     std::size_t getTimeOfParts() const;
203     std::size_t getTimeOfUMesh() const;
204   private:
205     mutable std::vector< MCAuto<MEDCoupling1GTUMesh> > _m_parts;
206     mutable std::size_t _mp_time;
207     mutable std::size_t _m_time;
208     mutable MCAuto<MEDCouplingUMesh> _m;
209     mutable std::vector< MCAuto<PartDefinition> > _part_def;
210   };
211
212   class MEDFileUMeshSplitL1 : public RefCountObject
213   {
214     friend class MEDFileUMeshPermCompute;
215     friend class MEDFileUMesh;
216   public:
217     MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other);
218     MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::string& mName, int id);
219     MEDFileUMeshSplitL1(MEDCoupling1GTUMesh *m);
220     MEDFileUMeshSplitL1(MEDCouplingUMesh *m);
221     MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld);
222     void setName(const std::string& name);
223     std::size_t getHeapMemorySizeWithoutChildren() const;
224     std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
225     MEDFileUMeshSplitL1 *shallowCpyUsingCoords(DataArrayDouble *coords) const;
226     MEDFileUMeshSplitL1 *deepCopy(DataArrayDouble *coords) const;
227     void checkConsistency() const;
228     void setCoords(DataArrayDouble *coords);
229     bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const;
230     void clearNonDiscrAttributes() const;
231     void synchronizeTinyInfo(const MEDFileMesh& master) const;
232     void assignMesh(MEDCouplingUMesh *m, bool newOrOld);
233     void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts);
234     void forceComputationOfParts() const;
235     bool empty() const;
236     bool presenceOfOneFams(const std::vector<int>& ids) const;
237     int getMeshDimension() const;
238     void simpleRepr(std::ostream& oss) const;
239     int getSize() const;
240     MEDCouplingUMesh *getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const;
241     DataArrayInt *getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const;
242     MEDCouplingUMesh *getWholeMesh(bool renum) const;
243     int getNumberOfCells() const;
244     bool isMeshStoredSplitByType() const { return _m_by_types.isStoredSplitByType(); }
245     std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes() const;
246     int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const;
247     std::vector<MEDCoupling1GTUMesh *> getDirectUndergroundSingleGeoTypeMeshes() const { return _m_by_types.retrievePartsWithoutComputation(); }
248     MEDCoupling1GTUMesh *getDirectUndergroundSingleGeoTypeMesh(INTERP_KERNEL::NormalizedCellType gt) const { return _m_by_types.retrievePartWithoutComputation(gt); }
249     DataArrayInt *extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const;
250     DataArrayInt *extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const;
251     std::vector<int> getDistributionOfTypes() const { return _m_by_types.getDistributionOfTypes(); }
252     DataArrayInt *getOrCreateAndGetFamilyField();
253     const DataArrayInt *getFamilyField() const;
254     const DataArrayInt *getNumberField() const;
255     const DataArrayAsciiChar *getNameField() const;
256     const DataArrayInt *getRevNumberField() const;
257     const PartDefinition *getPartDef(INTERP_KERNEL::NormalizedCellType gt) const;
258     void eraseFamilyField();
259     void setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
260                               std::map<std::string, std::vector<std::string> >& groups);
261     void write(med_idt fid, const std::string& mName, int mdim) const;
262     //
263     void setFamilyArr(DataArrayInt *famArr);
264     DataArrayInt *getFamilyField();
265     void setRenumArr(DataArrayInt *renumArr);
266     void setNameArr(DataArrayAsciiChar *nameArr);
267     void changeFamilyIdArr(int oldId, int newId);
268     //
269     void renumberNodesInConn(const int *newNodeNumbersO2N);
270     //
271     void serialize(std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI) const;
272     void unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI);
273     //
274     static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp);
275     static std::vector<int> GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
276     static void TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
277                                     std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams);
278     static DataArrayInt *Renumber(const DataArrayInt *renum, const DataArrayInt *da);
279     static MEDCouplingUMesh *Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds);
280     static MEDFileUMeshSplitL1 *Unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI);
281   private:
282     MEDFileUMeshSplitL1();
283     void assignCommonPart();
284     MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
285     DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const;
286     void computeRevNum() const;
287   private:
288     MEDFileUMeshAggregateCompute _m_by_types;
289     MCAuto<DataArrayInt> _fam;
290     MCAuto<DataArrayInt> _num;
291     MCAuto<DataArrayAsciiChar> _names;
292     mutable MCAuto<DataArrayInt> _rev_num;
293     MEDFileUMeshPermCompute _m;
294   };
295 }
296
297 #endif