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