1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #ifndef __MEDFILEFIELDOVERVIEW_HXX__
22 #define __MEDFILEFIELDOVERVIEW_HXX__
24 #include "MEDLoaderDefines.hxx"
27 #include "MEDCouplingRefCountObject.hxx"
28 #include "MEDCoupling1GTUMesh.hxx"
30 #include "NormalizedUnstructuredMesh.hxx"
31 #include "InterpKernelException.hxx"
38 class MEDCouplingMesh;
42 class MEDFileStructuredMesh;
43 class MEDFileCurveLinearMesh;
44 class MEDFileFieldGlobs;
45 class MEDFileFieldGlobsReal;
46 class MEDFileAnyTypeField1TS;
47 class MEDFileAnyTypeFieldMultiTS;
49 class MEDFileMeshStruct : public RefCountObject
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;
63 void appendIfImplicitType(INTERP_KERNEL::NormalizedCellType t);
65 MEDFileMeshStruct(const MEDFileMesh *mesh);
67 const MEDFileMesh *_mesh;
70 std::vector< std::vector<int> > _geo_types_distrib;
73 class MEDFileField1TSStructItem;
75 class MEDMeshMultiLev : public RefCountObject
78 std::size_t getHeapMemorySizeWithoutChildren() const;
79 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
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 DataArrayInt *retrieveGlobalNodeIdsIfAny() const;
93 MEDLOADER_EXPORT std::vector< INTERP_KERNEL::NormalizedCellType > getGeoTypes() const;
94 void setFamilyIdsOnCells(DataArrayInt *famIds);
95 void setNumberIdsOnCells(DataArrayInt *numIds);
96 void setFamilyIdsOnNodes(DataArrayInt *famIds);
97 void setNumberIdsOnNodes(DataArrayInt *numIds);
98 virtual void selectPartOfNodes(const DataArrayInt *pflNodes) = 0;
99 virtual MEDMeshMultiLev *prepare() const = 0;
100 int getNumberOfCells(INTERP_KERNEL::NormalizedCellType t) const;
101 int getNumberOfNodes() const;
103 std::string getPflNameOfId(int id) const;
104 DataArray *constructDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const;
105 virtual void appendVertices(const DataArrayInt *verticesToAdd, DataArrayInt *nr);
107 MEDMeshMultiLev(const MEDFileMesh *mesh);
108 MEDMeshMultiLev(const MEDMeshMultiLev& other);
109 MEDMeshMultiLev(const MEDFileMesh *mesh, int nbNodes, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
111 const MEDFileMesh *_mesh;
112 std::vector< MCAuto<DataArrayInt> > _pfls;
113 std::vector< INTERP_KERNEL::NormalizedCellType > _geo_types;
114 std::vector<int> _nb_entities;
115 MCAuto<DataArrayInt> _node_reduction;
118 MCAuto<DataArrayInt> _cell_fam_ids;
119 MCAuto<DataArrayInt> _cell_num_ids;
120 MCAuto<DataArrayInt> _node_fam_ids;
121 MCAuto<DataArrayInt> _node_num_ids;
123 MEDLOADER_EXPORT static const int PARAMEDMEM_2_VTKTYPE_LGTH=34;
124 MEDLOADER_EXPORT static const unsigned char PARAMEDMEM_2_VTKTYPE[PARAMEDMEM_2_VTKTYPE_LGTH];
125 MEDLOADER_EXPORT static const unsigned char HEXA27_PERM_ARRAY[27];
128 class MEDStructuredMeshMultiLev;
130 class MEDUMeshMultiLev : public MEDMeshMultiLev
133 static MEDUMeshMultiLev *New(const MEDFileUMesh *m, const std::vector<int>& levs);
134 static MEDUMeshMultiLev *New(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
135 void selectPartOfNodes(const DataArrayInt *pflNodes);
136 MEDMeshMultiLev *prepare() const;
137 MEDUMeshMultiLev(const MEDStructuredMeshMultiLev& other, const MCAuto<MEDCoupling1GTUMesh>& part);
138 MEDLOADER_EXPORT bool buildVTUArrays(DataArrayDouble *& coords, DataArrayByte *&types, DataArrayInt *&cellLocations, DataArrayInt *& cells, DataArrayInt *&faceLocations, DataArrayInt *&faces) const;
140 void appendVertices(const DataArrayInt *verticesToAdd, DataArrayInt *nr);
142 void reorderNodesIfNecessary(MCAuto<DataArrayDouble>& coords, DataArrayInt *nodalConnVTK, DataArrayInt *polyhedNodalConnVTK) const;
144 MEDUMeshMultiLev(const MEDUMeshMultiLev& other);
145 MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<int>& levs);
146 MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
148 std::vector< MCAuto<MEDCoupling1GTUMesh> > _parts;
149 //! 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.
150 MCAuto<DataArrayDouble> _coords;
153 class MEDStructuredMeshMultiLev : public MEDMeshMultiLev
156 void selectPartOfNodes(const DataArrayInt *pflNodes);
157 virtual std::vector<int> getNodeGridStructure() const = 0;
159 MEDStructuredMeshMultiLev(const MEDStructuredMeshMultiLev& other);
160 MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, const std::vector<int>& lev);
161 MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, int nbOfNodes, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
162 void dealWithImplicitUnstructuredMesh(const MEDFileMesh *m);
164 void moveFaceToCell() const;
165 bool prepareForImplicitUnstructuredMeshCase(MEDMeshMultiLev *&ret) const;
167 void initStdFieldOfIntegers(const MEDFileStructuredMesh *m);
170 MCAuto<DataArrayInt> _face_fam_ids;
171 MCAuto<DataArrayInt> _face_num_ids;
174 class MEDCMeshMultiLev : public MEDStructuredMeshMultiLev
177 static MEDCMeshMultiLev *New(const MEDFileCMesh *m, const std::vector<int>& levs);
178 static MEDCMeshMultiLev *New(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
179 std::vector<int> getNodeGridStructure() const;
180 MEDMeshMultiLev *prepare() const;
181 MEDLOADER_EXPORT std::vector< DataArrayDouble * > buildVTUArrays(bool& isInternal) const;
183 MEDCMeshMultiLev(const MEDCMeshMultiLev& other);
184 MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<int>& levs);
185 MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
187 std::vector< MCAuto<DataArrayDouble> > _coords;
190 class MEDCurveLinearMeshMultiLev : public MEDStructuredMeshMultiLev
193 static MEDCurveLinearMeshMultiLev *New(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs);
194 static MEDCurveLinearMeshMultiLev *New(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls , const std::vector<int>& nbEntities);
195 std::vector<int> getNodeGridStructure() const;
196 MEDMeshMultiLev *prepare() const;
197 MEDLOADER_EXPORT void buildVTUArrays(DataArrayDouble *&coords, std::vector<int>& nodeStrct, bool& isInternal) const;
199 MEDCurveLinearMeshMultiLev(const MEDCurveLinearMeshMultiLev& other);
200 MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs);
201 MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
203 MCAuto<DataArrayDouble> _coords;
204 std::vector<int> _structure;
207 class MEDFileField1TSStructItem2 : public BigMemoryObject
210 MEDFileField1TSStructItem2();
211 MEDFileField1TSStructItem2(INTERP_KERNEL::NormalizedCellType a, const std::pair<int,int>& b, const std::string& pfl, const std::string& loc);
212 void checkWithMeshStructForCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs);
213 void checkWithMeshStructForGaussNE(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs);
214 void checkWithMeshStructForGaussPT(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs);
216 MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
217 MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
219 const DataArrayInt *getPfl(const MEDFileFieldGlobsReal *globs) const;
220 INTERP_KERNEL::NormalizedCellType getGeo() const { return _geo_type; }
221 int getNbEntity() const { return _nb_of_entity; }
222 const std::pair<int,int>& getStartStop() const { return _start_end; }
223 std::string getPflName() const;
224 int getNbOfIntegrationPts(const MEDFileFieldGlobsReal *globs) const;
225 //! warning this method also set _nb_of_entity attribute !
226 void checkInRange(int nbOfEntity, int nip, const MEDFileFieldGlobsReal *globs);
227 bool isFastlyEqual(int& startExp, INTERP_KERNEL::NormalizedCellType gt, const std::string& pflName) const;
228 bool operator==(const MEDFileField1TSStructItem2& other) const;
229 bool isCellSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const;
230 bool isNodeSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const;
231 static MEDFileField1TSStructItem2 BuildAggregationOf(const std::vector<const MEDFileField1TSStructItem2 *>& objs, const MEDFileFieldGlobsReal *globs);
233 static const char NEWLY_CREATED_PFL_NAME[];
235 INTERP_KERNEL::NormalizedCellType _geo_type;
236 std::pair<int,int> _start_end;
237 MCAuto<DataArrayInt> _pfl;
242 class MEDFileField1TSStructItem : public BigMemoryObject
245 MEDFileField1TSStructItem():_computed(false),_type(ON_CELLS) { }
246 MEDFileField1TSStructItem(TypeOfField a, const std::vector< MEDFileField1TSStructItem2 >& b);
247 void checkWithMeshStruct(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs);
248 bool operator==(const MEDFileField1TSStructItem& other) const;
249 MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
250 MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
251 bool isEntityCell() const;
252 bool isComputed() const { return _computed; }
253 TypeOfField getType() const { return _type; }
254 std::size_t getNumberOfItems() const { return _items.size(); }
255 const MEDFileField1TSStructItem2& operator[](std::size_t i) const;
257 bool isCellSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const;
258 bool isNodeSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const;
259 MEDFileField1TSStructItem simplifyMeOnCellEntity(const MEDFileFieldGlobsReal *globs) const;
260 bool isCompatibleWithNodesDiscr(const MEDFileField1TSStructItem& other, const MEDFileMeshStruct *meshSt, const MEDFileFieldGlobsReal *globs) const;
261 bool isFullyOnOneLev(const MEDFileMeshStruct *meshSt, int& theFirstLevFull) const;
262 std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes(const MEDFileMesh *m) const;
263 MEDLOADER_EXPORT MEDMeshMultiLev *buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const;
264 MEDLOADER_EXPORT static MEDFileField1TSStructItem BuildItemFrom(const MEDFileAnyTypeField1TS *ref, const MEDFileMeshStruct *meshSt);
268 std::vector< MEDFileField1TSStructItem2 > _items;
271 class MEDFileField1TSStruct : public RefCountObject
274 static MEDFileField1TSStruct *New(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst);
275 void checkWithMeshStruct(MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs);
276 std::size_t getHeapMemorySizeWithoutChildren() const;
277 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
278 bool isEqualConsideringThePast(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *mst) const;
279 bool isSupportSameAs(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt);
280 bool isCompatibleWithNodesDiscr(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt);
281 MEDLOADER_EXPORT MEDMeshMultiLev *buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const;
282 bool isDataSetSupportFastlyEqualTo(const MEDFileField1TSStruct& other, const MEDFileFieldGlobsReal *globs) const;
283 std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes(const MEDFileMesh *m) const;
285 MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst);
286 bool presenceOfCellDiscr(int& pos) const;
287 bool presenceOfPartialNodeDiscr(int& pos) const;
289 std::vector<MEDFileField1TSStructItem> _already_checked;
292 class MEDFileFastCellSupportComparator : public RefCountObject
295 MEDLOADER_EXPORT static MEDFileFastCellSupportComparator *New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref);
296 MEDLOADER_EXPORT MEDMeshMultiLev *buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const;
297 MEDLOADER_EXPORT bool isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const;
298 MEDLOADER_EXPORT int getNumberOfTS() const;
299 MEDLOADER_EXPORT std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypesAt(int timeStepId, const MEDFileMesh *m) const;
300 bool isEqual(const MEDFileAnyTypeFieldMultiTS *other);
301 bool isCompatibleWithNodesDiscr(const MEDFileAnyTypeFieldMultiTS *other);
302 std::size_t getHeapMemorySizeWithoutChildren() const;
303 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
305 MEDFileFastCellSupportComparator(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref);
307 MCAuto<MEDFileMeshStruct> _mesh_comp;
308 std::vector< MCAuto<MEDFileField1TSStruct> > _f1ts_cmps;