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