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