Salome HOME
Win32 compatibility
[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 *> getDirectChildren() 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 *> getDirectChildren() 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, bool isNoCopy);
94     void setNumberIdsOnCells(DataArrayInt *numIds, bool isNoCopy);
95     void setFamilyIdsOnNodes(DataArrayInt *famIds, bool isNoCopy);
96     void setNumberIdsOnNodes(DataArrayInt *numIds, bool isNoCopy);
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     bool _cell_fam_ids_nocpy;
119     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _cell_num_ids;
120     bool _cell_num_ids_nocpy;
121     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _node_fam_ids;
122     bool _node_fam_ids_nocpy;
123     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _node_num_ids;
124     bool _node_num_ids_nocpy;
125   public:
126     MEDLOADER_EXPORT static const int PARAMEDMEM_2_VTKTYPE_LGTH=34;
127     MEDLOADER_EXPORT static const unsigned char PARAMEDMEM_2_VTKTYPE[PARAMEDMEM_2_VTKTYPE_LGTH];
128     MEDLOADER_EXPORT static const unsigned char HEXA27_PERM_ARRAY[27];
129   };
130
131   class MEDStructuredMeshMultiLev;
132
133   class MEDUMeshMultiLev : public MEDMeshMultiLev
134   {
135   public:
136     static MEDUMeshMultiLev *New(const MEDFileUMesh *m, const std::vector<int>& levs);
137     static MEDUMeshMultiLev *New(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
138     void selectPartOfNodes(const DataArrayInt *pflNodes);
139     MEDMeshMultiLev *prepare() const;
140     MEDUMeshMultiLev(const MEDStructuredMeshMultiLev& other, const MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh>& part);
141     MEDLOADER_EXPORT bool buildVTUArrays(DataArrayDouble *& coords, DataArrayByte *&types, DataArrayInt *&cellLocations, DataArrayInt *& cells, DataArrayInt *&faceLocations, DataArrayInt *&faces) const;
142   protected:
143     void appendVertices(const DataArrayInt *verticesToAdd, DataArrayInt *nr);
144   private:
145     void reorderNodesIfNecessary(MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>& coords, DataArrayInt *nodalConnVTK, DataArrayInt *polyhedNodalConnVTK) const;
146   private:
147     MEDUMeshMultiLev(const MEDUMeshMultiLev& other);
148     MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<int>& levs);
149     MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
150   private:
151     std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> > _parts;
152     //! 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.
153     MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
154   };
155
156   class MEDStructuredMeshMultiLev : public MEDMeshMultiLev
157   {
158   public:
159     void selectPartOfNodes(const DataArrayInt *pflNodes);
160     virtual std::vector<int> getNodeGridStructure() const = 0;
161   protected:
162     MEDStructuredMeshMultiLev(const MEDStructuredMeshMultiLev& other);
163     MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, const std::vector<int>& lev);
164     MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, int nbOfNodes, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
165     void dealWithImplicitUnstructuredMesh(const MEDFileMesh *m);
166   protected:
167     void moveFaceToCell() const;
168     bool prepareForImplicitUnstructuredMeshCase(MEDMeshMultiLev *&ret) const;
169   private:
170     void initStdFieldOfIntegers(const MEDFileStructuredMesh *m);
171   protected:
172     bool _is_internal;
173     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _face_fam_ids;
174     bool _face_fam_ids_nocpy;
175     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _face_num_ids;
176     bool _face_num_ids_nocpy;
177   };
178
179   class MEDCMeshMultiLev : public MEDStructuredMeshMultiLev
180   {
181   public:
182     static MEDCMeshMultiLev *New(const MEDFileCMesh *m, const std::vector<int>& levs);
183     static MEDCMeshMultiLev *New(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
184     std::vector<int> getNodeGridStructure() const;
185     MEDMeshMultiLev *prepare() const;
186     MEDLOADER_EXPORT std::vector< DataArrayDouble * > buildVTUArrays(bool& isInternal) const;
187   private:
188     MEDCMeshMultiLev(const MEDCMeshMultiLev& other);
189     MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<int>& levs);
190     MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
191   private:
192     std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > _coords;
193   };
194
195   class MEDCurveLinearMeshMultiLev : public MEDStructuredMeshMultiLev
196   {
197   public:
198     static MEDCurveLinearMeshMultiLev *New(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs);
199     static MEDCurveLinearMeshMultiLev *New(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls , const std::vector<int>& nbEntities);
200     std::vector<int> getNodeGridStructure() const;
201     MEDMeshMultiLev *prepare() const;
202     MEDLOADER_EXPORT void buildVTUArrays(DataArrayDouble *&coords, std::vector<int>& nodeStrct, bool& isInternal) const;
203   private:
204     MEDCurveLinearMeshMultiLev(const MEDCurveLinearMeshMultiLev& other);
205     MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs);
206     MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
207   private:
208     MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
209     std::vector<int> _structure;
210   };
211
212   class MEDFileField1TSStructItem2 : public BigMemoryObject
213   {
214   public:
215     MEDFileField1TSStructItem2();
216     MEDFileField1TSStructItem2(INTERP_KERNEL::NormalizedCellType a, const std::pair<int,int>& b, const std::string& pfl, const std::string& loc);
217     void checkWithMeshStructForCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs);
218     void checkWithMeshStructForGaussNE(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs);
219     void checkWithMeshStructForGaussPT(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs);
220     //
221     MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
222     MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildren() const;
223     //
224     const DataArrayInt *getPfl(const MEDFileFieldGlobsReal *globs) const;
225     INTERP_KERNEL::NormalizedCellType getGeo() const { return _geo_type; }
226     int getNbEntity() const { return _nb_of_entity; }
227     const std::pair<int,int>& getStartStop() const { return _start_end; }
228     std::string getPflName() const;
229     int getNbOfIntegrationPts(const MEDFileFieldGlobsReal *globs) const;
230     //! warning this method also set _nb_of_entity attribute !
231     void checkInRange(int nbOfEntity, int nip, const MEDFileFieldGlobsReal *globs);
232     bool isFastlyEqual(int& startExp, INTERP_KERNEL::NormalizedCellType gt, const std::string& pflName) const;
233     bool operator==(const MEDFileField1TSStructItem2& other) const;
234     bool isCellSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const;
235     bool isNodeSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const;
236     static MEDFileField1TSStructItem2 BuildAggregationOf(const std::vector<const MEDFileField1TSStructItem2 *>& objs, const MEDFileFieldGlobsReal *globs);
237   public:
238     static const char NEWLY_CREATED_PFL_NAME[];
239   private:
240     INTERP_KERNEL::NormalizedCellType _geo_type;
241     std::pair<int,int> _start_end;
242     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _pfl;
243     std::string _loc;
244     int _nb_of_entity;
245   };
246
247   class MEDFileField1TSStructItem : public BigMemoryObject
248   {
249   public:
250     MEDFileField1TSStructItem() { }
251     MEDFileField1TSStructItem(TypeOfField a, const std::vector< MEDFileField1TSStructItem2 >& b);
252     void checkWithMeshStruct(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs);
253     bool operator==(const MEDFileField1TSStructItem& other) const;
254     MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
255     MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildren() const;
256     bool isEntityCell() const;
257     bool isComputed() const { return _computed; }
258     TypeOfField getType() const { return _type; }
259     std::size_t getNumberOfItems() const { return _items.size(); }
260     const MEDFileField1TSStructItem2& operator[](std::size_t i) const;
261     //
262     bool isCellSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const;
263     bool isNodeSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const;
264     MEDFileField1TSStructItem simplifyMeOnCellEntity(const MEDFileFieldGlobsReal *globs) const;
265     bool isCompatibleWithNodesDiscr(const MEDFileField1TSStructItem& other, const MEDFileMeshStruct *meshSt, const MEDFileFieldGlobsReal *globs) const;
266     bool isFullyOnOneLev(const MEDFileMeshStruct *meshSt, int& theFirstLevFull) const;
267     std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes(const MEDFileMesh *m) const;
268     MEDLOADER_EXPORT MEDMeshMultiLev *buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const;
269     MEDLOADER_EXPORT static MEDFileField1TSStructItem BuildItemFrom(const MEDFileAnyTypeField1TS *ref, const MEDFileMeshStruct *meshSt);
270   private:
271     bool _computed;
272     TypeOfField _type;
273     std::vector< MEDFileField1TSStructItem2 > _items;
274   };
275
276   class MEDFileField1TSStruct : public RefCountObject
277   {
278   public:
279     static MEDFileField1TSStruct *New(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst);
280     void checkWithMeshStruct(MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs);
281     std::size_t getHeapMemorySizeWithoutChildren() const;
282     std::vector<const BigMemoryObject *> getDirectChildren() const;
283     bool isEqualConsideringThePast(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *mst) const;
284     bool isSupportSameAs(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt);
285     bool isCompatibleWithNodesDiscr(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt);
286     MEDLOADER_EXPORT MEDMeshMultiLev *buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const;
287     bool isDataSetSupportFastlyEqualTo(const MEDFileField1TSStruct& other, const MEDFileFieldGlobsReal *globs) const;
288     std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes(const MEDFileMesh *m) const;
289   private:
290     MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst);
291     bool presenceOfCellDiscr(int& pos) const;
292     bool presenceOfPartialNodeDiscr(int& pos) const;
293   private:
294     std::vector<MEDFileField1TSStructItem> _already_checked;
295   };
296
297   class MEDFileFastCellSupportComparator : public RefCountObject
298   {
299   public:
300     MEDLOADER_EXPORT static MEDFileFastCellSupportComparator *New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref);
301     MEDLOADER_EXPORT MEDMeshMultiLev *buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const;
302     MEDLOADER_EXPORT bool isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const;
303     MEDLOADER_EXPORT int getNumberOfTS() const;
304     MEDLOADER_EXPORT std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypesAt(int timeStepId, const MEDFileMesh *m) const;
305     bool isEqual(const MEDFileAnyTypeFieldMultiTS *other);
306     bool isCompatibleWithNodesDiscr(const MEDFileAnyTypeFieldMultiTS *other);
307     std::size_t getHeapMemorySizeWithoutChildren() const;
308     std::vector<const BigMemoryObject *> getDirectChildren() const;
309   private:
310     MEDFileFastCellSupportComparator(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref);
311   private:
312     MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> _mesh_comp;
313     std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct> > _f1ts_cmps;
314   };
315 }
316
317 #endif