Salome HOME
02e3bfc27aaa9fcf8310476f8b1ff7c55cc7c567
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingMesh.hxx
1 // Copyright (C) 2007-2019  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 __PARAMEDMEM_MEDCOUPLINGMESH_HXX__
22 #define __PARAMEDMEM_MEDCOUPLINGMESH_HXX__
23
24 #include "MEDCoupling.hxx"
25 #include "MCType.hxx"
26 #include "MEDCouplingTimeLabel.hxx"
27 #include "MEDCouplingRefCountObject.hxx"
28 #include "NormalizedUnstructuredMesh.hxx"
29 #include "MCAuto.hxx"
30
31 #include "InterpKernelException.hxx"
32
33 #include <set>
34 #include <vector>
35
36 namespace MEDCoupling
37 {
38   typedef enum
39     {
40       UNSTRUCTURED = 5,
41       CARTESIAN = 7,
42       EXTRUDED = 8,
43       CURVE_LINEAR = 9,
44       SINGLE_STATIC_GEO_TYPE_UNSTRUCTURED = 10,
45       SINGLE_DYNAMIC_GEO_TYPE_UNSTRUCTURED = 11,
46       IMAGE_GRID = 12
47     } MEDCouplingMeshType;
48   // -- WARNING this enum must be synchronized with MEDCouplingCommon.i file ! --
49
50   class DataArrayIdType;
51   class DataArrayByte;
52   class DataArrayDouble;
53   class MEDCouplingUMesh;
54   class MEDCouplingFieldDouble;
55
56   class MEDCouplingMesh : public RefCountObject, public TimeLabel
57   {
58   public:
59     MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
60     MEDCOUPLING_EXPORT void setName(const std::string& name) { _name=name; }
61     MEDCOUPLING_EXPORT std::string getName() const { return _name; }
62     MEDCOUPLING_EXPORT void setDescription(const std::string& descr) { _description=descr; }
63     MEDCOUPLING_EXPORT std::string getDescription() const { return _description; }
64     MEDCOUPLING_EXPORT double getTime(int& iteration, int& order) const { iteration=_iteration; order=_order; return _time; }
65     MEDCOUPLING_EXPORT void setTime(double val, int iteration, int order) { _time=val; _iteration=iteration; _order=order; }
66     MEDCOUPLING_EXPORT void setTimeUnit(const std::string& unit) { _time_unit=unit; }
67     MEDCOUPLING_EXPORT std::string getTimeUnit() const { return _time_unit; }
68     MEDCOUPLING_EXPORT virtual MEDCouplingMeshType getType() const = 0;
69     MEDCOUPLING_EXPORT bool isStructured() const;
70     // Copy methods
71     MEDCOUPLING_EXPORT virtual MEDCouplingMesh *deepCopy() const = 0;
72     MEDCOUPLING_EXPORT virtual MEDCouplingMesh *clone(bool recDeepCpy) const = 0;
73     MEDCOUPLING_EXPORT virtual void copyTinyStringsFrom(const MEDCouplingMesh *other);
74     MEDCOUPLING_EXPORT virtual void copyTinyInfoFrom(const MEDCouplingMesh *other);
75     // comparison methods
76     MEDCOUPLING_EXPORT virtual bool isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const;
77     MEDCOUPLING_EXPORT virtual bool isEqual(const MEDCouplingMesh *other, double prec) const;
78     MEDCOUPLING_EXPORT virtual bool isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const = 0;
79     MEDCOUPLING_EXPORT virtual void checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
80                                                          DataArrayIdType *&cellCor, DataArrayIdType *&nodeCor) const = 0;
81     MEDCOUPLING_EXPORT virtual void checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
82                                                                     DataArrayIdType *&cellCor) const = 0;
83     MEDCOUPLING_EXPORT virtual void checkFastEquivalWith(const MEDCouplingMesh *other, double prec) const;
84     MEDCOUPLING_EXPORT void checkGeoEquivalWith(const MEDCouplingMesh *other, int levOfCheck, double prec,
85                                                 DataArrayIdType *&cellCor, DataArrayIdType *&nodeCor) const;
86     //
87     MEDCOUPLING_EXPORT virtual void checkConsistencyLight() const = 0;
88     MEDCOUPLING_EXPORT virtual void checkConsistency(double eps=1e-12) const = 0;
89     MEDCOUPLING_EXPORT virtual mcIdType getNumberOfCells() const = 0;
90     MEDCOUPLING_EXPORT virtual mcIdType getNumberOfNodes() const = 0;
91     MEDCOUPLING_EXPORT virtual int getSpaceDimension() const = 0;
92     MEDCOUPLING_EXPORT virtual int getMeshDimension() const = 0;
93     MEDCOUPLING_EXPORT virtual DataArrayDouble *getCoordinatesAndOwner() const = 0;
94     MEDCOUPLING_EXPORT virtual DataArrayDouble *computeCellCenterOfMass() const = 0;
95     MEDCOUPLING_EXPORT virtual DataArrayDouble *computeIsoBarycenterOfNodesPerCell() const = 0;
96     MEDCOUPLING_EXPORT virtual DataArrayIdType *giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const = 0;
97     MEDCOUPLING_EXPORT virtual DataArrayIdType *computeNbOfNodesPerCell() const = 0;
98     MEDCOUPLING_EXPORT virtual DataArrayIdType *computeEffectiveNbOfNodesPerCell() const = 0;
99     MEDCOUPLING_EXPORT virtual DataArrayIdType *computeNbOfFacesPerCell() const = 0;
100     MEDCOUPLING_EXPORT virtual mcIdType getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const = 0;
101     MEDCOUPLING_EXPORT virtual INTERP_KERNEL::NormalizedCellType getTypeOfCell(mcIdType cellId) const = 0;
102     MEDCOUPLING_EXPORT virtual std::set<INTERP_KERNEL::NormalizedCellType> getAllGeoTypes() const = 0;
103     MEDCOUPLING_EXPORT virtual void getNodeIdsOfCell(mcIdType cellId, std::vector<mcIdType>& conn) const = 0;
104     MEDCOUPLING_EXPORT virtual DataArrayIdType *getCellIdsFullyIncludedInNodeIds(const mcIdType *partBg, const mcIdType *partEnd) const;
105     MEDCOUPLING_EXPORT virtual void getCoordinatesOfNode(mcIdType nodeId, std::vector<double>& coo) const = 0;
106     MEDCOUPLING_EXPORT virtual std::string simpleRepr() const = 0;
107     MEDCOUPLING_EXPORT virtual std::string advancedRepr() const = 0;
108     // tools
109     MEDCOUPLING_EXPORT virtual const DataArrayDouble *getDirectAccessOfCoordsArrIfInStructure() const = 0;
110     MEDCOUPLING_EXPORT virtual std::vector<mcIdType> getDistributionOfTypes() const = 0;
111     MEDCOUPLING_EXPORT virtual DataArrayIdType *checkTypeConsistencyAndContig(const std::vector<mcIdType>& code, const std::vector<const DataArrayIdType *>& idsPerType) const = 0;
112     MEDCOUPLING_EXPORT virtual void splitProfilePerType(const DataArrayIdType *profile, std::vector<mcIdType>& code, std::vector<DataArrayIdType *>& idsInPflPerType, std::vector<DataArrayIdType *>& idsPerType, bool smartPflKiller=true) const = 0;
113     MEDCOUPLING_EXPORT virtual void getBoundingBox(double *bbox) const = 0;
114     MEDCOUPLING_EXPORT virtual MEDCouplingFieldDouble *getMeasureField(bool isAbs) const = 0;
115     MEDCOUPLING_EXPORT virtual MEDCouplingFieldDouble *getMeasureFieldOnNode(bool isAbs) const = 0;
116     MEDCOUPLING_EXPORT virtual mcIdType getCellContainingPoint(const double *pos, double eps) const = 0;
117     MEDCOUPLING_EXPORT virtual void getCellsContainingPoint(const double *pos, double eps, std::vector<mcIdType>& elts) const = 0;
118     MEDCOUPLING_EXPORT virtual void getCellsContainingPoints(const double *pos, mcIdType nbOfPoints, double eps, MCAuto<DataArrayIdType>& elts, MCAuto<DataArrayIdType>& eltsIndex) const;
119     MEDCOUPLING_EXPORT virtual void getCellsContainingPointsLinearPartOnlyOnNonDynType(const double *pos, mcIdType nbOfPoints, double eps, MCAuto<DataArrayIdType>& elts, MCAuto<DataArrayIdType>& eltsIndex) const;
120     MEDCOUPLING_EXPORT virtual MEDCouplingFieldDouble *fillFromAnalytic(TypeOfField t, int nbOfComp, FunctionToEvaluate func) const;
121     MEDCOUPLING_EXPORT virtual MEDCouplingFieldDouble *fillFromAnalytic(TypeOfField t, int nbOfComp, const std::string& func) const;
122     MEDCOUPLING_EXPORT virtual MEDCouplingFieldDouble *fillFromAnalyticCompo(TypeOfField t, int nbOfComp, const std::string& func) const;
123     MEDCOUPLING_EXPORT virtual MEDCouplingFieldDouble *fillFromAnalyticNamedCompo(TypeOfField t, int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func) const;
124     MEDCOUPLING_EXPORT virtual MEDCouplingFieldDouble *buildOrthogonalField() const = 0;
125     MEDCOUPLING_EXPORT virtual void rotate(const double *center, const double *vector, double angle) = 0;
126     MEDCOUPLING_EXPORT virtual void translate(const double *vector) = 0;
127     MEDCOUPLING_EXPORT virtual void scale(const double *point, double factor) = 0;
128     MEDCOUPLING_EXPORT virtual void renumberCells(const mcIdType *old2NewBg, bool check=true) = 0;
129     MEDCOUPLING_EXPORT virtual MEDCouplingMesh *mergeMyselfWith(const MEDCouplingMesh *other) const = 0;
130     MEDCOUPLING_EXPORT virtual MEDCouplingMesh *buildPart(const mcIdType *start, const mcIdType *end) const = 0;
131     MEDCOUPLING_EXPORT virtual MEDCouplingMesh *buildPartAndReduceNodes(const mcIdType *start, const mcIdType *end, DataArrayIdType*& arr) const = 0;
132     MEDCOUPLING_EXPORT virtual MEDCouplingMesh *buildPartRange(mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds) const;
133     MEDCOUPLING_EXPORT virtual MEDCouplingMesh *buildPartRangeAndReduceNodes(mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds, mcIdType& beginOut, mcIdType& endOut, mcIdType& stepOut, DataArrayIdType*& arr) const;
134     MEDCOUPLING_EXPORT virtual MEDCouplingUMesh *buildUnstructured() const = 0;
135     MEDCOUPLING_EXPORT virtual DataArrayIdType *simplexize(int policy) = 0;
136     MEDCOUPLING_EXPORT virtual void getReverseNodalConnectivity(DataArrayIdType *revNodal, DataArrayIdType *revNodalIndx) const = 0;
137     MEDCOUPLING_EXPORT virtual bool areCompatibleForMerge(const MEDCouplingMesh *other) const;
138     MEDCOUPLING_EXPORT static MEDCouplingMesh *MergeMeshes(const MEDCouplingMesh *mesh1, const MEDCouplingMesh *mesh2);
139     MEDCOUPLING_EXPORT static MEDCouplingMesh *MergeMeshes(std::vector<const MEDCouplingMesh *>& meshes);
140     MEDCOUPLING_EXPORT static bool IsStaticGeometricType(INTERP_KERNEL::NormalizedCellType type);
141     MEDCOUPLING_EXPORT static bool IsLinearGeometricType(INTERP_KERNEL::NormalizedCellType type);
142     MEDCOUPLING_EXPORT static INTERP_KERNEL::NormalizedCellType GetCorrespondingPolyType(INTERP_KERNEL::NormalizedCellType type);
143     MEDCOUPLING_EXPORT static mcIdType GetNumberOfNodesOfGeometricType(INTERP_KERNEL::NormalizedCellType type);
144     MEDCOUPLING_EXPORT static int GetDimensionOfGeometricType(INTERP_KERNEL::NormalizedCellType type);
145     MEDCOUPLING_EXPORT static const char *GetReprOfGeometricType(INTERP_KERNEL::NormalizedCellType type);
146     //serialisation-unserialization
147     MEDCOUPLING_EXPORT virtual void getTinySerializationInformation(std::vector<double>& tinyInfoD, std::vector<mcIdType>& tinyInfo, std::vector<std::string>& littleStrings) const = 0;
148     MEDCOUPLING_EXPORT virtual void resizeForUnserialization(const std::vector<mcIdType>& tinyInfo, DataArrayIdType *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings) const = 0;
149     MEDCOUPLING_EXPORT virtual void serialize(DataArrayIdType *&a1, DataArrayDouble *&a2) const = 0;
150     MEDCOUPLING_EXPORT virtual void unserialization(const std::vector<double>& tinyInfoD, const std::vector<mcIdType>& tinyInfo, const DataArrayIdType *a1, DataArrayDouble *a2,
151                                                     const std::vector<std::string>& littleStrings) = 0;
152     MEDCOUPLING_EXPORT std::string writeVTK(const std::string& fileName, bool isBinary=true) const;
153     MEDCOUPLING_EXPORT std::string getVTKFileNameOf(const std::string& fileName) const;
154     MEDCOUPLING_EXPORT virtual std::string getVTKFileExtension() const = 0;
155     /// @cond INTERNAL
156     MEDCOUPLING_EXPORT void writeVTKAdvanced(const std::string& fileName, const std::string& cda, const std::string& pda, DataArrayByte *byteData) const;
157     MEDCOUPLING_EXPORT static void SplitExtension(const std::string& fileName, std::string& baseName, std::string& extension);
158     /// @endcond
159     MEDCOUPLING_EXPORT virtual void writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const = 0;
160     MEDCOUPLING_EXPORT virtual void reprQuickOverview(std::ostream& stream) const = 0;
161   protected:
162     MEDCOUPLING_EXPORT MEDCouplingMesh();
163     MEDCOUPLING_EXPORT MEDCouplingMesh(const MEDCouplingMesh& other);
164     MEDCOUPLING_EXPORT virtual std::string getVTKDataSetType() const = 0;
165     MEDCOUPLING_EXPORT virtual ~MEDCouplingMesh() { }
166   private:
167     std::string _name;
168     std::string _description;
169     double _time;
170     int _iteration;
171     int _order;
172     std::string _time_unit;
173   };
174 }
175
176 #endif