1 // Copyright (C) 2007-2023 CEA, EDF
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::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;
64 void appendIfImplicitType(INTERP_KERNEL::NormalizedCellType t);
66 MEDFileMeshStruct(const MEDFileMesh *mesh);
68 const MEDFileMesh *_mesh;
71 std::vector< std::vector<mcIdType> > _geo_types_distrib;
74 class MEDFileField1TSStructItem;
76 class MEDMeshMultiLev : public RefCountObject
79 std::size_t getHeapMemorySizeWithoutChildren() const;
80 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
81 std::string getClassName() const override { return std::string("MEDMeshMultiLev"); }
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;
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);
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);
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;
120 MCAuto<DataArrayIdType> _cell_fam_ids;
121 MCAuto<DataArrayIdType> _cell_num_ids;
122 MCAuto<DataArrayIdType> _node_fam_ids;
123 MCAuto<DataArrayIdType> _node_num_ids;
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];
130 class MEDStructuredMeshMultiLev;
132 class MEDUMeshMultiLev : public MEDMeshMultiLev
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;
143 void appendVertices(const DataArrayIdType *verticesToAdd, DataArrayIdType *nr);
145 void reorderNodesIfNecessary(MCAuto<DataArrayDouble>& coords, DataArrayIdType *nodalConnVTK, DataArrayIdType *polyhedNodalConnVTK) const;
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);
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;
156 class MEDStructuredMeshMultiLev : public MEDMeshMultiLev
159 void selectPartOfNodes(const DataArrayIdType *pflNodes);
160 virtual std::vector<mcIdType> getNodeGridStructure() const = 0;
161 std::string getClassName() const override { return std::string("MEDStructuredMeshMultiLev"); }
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);
168 void moveFaceToCell() const;
169 bool prepareForImplicitUnstructuredMeshCase(MEDMeshMultiLev *&ret) const;
171 void initStdFieldOfIntegers(const MEDFileStructuredMesh *m);
174 MCAuto<DataArrayIdType> _face_fam_ids;
175 MCAuto<DataArrayIdType> _face_num_ids;
178 class MEDCMeshMultiLev : public MEDStructuredMeshMultiLev
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;
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);
192 std::vector< MCAuto<DataArrayDouble> > _coords;
195 class MEDCurveLinearMeshMultiLev : public MEDStructuredMeshMultiLev
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;
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);
209 MCAuto<DataArrayDouble> _coords;
210 std::vector<mcIdType> _structure;
213 class MEDFileField1TSStructItem2 : public BigMemoryObject
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);
223 MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
224 MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
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);
240 static const char NEWLY_CREATED_PFL_NAME[];
242 INTERP_KERNEL::NormalizedCellType _geo_type;
243 std::pair<mcIdType,mcIdType> _start_end;
244 MCAuto<DataArrayIdType> _pfl;
246 mcIdType _nb_of_entity;
249 class MEDFileField1TSStructItem : public BigMemoryObject
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;
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);
276 std::vector< MEDFileField1TSStructItem2 > _items;
279 class MEDFileField1TSStruct : public RefCountObject
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;
294 MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst);
295 bool presenceOfCellDiscr(int& pos) const;
296 bool presenceOfPartialNodeDiscr(int& pos) const;
298 std::vector<MEDFileField1TSStructItem> _already_checked;
301 class MEDFileFastCellSupportComparator : public RefCountObject
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;
315 MEDFileFastCellSupportComparator(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref);
317 MCAuto<MEDFileMeshStruct> _mesh_comp;
318 std::vector< MCAuto<MEDFileField1TSStruct> > _f1ts_cmps;