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