Salome HOME
Increment version: 8.5.0
[modules/smesh.git] / src / SMDS / SMDS_VolumeTool.hxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, 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 class SMDS_MeshElement;
35 class SMDS_MeshNode;
36 class SMDS_MeshVolume;
37
38 #include <vector>
39 #include <set>
40 #include <map>
41
42 // =========================================================================
43 //
44 // Class providing topological and other information about SMDS_MeshVolume:
45 // allows iteration on faces or, to be precise, on nodes of volume sides;
46 // provides info on nodes connection etc.
47 //
48 // =========================================================================
49
50 class SMDS_EXPORT SMDS_VolumeTool
51 {
52  public:
53
54   enum VolumeType { UNKNOWN = -1, TETRA = 0, PYRAM, PENTA, HEXA,
55                     HEX_PRISM, QUAD_TETRA, QUAD_PYRAM, QUAD_PENTA, QUAD_HEXA,
56                     POLYHEDA, NB_VOLUME_TYPES }; // to keep synchronised with GetSize()!
57
58   SMDS_VolumeTool ();
59   ~SMDS_VolumeTool ();
60   SMDS_VolumeTool( const SMDS_MeshElement* theVolume,
61                    const bool              ignoreCentralNodes = true);
62
63   bool Set( const SMDS_MeshElement*                  theVolume,
64             const bool                               ignoreCentralNodes = true,
65             const std::vector<const SMDS_MeshNode*>* nodes = 0);
66   // Set volume.
67   // Return false if theVolume is not of type SMDSAbs_Volume.
68   // ignoreCentralNodes makes skip nodes at face centers when returning
69   // nodes of faces of SMDSEntity_TriQuad_Hexa.
70   // alternative nodes can be provided
71
72   const SMDS_MeshVolume* Element() const;
73   // return element
74
75   int ID() const;
76   // return element ID
77
78   bool IsPoly() const { return myPolyedre; }
79
80   // -----------------------
81   // general info
82   // -----------------------
83
84   VolumeType GetVolumeType() const;
85
86   bool IsForward() const { return myVolForward; }
87   // Check volume orientation. can be changed by Inverse().
88   // See node order of forward volumes at the file bottom
89
90   void Inverse();
91   // Change nodes order as if the volume changes its orientation:
92   // top and bottom faces are reversed.
93   // Result of IsForward() and methods returning nodes change
94
95   const SMDS_MeshNode** GetNodes() const { return (const SMDS_MeshNode**) &myVolumeNodes[0]; }
96   // Return array of volume nodes
97
98   int NbNodes() const { return myVolumeNodes.size(); }
99   // Return array of volume nodes
100
101   double GetSize() const;
102   // Return element volume
103
104   bool GetBaryCenter (double & X, double & Y, double & Z) const;
105
106   bool IsOut(double X, double Y, double Z, double tol) const;
107   // Classify a point
108
109   // -----------------------
110   // info on node connection
111   // -----------------------
112
113   bool IsLinked (const SMDS_MeshNode* theNode1,
114                  const SMDS_MeshNode* theNode2,
115                  const bool           theIgnoreMediumNodes=false) const;
116   // Return true if theNode1 is linked with theNode2.
117   // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
118
119   bool IsLinked (const int theNode1Index,
120                  const int theNode2Index,
121                  bool      theIgnoreMediumNodes=false) const;
122   // Return true if the node with theNode1Index is linked
123   // with the node with theNode2Index
124   // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
125
126   int GetNodeIndex(const SMDS_MeshNode* theNode) const;
127   // Return an index of theNode
128
129   int GetAllExistingEdges(std::vector<const SMDS_MeshElement*> & edges) const;
130   // Fill vector with boundary edges existing in the mesh
131
132   double MinLinearSize2() const;
133   // Return minimal square distance between connected corner nodes
134
135   double MaxLinearSize2() const;
136   // Return maximal square distance between connected corner nodes
137
138   // -------------
139   // info on faces
140   // -------------
141   // For all elements, 0-th face is bottom based on the first nodes.
142   // For prismatic elements (tetra,hexa,prisms), 1-th face is a top one.
143   // For all elements, side faces follow order of bottom nodes
144
145   void SetExternalNormal ();
146   // Node order in faces  will be so that faces normals are external.
147
148   int NbFaces() const { return myNbFaces; }
149   // Return number of faces of the volume. In the following
150   // methods 0 <= faceIndex < NbFaces()
151
152   int NbFaceNodes( int faceIndex ) const;
153   // Return number of nodes in the array of face nodes
154
155   const int* GetFaceNodesIndices( int faceIndex ) const;
156   // Return the array of face nodes indices
157   // To comfort link iteration, the array
158   // length == NbFaceNodes( faceIndex ) + 1 and
159   // the last node index == the first one, except for
160   // SMDSEntity_TriQuad_Hexa at ignoreCentralNodes==false.
161   // NOTE: for the quadratic volume, node indices are in the order the nodes encounter
162   // in face boundary and not the order they are in the mesh face
163
164   const SMDS_MeshNode** GetFaceNodes( int faceIndex ) const;
165   // Return the array of face nodes.
166   // To comfort link iteration, the array
167   // length == NbFaceNodes( faceIndex ) + 1 and
168   // the last node == the first one, except for
169   // SMDSEntity_TriQuad_Hexa at ignoreCentralNodes==false.
170   // NOTE: for the quadratic volume, nodes are in the order they encounter in face boundary
171   // and not the order they are in the mesh face
172   // WARNING: do not modify the array, some methods
173   //          work basing on its contents
174
175   bool GetFaceNodes (int faceIndex,
176                      std::set<const SMDS_MeshNode*>& theFaceNodes ) const;
177   // Return a set of face nodes.
178
179   bool IsFaceExternal( int faceIndex ) const;
180   // Check normal orientation of a face.
181   // SetExternalNormal() is taken into account.
182
183   bool IsFreeFace(  int faceIndex, const SMDS_MeshElement** otherVol=0 ) const;
184   // Fast check that only one volume is built on nodes of a given face
185   // otherVol returns another volume sharing the given facet
186
187   bool IsFreeFaceAdv(  int faceIndex, const SMDS_MeshElement** otherVol=0 ) const;
188   // Thorough check that all volumes built on the face nodes lays on one side
189   // otherVol returns another volume sharing the given facet
190
191   bool GetFaceNormal (int faceIndex, double & X, double & Y, double & Z) const;
192   // Return a normal to a face
193
194   bool GetFaceBaryCenter (int faceIndex, double & X, double & Y, double & Z) const;
195   // Return barycenter of a face
196
197   double GetFaceArea( int faceIndex ) const;
198   // Return face area
199
200   int GetOppFaceIndex( int faceIndex ) const;
201   // Return index of the opposite face if it exists, else -1.
202
203   int GetCenterNodeIndex( int faceIndex ) const;
204   // Return index of the node located at face center of a quadratic element like HEX27
205
206   int GetFaceIndex( const std::set<const SMDS_MeshNode*>& theFaceNodes,
207                     const int                             theFaceIndexHint=-1) const;
208   // Return index of a face formed by theFaceNodes.
209   // Return -1 if a face not found
210
211   //int GetFaceIndex( const std::set<int>& theFaceNodesIndices );
212   // Return index of a face formed by theFaceNodesIndices
213   // Return -1 if a face not found
214
215   int GetAllExistingFaces(std::vector<const SMDS_MeshElement*> & faces) const;
216   // Fill vector with boundary faces existing in the mesh
217
218   // ------------------------
219   // static methods for faces
220   // ------------------------
221
222   static VolumeType GetType(int nbNodes);
223   // return VolumeType by nb of nodes in a volume
224
225   static int NbFaces( VolumeType type );
226   // return nb of faces by volume type
227
228   static const int* GetFaceNodesIndices(VolumeType type,
229                                         int        faceIndex,
230                                         bool       external);
231   // Return the array of face nodes indices
232   // To comfort link iteration, the array
233   // length == NbFaceNodes( faceIndex ) + 1 and
234   // the last node index == the first one.
235   // Nodes at face centers of SMDSEntity_TriQuad_Hexa are ignored
236
237   static int NbFaceNodes(VolumeType type, int faceIndex );
238   // Return number of nodes in the array of face nodes
239   // Nodes at face centers of SMDSEntity_TriQuad_Hexa are ignored
240
241   static int NbCornerNodes(VolumeType type);
242   // Useful to know nb of corner nodes of a quadratic volume
243
244   static int GetOppFaceIndexOfHex( int faceIndex );
245   // Return index of the opposite face of the hexahedron
246
247  private:
248
249   bool setFace( int faceIndex ) const;
250
251   bool projectNodesToNormal( int faceIndex, double& minProj, double& maxProj ) const;
252
253   const SMDS_MeshElement* myVolume;
254   const SMDS_MeshVolume*  myPolyedre;
255   bool                    myIgnoreCentralNodes;
256
257   bool                    myVolForward;
258   int                     myNbFaces;
259   std::vector<const SMDS_MeshNode*> myVolumeNodes;
260   std::vector< int >      myPolyIndices; // of a myCurFace
261   std::vector< int >      myPolyQuantities;
262   std::vector< int >      myPolyFacetOri; // -1-in, +1-out, 0-undef
263
264   typedef std::pair<int,int> Link;
265   std::map<Link, int>     myFwdLinks; // used in IsFaceExternal() to find out myPolyFacetOri
266
267   mutable bool            myExternalFaces;
268
269   mutable const int*      myAllFacesNodeIndices_F;
270   mutable const int*      myAllFacesNodeIndices_RE;
271   mutable const int*      myAllFacesNbNodes;
272   mutable int             myMaxFaceNbNodes;
273
274   struct SaveFacet;
275   struct Facet
276   {
277     int                   myIndex;
278     int                   myNbNodes;
279     int*                  myNodeIndices;
280     std::vector<const SMDS_MeshNode*> myNodes;
281   };
282   mutable Facet           myCurFace;
283
284 };
285 #endif
286
287
288 ///////////////////////////////////////////////////////////////////////////
289 //
290 //                   ORDER OF NODES OF FORWARD ELEMENT
291 //
292 ///////////////////////////////////////////////////////////////////////////
293 /*
294 //           N3
295 //           +
296 //          /|\
297 //         / | \
298 //        /  |  \
299 //    N0 +---|---+ N1                TETRAHEDRON
300 //       \   |   /
301 //        \  |  /
302 //         \ | /
303 //          \|/
304 //           +
305 //           N2
306
307 //            + N4
308 //           /|\
309 //          / | \
310 //         /  |  \
311 //        /   |   \
312 //    N3 +---------+ N5
313 //       |    |    |
314 //       |    + N1 |
315 //       |   / \   |                PENTAHEDRON
316 //       |  /   \  |
317 //       | /     \ |
318 //       |/       \|
319 //    N0 +---------+ N2
320
321 //         N5+----------+N6
322 //          /|         /|
323 //         / |        / |
324 //        /  |       /  |
325 //     N4+----------+N7 |
326 //       |   |      |   |           HEXAHEDRON
327 //       |   |      |   |
328 //       |   |      |   |
329 //       | N1+------|---+N2
330 //       |  /       |  /
331 //       | /        | /
332 //       |/         |/
333 //     N0+----------+N3
334 //
335 */