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