Version: 9.16.0
SMDS_VolumeTool.hxx
Go to the documentation of this file.
1// Copyright (C) 2007-2026 CEA, EDF, OPEN CASCADE
2//
3// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5//
6// This library is free software; you can redistribute it and/or
7// modify it under the terms of the GNU Lesser General Public
8// License as published by the Free Software Foundation; either
9// version 2.1 of the License, or (at your option) any later version.
10//
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// Lesser General Public License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public
17// License along with this library; if not, write to the Free Software
18// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19//
20// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21//
22
23// SMESH SMDS : implementation of Salome mesh data structure
24// File : SMDS_VolumeTool.hxx
25// Module : SMESH
26// Created : Tue Jul 13 11:27:17 2004
27// Author : Edward AGAPOV (eap)
28//
29#ifndef SMDS_VolumeTool_HeaderFile
30#define SMDS_VolumeTool_HeaderFile
31
32#include "SMESH_SMDS.hxx"
33
34#include <smIdType.hxx>
35
37class SMDS_MeshNode;
38class SMDS_MeshVolume;
39
40#include <vector>
41#include <set>
42#include <map>
43
44// =========================================================================
45//
46// Class providing topological and other information about SMDS_MeshVolume:
47// allows iteration on faces or, to be precise, on nodes of volume sides;
48// provides info on nodes connection etc.
49//
50// =========================================================================
51
53{
54 public:
55
56 enum VolumeType { UNKNOWN = -1, TETRA = 0, PYRAM, PENTA, HEXA,
57 HEX_PRISM, QUAD_TETRA, QUAD_PYRAM, QUAD_PENTA, QUAD_HEXA,
58 POLYHEDA, NB_VOLUME_TYPES }; // to keep synchronised with GetSize()!
59
62 SMDS_VolumeTool( const SMDS_MeshElement* theVolume,
63 const bool ignoreCentralNodes = true);
64
65 bool Set( const SMDS_MeshElement* theVolume,
66 const bool ignoreCentralNodes = true,
67 const std::vector<const SMDS_MeshNode*>* nodes = 0);
68 // Set volume.
69 // Return false if theVolume is not of type SMDSAbs_Volume.
70 // ignoreCentralNodes makes skip nodes at face centers when returning
71 // nodes of faces of SMDSEntity_TriQuad_Hexa.
72 // alternative nodes can be provided
73
74 const SMDS_MeshVolume* Element() const;
75 // return element
76
77 smIdType ID() const;
78 // return element ID
79
80 bool IsPoly() const { return myPolyedre; }
81
82 // -----------------------
83 // general info
84 // -----------------------
85
86 VolumeType GetVolumeType() const;
87
88 bool IsForward() const { return myVolForward; }
89 // Check volume orientation. can be changed by Inverse().
90 // See node order of forward volumes at the file bottom
91
92 void Inverse();
93 // Change nodes order as if the volume changes its orientation:
94 // top and bottom faces are reversed.
95 // Result of IsForward() and methods returning nodes change
96
97 const SMDS_MeshNode** GetNodes() const { return (const SMDS_MeshNode**) &myVolumeNodes[0]; }
98 // Return array of volume nodes
99
100 int NbNodes() const { return (int) myVolumeNodes.size(); }
101 // Return number of volume nodes
102
103 double GetSize() const;
104 // Return element volume
105
106 double GetScaledJacobian() const;
107 // Return the scaled jacobian
108
109 bool GetBaryCenter (double & X, double & Y, double & Z) const;
110
111 bool IsOut(double X, double Y, double Z, double tol) const;
112 // Classify a point
113
114 // -----------------------
115 // info on node connection
116 // -----------------------
117
118 bool IsLinked (const SMDS_MeshNode* theNode1,
119 const SMDS_MeshNode* theNode2,
120 const bool theIgnoreMediumNodes=false) const;
121 // Return true if theNode1 is linked with theNode2.
122 // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
123
124 bool IsLinked (const int theNode1Index,
125 const int theNode2Index,
126 bool theIgnoreMediumNodes=false) const;
127 // Return true if the node with theNode1Index is linked
128 // with the node with theNode2Index
129 // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
130
131 int GetNodeIndex(const SMDS_MeshNode* theNode) const;
132 // Return an index of theNode
133
134 int GetAllExistingEdges(std::vector<const SMDS_MeshElement*> & edges) const;
135 // Fill vector with boundary edges existing in the mesh
136
137 double MinLinearSize2() const;
138 // Return minimal square distance between connected corner nodes
139
140 double MaxLinearSize2() const;
141 // Return maximal square distance between connected corner nodes
142
143 // -------------
144 // info on faces
145 // -------------
146 // For all elements, 0-th face is bottom based on the first nodes.
147 // For prismatic elements (tetra,hexa,prisms), 1-th face is a top one.
148 // For all elements, side faces follow order of bottom nodes
149
150 void SetExternalNormal ();
151 // Node order in faces will be so that faces normals are external.
152
153 int NbFaces() const { return myNbFaces; }
154 // Return number of faces of the volume. In the following
155 // methods 0 <= faceIndex < NbFaces()
156
157 int NbFaceNodes( int faceIndex ) const;
158 // Return number of nodes in the array of face nodes
159
160 const int* GetFaceNodesIndices( int faceIndex ) const;
161 // Return the array of face nodes indices
162 // To comfort link iteration, the array
163 // length == NbFaceNodes( faceIndex ) + 1 and
164 // the last node index == the first one, except for
165 // SMDSEntity_TriQuad_Hexa at ignoreCentralNodes==false.
166 // NOTE: for the quadratic volume, node indices are in the order the nodes encounter
167 // in face boundary and not the order they are in the mesh face
168
169 const SMDS_MeshNode** GetFaceNodes( int faceIndex ) const;
170 // Return the array of face nodes.
171 // To comfort link iteration, the array
172 // length == NbFaceNodes( faceIndex ) + 1 and
173 // the last node == the first one, except for
174 // SMDSEntity_TriQuad_Hexa at ignoreCentralNodes==false.
175 // NOTE: for the quadratic volume, nodes are in the order they encounter in face boundary
176 // and not the order they are in the mesh face
177 // WARNING: do not modify the array, some methods
178 // work basing on its contents
179
180 bool GetFaceNodes (int faceIndex,
181 std::set<const SMDS_MeshNode*>& theFaceNodes ) const;
182 // Return a set of face nodes.
183
184 bool IsFaceExternal( int faceIndex ) const;
185 // Check normal orientation of a face.
186 // SetExternalNormal() is taken into account.
187
188 bool IsFreeFace( int faceIndex, const SMDS_MeshElement** otherVol=0 ) const;
189 // Fast check that only one volume is built on nodes of a given face
190 // otherVol returns another volume sharing the given facet
191 // Function works for conforming mesh.
192
193 bool IsFreeFaceCheckAllNodes( int faceIndex, const SMDS_MeshElement** otherVol=0 ) const;
194 // Check that only one volume is built on nodes of a given face
195 // otherVol returns another volume sharing the given facet
196 // Function to be used on mesh with non conforming elements. The face shared between
197
198 bool IsFreeFaceAdv( int faceIndex, const SMDS_MeshElement** otherVol=0 ) const;
199 // Thorough check that all volumes built on the face nodes lays on one side
200 // otherVol returns another volume sharing the given facet
201
202 bool GetFaceNormal (int faceIndex, double & X, double & Y, double & Z) const;
203 // Return a normal to a face
204
205 bool GetFaceBaryCenter (int faceIndex, double & X, double & Y, double & Z) const;
206 // Return barycenter of a face
207
208 bool AllFacesSameOriented() const;
209 // Check that all the faces of a polyhedron have the same orientation
210 // no differentiation between inward and outward orientation is made.
211
212 double GetFaceArea( int faceIndex ) const;
213 // Return face area
214
215 int GetOppFaceIndex( int faceIndex ) const;
216 // Return index of the opposite face if it exists, else -1.
217
218 int GetCenterNodeIndex( int faceIndex ) const;
219 // Return index of the node located at face center of a quadratic element like HEX27
220
221 int GetFaceIndex( const std::set<const SMDS_MeshNode*>& theFaceNodes,
222 const int theFaceIndexHint=-1) const;
223 // Return index of a face formed by theFaceNodes.
224 // Return -1 if a face not found
225
226 //int GetFaceIndex( const std::set<int>& theFaceNodesIndices );
227 // Return index of a face formed by theFaceNodesIndices
228 // Return -1 if a face not found
229
230 int GetAllExistingFaces(std::vector<const SMDS_MeshElement*> & faces) const;
231 // Fill vector with boundary faces existing in the mesh
232
233 // ------------------------
234 // static methods for faces
235 // ------------------------
236
237 static VolumeType GetType(int nbNodes);
238 // return VolumeType by nb of nodes in a volume
239
240 static int NbFaces( VolumeType type );
241 // return nb of faces by volume type
242
243 static const int* GetFaceNodesIndices(VolumeType type,
244 int faceIndex,
245 bool external);
246 // Return the array of face nodes indices
247 // To comfort link iteration, the array
248 // length == NbFaceNodes( faceIndex ) + 1 and
249 // the last node index == the first one.
250 // Nodes at face centers of SMDSEntity_TriQuad_Hexa are ignored
251
252 static int NbFaceNodes(VolumeType type, int faceIndex );
253 // Return number of nodes in the array of face nodes
254 // Nodes at face centers of SMDSEntity_TriQuad_Hexa are ignored
255
256 static int NbCornerNodes(VolumeType type);
257 // Useful to know nb of corner nodes of a quadratic volume
258
259 static int GetOppFaceIndexOfHex( int faceIndex );
260 // Return index of the opposite face of the hexahedron
261
262 private:
263
264 bool setFace( int faceIndex ) const;
265
266 bool projectNodesToNormal( int faceIndex,
267 double& minProj,
268 double& maxProj,
269 double* normal = 0) const;
270
274
277 std::vector<const SMDS_MeshNode*> myVolumeNodes;
278 std::vector< int > myPolyIndices; // of a myCurFace
279 std::vector<int> myPolyQuantities;
280 std::vector< int > myPolyFacetOri; // -1-in, +1-out, 0-undef
281
282 typedef std::pair<int,int> Link;
283 std::map<Link, int> myFwdLinks; // used in IsFaceExternal() to find out myPolyFacetOri
284
285 mutable bool myExternalFaces;
286
287 mutable const int* myAllFacesNodeIndices_F;
288 mutable const int* myAllFacesNodeIndices_RE;
289 mutable const int* myAllFacesNbNodes;
290 mutable int myMaxFaceNbNodes;
291
292 struct SaveFacet;
293 struct Facet
294 {
298 std::vector<const SMDS_MeshNode*> myNodes;
299 };
301
302};
303#endif
304
305
307//
308// ORDER OF NODES OF FORWARD ELEMENT
309//
311/*
312// N3
313// +
314// /|\
315// / | \
316// / | \
317// N0 +---|---+ N1 TETRAHEDRON
318// \ | /
319// \ | /
320// \ | /
321// \|/
322// +
323// N2
324
325// + N4
326// /|\
327// / | \
328// / | \
329// / | \
330// N3 +---------+ N5
331// | | |
332// | + N1 |
333// | / \ | PENTAHEDRON
334// | / \ |
335// | / \ |
336// |/ \|
337// N0 +---------+ N2
338
339// N5+----------+N6
340// /| /|
341// / | / |
342// / | / |
343// N4+----------+N7 |
344// | | | | HEXAHEDRON
345// | | | |
346// | | | |
347// | N1+------|---+N2
348// | / | /
349// | / | /
350// |/ |/
351// N0+----------+N3
352//
353*/
#define SMDS_EXPORT
Definition: SMESH_SMDS.hxx:37
Base class for elements.
Definition: SMDS_MeshElement.hxx:56
Definition: SMDS_MeshNode.hxx:36
Mesh volume.
Definition: SMDS_MeshVolume.hxx:40
Definition: SMDS_VolumeTool.hxx:53
std::vector< const SMDS_MeshNode * > myVolumeNodes
Definition: SMDS_VolumeTool.hxx:277
std::vector< int > myPolyQuantities
Definition: SMDS_VolumeTool.hxx:279
bool myIgnoreCentralNodes
Definition: SMDS_VolumeTool.hxx:273
const int * myAllFacesNodeIndices_RE
Definition: SMDS_VolumeTool.hxx:288
VolumeType
Definition: SMDS_VolumeTool.hxx:56
@ HEXA
Definition: SMDS_VolumeTool.hxx:56
@ HEX_PRISM
Definition: SMDS_VolumeTool.hxx:57
bool myExternalFaces
Definition: SMDS_VolumeTool.hxx:285
int myMaxFaceNbNodes
Definition: SMDS_VolumeTool.hxx:290
int NbFaces() const
Definition: SMDS_VolumeTool.hxx:153
bool myVolForward
Definition: SMDS_VolumeTool.hxx:275
int NbNodes() const
Definition: SMDS_VolumeTool.hxx:100
bool IsPoly() const
Definition: SMDS_VolumeTool.hxx:80
std::pair< int, int > Link
Definition: SMDS_VolumeTool.hxx:282
std::map< Link, int > myFwdLinks
Definition: SMDS_VolumeTool.hxx:283
const int * myAllFacesNbNodes
Definition: SMDS_VolumeTool.hxx:289
bool IsForward() const
Definition: SMDS_VolumeTool.hxx:88
const SMDS_MeshElement * myVolume
Definition: SMDS_VolumeTool.hxx:271
const SMDS_MeshVolume * myPolyedre
Definition: SMDS_VolumeTool.hxx:272
Facet myCurFace
Definition: SMDS_VolumeTool.hxx:300
std::vector< int > myPolyFacetOri
Definition: SMDS_VolumeTool.hxx:280
int myNbFaces
Definition: SMDS_VolumeTool.hxx:276
std::vector< int > myPolyIndices
Definition: SMDS_VolumeTool.hxx:278
const SMDS_MeshNode ** GetNodes() const
Definition: SMDS_VolumeTool.hxx:97
const int * myAllFacesNodeIndices_F
Definition: SMDS_VolumeTool.hxx:287
bool GetBaryCenter(const TCellInfo &theCellInfo, const TNodeInfo &theNodeInfo, TGaussCoord &theGaussCoord, const TElemNum &theElemNum, EModeSwitch theMode)
To calculate Gauss Points coordinates for defined TCellInfo as its bary center.
Definition: MED_GaussUtils.cxx:1908
bool IsOut(const SMDS_MeshElement *element, const gp_Pnt &point, double tol)
Return true if the point is IN or ON of the element.
Definition: SMESH_MeshAlgos.cxx:1367
Definition: SMDS_VolumeTool.hxx:294
int myNbNodes
Definition: SMDS_VolumeTool.hxx:296
int myIndex
Definition: SMDS_VolumeTool.hxx:295
int * myNodeIndices
Definition: SMDS_VolumeTool.hxx:297
std::vector< const SMDS_MeshNode * > myNodes
Definition: SMDS_VolumeTool.hxx:298
Saver/restorer of a SMDS_VolumeTool::myCurFace.
Definition: SMDS_VolumeTool.cxx:456