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