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