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