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