Salome HOME
f0c6e6b22b47bd5ea10b6e19c77db60ae6d11f7d
[modules/med.git] / src / MEDLoader / MEDFileFieldOverView.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 __MEDFILEFIELDOVERVIEW_HXX__
22 #define __MEDFILEFIELDOVERVIEW_HXX__
23
24 #include "MEDLoaderDefines.hxx"
25
26 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
27 #include "MEDCouplingRefCountObject.hxx"
28 #include "MEDCoupling1GTUMesh.hxx"
29
30 #include "NormalizedUnstructuredMesh.hxx"
31 #include "InterpKernelException.hxx"
32
33 #include <vector>
34
35 namespace ParaMEDMEM
36 {
37   class DataArrayInt;
38   class MEDCouplingMesh;
39   class MEDFileMesh;
40   class MEDFileUMesh;
41   class MEDFileCMesh;
42   class MEDFileCurveLinearMesh;
43   class MEDFileFieldGlobs;
44   class MEDFileFieldGlobsReal;
45   class MEDFileAnyTypeField1TS;
46   class MEDFileAnyTypeFieldMultiTS;
47
48   class MEDFileMeshStruct : public RefCountObject
49   {
50   public:
51     MEDLOADER_EXPORT static MEDFileMeshStruct *New(const MEDFileMesh *mesh);
52     std::size_t getHeapMemorySize() const;
53     const MEDFileMesh *getTheMesh() const { return _mesh; }
54     int getNumberOfNodes() const { return _nb_nodes; }
55     int getNumberOfElemsOfGeoType(INTERP_KERNEL::NormalizedCellType t) const throw(INTERP_KERNEL::Exception);
56     int getLevelOfGeoType(INTERP_KERNEL::NormalizedCellType t) const throw(INTERP_KERNEL::Exception);
57     int getNumberOfLevs() const;
58     int getNumberOfGeoTypesInLev(int relativeLev) const throw(INTERP_KERNEL::Exception);
59   private:
60     MEDFileMeshStruct(const MEDFileMesh *mesh);
61   private:
62     const MEDFileMesh *_mesh;
63     std::string _name;
64     int _nb_nodes;
65     std::vector< std::vector<int> > _geo_types_distrib;
66   }; 
67   
68   class MEDFileField1TSStructItem;
69   
70   class MEDMeshMultiLev : public RefCountObject
71   {
72   public:
73     std::size_t getHeapMemorySize() const;
74   public:
75     static MEDMeshMultiLev *New(const MEDFileMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities) throw(INTERP_KERNEL::Exception);
76     static MEDMeshMultiLev *New(const MEDFileMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception);
77     static MEDMeshMultiLev *NewOnlyOnNode(const MEDFileMesh *m, const DataArrayInt *pflOnNode) throw(INTERP_KERNEL::Exception);
78     void setNodeReduction(const DataArrayInt *nr);
79     bool isFastlyTheSameStruct(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception);
80     MEDLOADER_EXPORT DataArray *buildDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const throw(INTERP_KERNEL::Exception);
81     virtual void selectPartOfNodes(const DataArrayInt *pflNodes) throw(INTERP_KERNEL::Exception) = 0;
82     virtual MEDMeshMultiLev *prepare() const throw(INTERP_KERNEL::Exception) = 0;
83   protected:
84     std::string getPflNameOfId(int id) const;
85     DataArray *constructDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const throw(INTERP_KERNEL::Exception);
86   protected:
87     MEDMeshMultiLev();
88     MEDMeshMultiLev(const MEDMeshMultiLev& other);
89     MEDMeshMultiLev(const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
90   protected:
91     std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > _pfls;
92     std::vector< INTERP_KERNEL::NormalizedCellType > _geo_types;
93     std::vector<int> _nb_entities;
94     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _node_reduction;
95   public:
96     static const int PARAMEDMEM_2_VTKTYPE_LGTH=34;
97     static const unsigned char PARAMEDMEM_2_VTKTYPE[PARAMEDMEM_2_VTKTYPE_LGTH];
98   };
99   
100   class MEDStructuredMeshMultiLev;
101   
102   class MEDUMeshMultiLev : public MEDMeshMultiLev
103   {
104   public:
105     static MEDUMeshMultiLev *New(const MEDFileUMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception);
106     static MEDUMeshMultiLev *New(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities) throw(INTERP_KERNEL::Exception);
107     void selectPartOfNodes(const DataArrayInt *pflNodes) throw(INTERP_KERNEL::Exception);
108     MEDMeshMultiLev *prepare() const throw(INTERP_KERNEL::Exception);
109     MEDUMeshMultiLev(const MEDStructuredMeshMultiLev& other, const MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh>& part);
110     MEDLOADER_EXPORT void buildVTUArrays(DataArrayDouble *& coords, DataArrayByte *&types, DataArrayInt *&cellLocations, DataArrayInt *& cells, DataArrayInt *&faceLocations, DataArrayInt *&faces) const throw(INTERP_KERNEL::Exception);
111   private:
112     void reorderNodesIfNecessary(MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>& coords, DataArrayInt *nodalConnVTK, DataArrayInt *polyhedNodalConnVTK) const throw(INTERP_KERNEL::Exception);
113   private:
114     MEDUMeshMultiLev(const MEDUMeshMultiLev& other);
115     MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<int>& levs);
116     MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
117   private:
118     std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> > _parts;
119   };
120
121   class MEDStructuredMeshMultiLev : public MEDMeshMultiLev
122   {
123   public:
124     void selectPartOfNodes(const DataArrayInt *pflNodes) throw(INTERP_KERNEL::Exception);
125     virtual std::vector<int> getNodeGridStructure() const throw(INTERP_KERNEL::Exception) = 0;
126   protected:
127     MEDStructuredMeshMultiLev();
128     MEDStructuredMeshMultiLev(const MEDStructuredMeshMultiLev& other);
129     MEDStructuredMeshMultiLev(const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
130   };
131   
132   class MEDCMeshMultiLev : public MEDStructuredMeshMultiLev
133   {
134   public:
135     static MEDCMeshMultiLev *New(const MEDFileCMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception);
136     static MEDCMeshMultiLev *New(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities) throw(INTERP_KERNEL::Exception);
137     std::vector<int> getNodeGridStructure() const throw(INTERP_KERNEL::Exception);
138     MEDMeshMultiLev *prepare() const throw(INTERP_KERNEL::Exception);
139     MEDLOADER_EXPORT std::vector< DataArrayDouble * > buildVTUArrays() const throw(INTERP_KERNEL::Exception);
140   private:
141     MEDCMeshMultiLev(const MEDCMeshMultiLev& other);
142     MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<int>& levs);
143     MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
144   private:
145     std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > _coords;
146   };
147
148   class MEDCurveLinearMeshMultiLev : public MEDStructuredMeshMultiLev
149   {
150   public:
151     static MEDCurveLinearMeshMultiLev *New(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception);
152     static MEDCurveLinearMeshMultiLev *New(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls , const std::vector<int>& nbEntities) throw(INTERP_KERNEL::Exception);
153     std::vector<int> getNodeGridStructure() const throw(INTERP_KERNEL::Exception);
154     MEDMeshMultiLev *prepare() const throw(INTERP_KERNEL::Exception);
155     MEDLOADER_EXPORT void buildVTUArrays(DataArrayDouble *&coords, std::vector<int>& nodeStrct) const throw(INTERP_KERNEL::Exception);
156   private:
157     MEDCurveLinearMeshMultiLev(const MEDCurveLinearMeshMultiLev& other);
158     MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs);
159     MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
160   private:
161     MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
162     std::vector<int> _structure;
163   };
164
165   class MEDFileField1TSStructItem2 : public RefCountObject
166   {
167   public:
168     MEDFileField1TSStructItem2();
169     MEDFileField1TSStructItem2(INTERP_KERNEL::NormalizedCellType a, const std::pair<int,int>& b, const std::string& pfl, const std::string& loc);
170     void checkWithMeshStructForCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception);
171     void checkWithMeshStructForGaussNE(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception);
172     void checkWithMeshStructForGaussPT(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception);
173     //
174     MEDLOADER_EXPORT std::size_t getHeapMemorySize() const;
175     //
176     const DataArrayInt *getPfl(const MEDFileFieldGlobsReal *globs) const;
177     INTERP_KERNEL::NormalizedCellType getGeo() const { return _geo_type; }
178     int getNbEntity() const { return _nb_of_entity; }
179     const std::pair<int,int>& getStartStop() const { return _start_end; }
180     std::string getPflName() const;
181     int getNbOfIntegrationPts(const MEDFileFieldGlobsReal *globs) const;
182     //! warning this method also set _nb_of_entity attribute !
183     void checkInRange(int nbOfEntity, int nip, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception);
184     bool isFastlyEqual(int& startExp, INTERP_KERNEL::NormalizedCellType gt, const char *pflName) const;
185     bool operator==(const MEDFileField1TSStructItem2& other) const throw(INTERP_KERNEL::Exception);
186     bool isCellSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception);
187     bool isNodeSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception);
188     static MEDFileField1TSStructItem2 BuildAggregationOf(const std::vector<const MEDFileField1TSStructItem2 *>& objs, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception);
189   public:
190     static const char NEWLY_CREATED_PFL_NAME[];
191   private:
192     INTERP_KERNEL::NormalizedCellType _geo_type;
193     std::pair<int,int> _start_end;
194     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _pfl;
195     std::string _loc;
196     int _nb_of_entity;
197   };
198
199   class MEDFileField1TSStructItem : public RefCountObject
200   {
201   public:
202     MEDFileField1TSStructItem() { }
203     MEDFileField1TSStructItem(TypeOfField a, const std::vector< MEDFileField1TSStructItem2 >& b);
204     void checkWithMeshStruct(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception);
205     bool operator==(const MEDFileField1TSStructItem& other) const throw(INTERP_KERNEL::Exception);
206     MEDLOADER_EXPORT std::size_t getHeapMemorySize() const;
207     bool isEntityCell() const;
208     bool isComputed() const { return _computed; }
209     TypeOfField getType() const { return _type; }
210     std::size_t getNumberOfItems() const { return _items.size(); }
211     const MEDFileField1TSStructItem2& operator[](std::size_t i) const throw(INTERP_KERNEL::Exception);
212     //
213     bool isCellSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception);
214     bool isNodeSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception);
215     MEDFileField1TSStructItem simplifyMeOnCellEntity(const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception);
216     bool isCompatibleWithNodesDiscr(const MEDFileField1TSStructItem& other, const MEDFileMeshStruct *meshSt, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception);
217     bool isFullyOnOneLev(const MEDFileMeshStruct *meshSt, int& theFirstLevFull) const throw(INTERP_KERNEL::Exception);
218     MEDLOADER_EXPORT MEDMeshMultiLev *buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception);
219     MEDLOADER_EXPORT static MEDFileField1TSStructItem BuildItemFrom(const MEDFileAnyTypeField1TS *ref, const MEDFileMeshStruct *meshSt);
220   private:
221     bool _computed;
222     TypeOfField _type;
223     std::vector< MEDFileField1TSStructItem2 > _items;
224   };
225
226   class MEDFileField1TSStruct : public RefCountObject
227   {
228   public:
229     static MEDFileField1TSStruct *New(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst) throw(INTERP_KERNEL::Exception);
230     void checkWithMeshStruct(MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception);
231     std::size_t getHeapMemorySize() const;
232     bool isEqualConsideringThePast(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *mst) const throw(INTERP_KERNEL::Exception);
233     bool isSupportSameAs(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt) throw(INTERP_KERNEL::Exception);
234     bool isCompatibleWithNodesDiscr(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt) throw(INTERP_KERNEL::Exception);
235     MEDLOADER_EXPORT MEDMeshMultiLev *buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception);
236     bool isDataSetSupportFastlyEqualTo(const MEDFileField1TSStruct& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception);
237   private:
238     MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst);
239     bool presenceOfCellDiscr(int& pos) const throw(INTERP_KERNEL::Exception);
240     bool presenceOfPartialNodeDiscr(int& pos) const throw(INTERP_KERNEL::Exception);
241   private:
242     std::vector<MEDFileField1TSStructItem> _already_checked;
243   };
244
245   class MEDFileFastCellSupportComparator : public RefCountObject
246   {
247   public:
248     MEDLOADER_EXPORT static MEDFileFastCellSupportComparator *New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref) throw(INTERP_KERNEL::Exception);
249     MEDLOADER_EXPORT MEDMeshMultiLev *buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception);
250     MEDLOADER_EXPORT bool isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception);
251     bool isEqual(const MEDFileAnyTypeFieldMultiTS *other) throw(INTERP_KERNEL::Exception);
252     bool isCompatibleWithNodesDiscr(const MEDFileAnyTypeFieldMultiTS *other) throw(INTERP_KERNEL::Exception);
253     std::size_t getHeapMemorySize() const;
254   private:
255     MEDFileFastCellSupportComparator(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref);
256   private:
257     MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> _mesh_comp;
258     std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct> > _f1ts_cmps;
259   };
260 }
261
262 #endif