Salome HOME
Merge remote branch 'origin/abn/checkDeepEquival' into V7_5_BR
[modules/med.git] / src / MEDLoader / MEDFileMeshLL.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 __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 "MEDCouplingAutoRefCountObjectPtr.hxx"
33
34 #include "med.h"
35
36 #include <map>
37
38 namespace ParaMEDMEM
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     MEDCouplingAutoRefCountObjectPtr<PartDefinition> getPartDefOfCoo() const { return _part_coords; }
56     std::vector<std::string> getAxisInfoOnMesh(med_idt fid, int mId, const std::string& mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim);
57     static int GetMeshIdFromName(med_idt fid, const std::string& mName, ParaMEDMEM::MEDCouplingMeshType& meshType, 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   protected:
62     MEDFileString _name;
63     MEDFileString _description;
64     MEDFileString _univ_name;
65     MEDFileString _dt_unit;
66     int _iteration;
67     int _order;
68     double _time;
69     MEDCouplingAutoRefCountObjectPtr<PartDefinition> _part_coords;
70   };
71
72   class MEDFileUMeshL2 : public MEDFileMeshL2
73   {
74   public:
75     MEDFileUMeshL2();
76     std::vector<std::string> loadCommonPart(med_idt fid, int mId, const std::string& mName, int dt, int it, int& Mdim);
77     void loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs);
78     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);
79     void loadConnectivity(med_idt fid, int mdim, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs);
80     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);
81     void loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it);
82     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);
83     int getNumberOfLevels() const { return _per_type_mesh.size(); }
84     bool emptyLev(int levId) const { return _per_type_mesh[levId].empty(); }
85     const std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& getLev(int levId) const { return _per_type_mesh[levId]; }
86     bool isFamDefinedOnLev(int levId) const;
87     bool isNumDefinedOnLev(int levId) const;
88     bool isNamesDefinedOnLev(int levId) const;
89     MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> getCoords() const { return _coords; }
90     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsFamily() const { return _fam_coords; }
91     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsNum() const { return _num_coords; }
92     MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> getCoordsName() const { return _name_coords; }
93     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);
94   private:
95     void sortTypes();
96   private:
97     std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > > _per_type_mesh;
98     MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
99     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_coords;
100     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_coords;
101     MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _name_coords;
102   };
103
104   class MEDFileStrMeshL2 : public MEDFileMeshL2
105   {
106   };
107
108   class MEDFileCMeshL2 : public MEDFileStrMeshL2
109   {
110   public:
111     MEDFileCMeshL2();
112     void loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it);
113     MEDCouplingCMesh *getMesh() { return _cmesh; }
114   private:
115     static med_data_type GetDataTypeCorrespondingToSpaceId(int id);
116   private:
117     MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> _cmesh;
118   };
119
120   class MEDFileCLMeshL2 : public MEDFileStrMeshL2
121   {
122   public:
123     MEDFileCLMeshL2();
124     void loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it);
125     MEDCouplingCurveLinearMesh *getMesh() { return _clmesh; }
126   private:
127     MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> _clmesh;
128   };
129
130   class MEDFileMesh;
131   class MEDFileUMeshSplitL1;
132
133   class MEDFileUMeshPermCompute : public BigMemoryObject
134   {
135   public:
136     MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st);
137     operator MEDCouplingUMesh *() const;
138     void operator=(MEDCouplingUMesh *m);
139     void updateTime() const;
140     std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
141     std::size_t getHeapMemorySizeWithoutChildren() const;
142   private:
143     const MEDFileUMeshSplitL1 *_st;
144     mutable std::size_t _mpt_time;
145     mutable std::size_t _num_time;
146     mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
147   };
148
149   class MEDFileUMeshAggregateCompute : public BigMemoryObject
150   {
151   public:
152     MEDFileUMeshAggregateCompute();
153     void setName(const std::string& name);
154     void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts);
155     void assignDefParts(const std::vector<const PartDefinition *>& partDefs);
156     void assignUMesh(MEDCouplingUMesh *m);
157     MEDCouplingUMesh *getUmesh() const;
158     std::vector<MEDCoupling1GTUMesh *> getParts() const;
159     std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes() const;
160     std::vector<MEDCoupling1GTUMesh *> retrievePartsWithoutComputation() const;
161     MEDCoupling1GTUMesh *retrievePartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const;
162     void getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, int& start, int& stop) const;
163     void renumberNodesInConnWithoutComputation(const int *newNodeNumbersO2N);
164     bool isStoredSplitByType() const;
165     std::size_t getTimeOfThis() const;
166     std::size_t getHeapMemorySizeWithoutChildren() const;
167     std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
168     MEDFileUMeshAggregateCompute deepCpy(DataArrayDouble *coords) const;
169     bool isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const;
170     void clearNonDiscrAttributes() const;
171     void synchronizeTinyInfo(const MEDFileMesh& master) const;
172     bool empty() const;
173     int getMeshDimension() const;
174     std::vector<int> getDistributionOfTypes() const;
175     int getSize() const;
176     void setCoords(DataArrayDouble *coords);
177     void forceComputationOfPartsFromUMesh() const;
178     const PartDefinition *getPartDefOfWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const;
179   private:
180     std::size_t getTimeOfParts() const;
181     std::size_t getTimeOfUMesh() const;
182   private:
183     mutable std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> > _m_parts;
184     mutable std::size_t _mp_time;
185     mutable std::size_t _m_time;
186     mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
187     mutable std::vector< MEDCouplingAutoRefCountObjectPtr<PartDefinition> > _part_def;
188   };
189
190   class MEDFileUMeshSplitL1 : public RefCountObject
191   {
192     friend class MEDFileUMeshPermCompute;
193   public:
194     MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other);
195     MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::string& mName, int id);
196     MEDFileUMeshSplitL1(MEDCoupling1GTUMesh *m);
197     MEDFileUMeshSplitL1(MEDCouplingUMesh *m);
198     MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld);
199     void setName(const std::string& name);
200     std::size_t getHeapMemorySizeWithoutChildren() const;
201     std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
202     MEDFileUMeshSplitL1 *deepCpy(DataArrayDouble *coords) const;
203     void setCoords(DataArrayDouble *coords);
204     bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const;
205     void clearNonDiscrAttributes() const;
206     void synchronizeTinyInfo(const MEDFileMesh& master) const;
207     void assignMesh(MEDCouplingUMesh *m, bool newOrOld);
208     void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts);
209     void forceComputationOfParts() const;
210     bool empty() const;
211     bool presenceOfOneFams(const std::vector<int>& ids) const;
212     int getMeshDimension() const;
213     void simpleRepr(std::ostream& oss) const;
214     int getSize() const;
215     MEDCouplingUMesh *getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const;
216     DataArrayInt *getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const;
217     MEDCouplingUMesh *getWholeMesh(bool renum) const;
218     bool isMeshStoredSplitByType() const { return _m_by_types.isStoredSplitByType(); }
219     std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes() const;
220     std::vector<MEDCoupling1GTUMesh *> getDirectUndergroundSingleGeoTypeMeshes() const { return _m_by_types.retrievePartsWithoutComputation(); }
221     MEDCoupling1GTUMesh *getDirectUndergroundSingleGeoTypeMesh(INTERP_KERNEL::NormalizedCellType gt) const { return _m_by_types.retrievePartWithoutComputation(gt); }
222     DataArrayInt *extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const;
223     DataArrayInt *extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const;
224     std::vector<int> getDistributionOfTypes() const { return _m_by_types.getDistributionOfTypes(); }
225     DataArrayInt *getOrCreateAndGetFamilyField();
226     const DataArrayInt *getFamilyField() const;
227     const DataArrayInt *getNumberField() const;
228     const DataArrayAsciiChar *getNameField() const;
229     const DataArrayInt *getRevNumberField() const;
230     const PartDefinition *getPartDef(INTERP_KERNEL::NormalizedCellType gt) const;
231     void eraseFamilyField();
232     void setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
233                               std::map<std::string, std::vector<std::string> >& groups);
234     void write(med_idt fid, const std::string& mName, int mdim) const;
235     //
236     void setFamilyArr(DataArrayInt *famArr);
237     void setRenumArr(DataArrayInt *renumArr);
238     void setNameArr(DataArrayAsciiChar *nameArr);
239     void changeFamilyIdArr(int oldId, int newId);
240     //
241     void renumberNodesInConn(const int *newNodeNumbersO2N);
242     //
243     static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp);
244     static std::vector<int> GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
245     static void TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
246                                     std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams);
247     static DataArrayInt *Renumber(const DataArrayInt *renum, const DataArrayInt *da);
248     static MEDCouplingUMesh *Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds);
249   private:
250     void assignCommonPart();
251     MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
252     DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const;
253     void computeRevNum() const;
254   private:
255     MEDFileUMeshAggregateCompute _m_by_types;
256     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam;
257     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num;
258     MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _names;
259     mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num;
260     MEDFileUMeshPermCompute _m;
261   };
262 }
263
264 #endif