1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SMDS_VolumeTool.cxx
24 // Created : Tue Jul 13 12:22:13 2004
25 // Author : Edward AGAPOV (eap)
28 #pragma warning(disable:4786)
31 #include "SMDS_VolumeTool.hxx"
33 #include "SMDS_MeshElement.hxx"
34 #include "SMDS_MeshNode.hxx"
35 #include "SMDS_Mesh.hxx"
37 #include <utilities.h>
49 // ======================================================
50 // Node indices in faces depending on volume orientation
51 // making most faces normals external
52 // ======================================================
53 // For all elements, 0-th face is bottom based on the first nodes.
54 // For prismatic elements (tetra,hexa,prisms), 1-th face is a top one.
55 // For all elements, side faces follow order of bottom nodes
56 // ======================================================
64 // N0 +---|---+ N1 TETRAHEDRON
72 static int Tetra_F [4][4] = { // FORWARD == EXTERNAL
73 { 0, 1, 2, 0 }, // All faces have external normals
77 static int Tetra_RE [4][4] = { // REVERSED -> FORWARD (EXTERNAL)
78 { 0, 2, 1, 0 }, // All faces have external normals
82 static int Tetra_nbN [] = { 3, 3, 3, 3 };
95 static int Pyramid_F [5][5] = { // FORWARD == EXTERNAL
96 { 0, 1, 2, 3, 0 }, // All faces have external normals
102 static int Pyramid_RE [5][5] = { // REVERSED -> FORWARD (EXTERNAL)
103 { 0, 3, 2, 1, 0 }, // All faces but a bottom have external normals
108 static int Pyramid_nbN [] = { 4, 3, 3, 3, 3 };
119 // | / \ | PENTAHEDRON
125 static int Penta_F [5][5] = { // FORWARD
126 { 0, 1, 2, 0, 0 }, // All faces have external normals
127 { 3, 5, 4, 3, 3 }, // 0 is bottom, 1 is top face
131 static int Penta_RE [5][5] = { // REVERSED -> EXTERNAL
137 static int Penta_nbN [] = { 3, 3, 4, 4, 4 };
144 // N4+----------+N7 |
145 // | | | | HEXAHEDRON
146 // | N1+------|---+N2
152 static int Hexa_F [6][5] = { // FORWARD
154 { 4, 7, 6, 5, 4 }, // all face normals are external
159 static int Hexa_RE [6][5] = { // REVERSED -> EXTERNAL
161 { 4, 5, 6, 7, 4 }, // all face normals are external
166 static int Hexa_nbN [] = { 4, 4, 4, 4, 4, 4 };
167 static int Hexa_oppF[] = { 1, 0, 4, 5, 2, 3 }; // oppopsite facet indices
186 static int HexPrism_F [8][7] = { // FORWARD
187 { 0, 1, 2, 3, 4, 5, 0 },
188 { 6,11,10, 9, 8, 7, 6 },
189 { 0, 6, 7, 1, 0, 0, 0 },
190 { 1, 7, 8, 2, 1, 1, 1 },
191 { 2, 8, 9, 3, 2, 2, 2 },
192 { 3, 9,10, 4, 3, 3, 3 },
193 { 4,10,11, 5, 4, 4, 4 },
194 { 5,11, 6, 0, 5, 5, 5 }};
195 static int HexPrism_RE [8][7] = { // REVERSED -> EXTERNAL
196 { 0, 5, 4, 3, 2, 1, 0 },
197 { 6,11,10, 9, 8, 7, 6 },
198 { 0, 6, 7, 1, 0, 0, 0 },
199 { 1, 7, 8, 2, 1, 1, 1 },
200 { 2, 8, 9, 3, 2, 2, 2 },
201 { 3, 9,10, 4, 3, 3, 3 },
202 { 4,10,11, 5, 4, 4, 4 },
203 { 5,11, 6, 0, 5, 5, 5 }};
204 static int HexPrism_nbN [] = { 6, 6, 4, 4, 4, 4, 4, 4 };
213 // N0 +---|---+ N1 TETRAHEDRON
221 static int QuadTetra_F [4][7] = { // FORWARD
222 { 0, 4, 1, 5, 2, 6, 0 }, // All faces have external normals
223 { 0, 7, 3, 8, 1, 4, 0 },
224 { 1, 8, 3, 9, 2, 5, 1 },
225 { 0, 6, 2, 9, 3, 7, 0 }};
226 static int QuadTetra_RE [4][7] = { // REVERSED -> FORWARD (EXTERNAL)
227 { 0, 6, 2, 5, 1, 4, 0 }, // All faces have external normals
228 { 0, 4, 1, 8, 3, 7, 0 },
229 { 1, 5, 2, 9, 3, 8, 1 },
230 { 0, 7, 3, 9, 2, 6, 0 }};
231 static int QuadTetra_nbN [] = { 6, 6, 6, 6 };
241 // | | 9 - middle point for (0,4) etc.
254 static int QuadPyram_F [5][9] = { // FORWARD
255 { 0, 5, 1, 6, 2, 7, 3, 8, 0 }, // All faces have external normals
256 { 0, 9, 4, 10,1, 5, 0, 4, 4 },
257 { 1, 10,4, 11,2, 6, 1, 4, 4 },
258 { 2, 11,4, 12,3, 7, 2, 4, 4 },
259 { 3, 12,4, 9, 0, 8, 3, 4, 4 }};
260 static int QuadPyram_RE [5][9] = { // REVERSED -> FORWARD (EXTERNAL)
261 { 0, 8, 3, 7, 2, 6, 1, 5, 0 }, // All faces but a bottom have external normals
262 { 0, 5, 1, 10,4, 9, 0, 4, 4 },
263 { 1, 6, 2, 11,4, 10,1, 4, 4 },
264 { 2, 7, 3, 12,4, 11,2, 4, 4 },
265 { 3, 8, 0, 9, 4, 12,3, 4, 4 }};
266 static int QuadPyram_nbN [] = { 8, 6, 6, 6, 6 };
290 static int QuadPenta_F [5][9] = { // FORWARD
291 { 0, 6, 1, 7, 2, 8, 0, 0, 0 },
292 { 3, 11,5, 10,4, 9, 3, 3, 3 },
293 { 0, 12,3, 9, 4, 13,1, 6, 0 },
294 { 1, 13,4, 10,5, 14,2, 7, 1 },
295 { 0, 8, 2, 14,5, 11,3, 12,0 }};
296 static int QuadPenta_RE [5][9] = { // REVERSED -> EXTERNAL
297 { 0, 8, 2, 7, 1, 6, 0, 0, 0 },
298 { 3, 9, 4, 10,5, 11,3, 3, 3 },
299 { 0, 6, 1, 13,4, 9, 3, 12,0 },
300 { 1, 7, 2, 14,5, 10,4, 13,1 },
301 { 0, 12,3, 11,5, 14,2, 8, 0 }};
302 static int QuadPenta_nbN [] = { 6, 6, 8, 8, 8 };
306 // N5+-----+-----+N6 +-----+-----+
308 // 12+ | 14+ | + | +25 + |
310 // N4+-----+-----+N7 | QUADRATIC +-----+-----+ | Central nodes
311 // | | 15 | | HEXAHEDRON | | | | of tri-quadratic
312 // | | | | | | | | HEXAHEDRON
313 // | 17+ | +18 | + 22+ | +
315 // | | | | | + | 26+ | + |
317 // 16+ | +19 | + | +24 + |
320 // | N1+-----+-|---+N2 | +-----+-|---+
322 // | +8 | +10 | + 20+ | +
324 // N0+-----+-----+N3 +-----+-----+
327 static int QuadHexa_F [6][9] = { // FORWARD
328 { 0, 8, 1, 9, 2, 10,3, 11,0 }, // all face normals are external,
329 { 4, 15,7, 14,6, 13,5, 12,4 },
330 { 0, 16,4, 12,5, 17,1, 8, 0 },
331 { 1, 17,5, 13,6, 18,2, 9, 1 },
332 { 3, 10,2, 18,6, 14,7, 19,3 },
333 { 0, 11,3, 19,7, 15,4, 16,0 }};
334 static int QuadHexa_RE [6][9] = { // REVERSED -> EXTERNAL
335 { 0, 11,3, 10,2, 9, 1, 8, 0 }, // all face normals are external
336 { 4, 12,5, 13,6, 14,7, 15,4 },
337 { 0, 8, 1, 17,5, 12,4, 16,0 },
338 { 1, 9, 2, 18,6, 13,5, 17,1 },
339 { 3, 19,7, 14,6, 18,2, 10,3 },
340 { 0, 16,4, 15,7, 19,3, 11,0 }};
341 static int QuadHexa_nbN [] = { 8, 8, 8, 8, 8, 8 };
343 static int TriQuadHexa_F [6][9] = { // FORWARD
344 { 0, 8, 1, 9, 2, 10,3, 11, 20 }, // all face normals are external
345 { 4, 15,7, 14,6, 13,5, 12, 25 },
346 { 0, 16,4, 12,5, 17,1, 8, 21 },
347 { 1, 17,5, 13,6, 18,2, 9, 22 },
348 { 3, 10,2, 18,6, 14,7, 19, 23 },
349 { 0, 11,3, 19,7, 15,4, 16, 24 }};
350 static int TriQuadHexa_RE [6][9] = { // REVERSED -> EXTERNAL
351 { 0, 11,3, 10,2, 9, 1, 8, 20 }, // opposite faces are neighbouring,
352 { 4, 12,5, 13,6, 14,7, 15, 25 }, // all face normals are external
353 { 0, 8, 1, 17,5, 12,4, 16, 21 },
354 { 1, 9, 2, 18,6, 13,5, 17, 22 },
355 { 3, 19,7, 14,6, 18,2, 10, 23 },
356 { 0, 16,4, 15,7, 19,3, 11, 24 }};
357 static int TriQuadHexa_nbN [] = { 9, 9, 9, 9, 9, 9 };
360 // ========================================================
361 // to perform some calculations without linkage to CASCADE
362 // ========================================================
367 XYZ() { x = 0; y = 0; z = 0; }
368 XYZ( double X, double Y, double Z ) { x = X; y = Y; z = Z; }
369 XYZ( const XYZ& other ) { x = other.x; y = other.y; z = other.z; }
370 XYZ( const SMDS_MeshNode* n ) { x = n->X(); y = n->Y(); z = n->Z(); }
371 double* data() { return &x; }
372 inline XYZ operator-( const XYZ& other );
373 inline XYZ operator+( const XYZ& other );
374 inline XYZ Crossed( const XYZ& other );
375 inline XYZ operator-();
376 inline double Dot( const XYZ& other );
377 inline double Magnitude();
378 inline double SquareMagnitude();
379 inline XYZ Normalize();
381 inline XYZ XYZ::operator-( const XYZ& Right ) {
382 return XYZ(x - Right.x, y - Right.y, z - Right.z);
384 inline XYZ XYZ::operator-() {
385 return XYZ(-x,-y,-z);
387 inline XYZ XYZ::operator+( const XYZ& Right ) {
388 return XYZ(x + Right.x, y + Right.y, z + Right.z);
390 inline XYZ XYZ::Crossed( const XYZ& Right ) {
391 return XYZ (y * Right.z - z * Right.y,
392 z * Right.x - x * Right.z,
393 x * Right.y - y * Right.x);
395 inline double XYZ::Dot( const XYZ& Other ) {
396 return(x * Other.x + y * Other.y + z * Other.z);
398 inline double XYZ::Magnitude() {
399 return sqrt (x * x + y * y + z * z);
401 inline double XYZ::SquareMagnitude() {
402 return (x * x + y * y + z * z);
404 inline XYZ XYZ::Normalize() {
405 double magnitude = Magnitude();
406 if ( magnitude != 0.0 )
407 return XYZ(x /= magnitude,y /= magnitude,z /= magnitude );
412 //================================================================================
414 * \brief Return linear type corresponding to a quadratic one
416 //================================================================================
418 SMDS_VolumeTool::VolumeType quadToLinear(SMDS_VolumeTool::VolumeType quadType)
420 SMDS_VolumeTool::VolumeType linType = SMDS_VolumeTool::VolumeType( int(quadType)-4 );
421 const int nbCornersByQuad = SMDS_VolumeTool::NbCornerNodes( quadType );
422 if ( SMDS_VolumeTool::NbCornerNodes( linType ) == nbCornersByQuad )
426 for ( ; iLin < SMDS_VolumeTool::NB_VOLUME_TYPES; ++iLin )
427 if ( SMDS_VolumeTool::NbCornerNodes( SMDS_VolumeTool::VolumeType( iLin )) == nbCornersByQuad)
428 return SMDS_VolumeTool::VolumeType( iLin );
430 return SMDS_VolumeTool::UNKNOWN;
435 //================================================================================
437 * \brief Saver/restorer of a SMDS_VolumeTool::myCurFace
439 //================================================================================
441 struct SMDS_VolumeTool::SaveFacet
443 SMDS_VolumeTool::Facet mySaved;
444 SMDS_VolumeTool::Facet& myToRestore;
445 SaveFacet( SMDS_VolumeTool::Facet& facet ): myToRestore( facet )
448 mySaved.myNodes.swap( facet.myNodes );
452 if ( myToRestore.myIndex != mySaved.myIndex )
453 myToRestore = mySaved;
454 myToRestore.myNodes.swap( mySaved.myNodes );
458 //=======================================================================
459 //function : SMDS_VolumeTool
461 //=======================================================================
463 SMDS_VolumeTool::SMDS_VolumeTool ()
468 //=======================================================================
469 //function : SMDS_VolumeTool
471 //=======================================================================
473 SMDS_VolumeTool::SMDS_VolumeTool (const SMDS_MeshElement* theVolume,
474 const bool ignoreCentralNodes)
476 Set( theVolume, ignoreCentralNodes );
479 //=======================================================================
480 //function : SMDS_VolumeTool
482 //=======================================================================
484 SMDS_VolumeTool::~SMDS_VolumeTool()
486 myCurFace.myNodeIndices = NULL;
489 //=======================================================================
490 //function : SetVolume
491 //purpose : Set volume to iterate on
492 //=======================================================================
494 bool SMDS_VolumeTool::Set (const SMDS_MeshElement* theVolume,
495 const bool ignoreCentralNodes,
496 const std::vector<const SMDS_MeshNode*>* otherNodes)
501 myIgnoreCentralNodes = ignoreCentralNodes;
505 myVolumeNodes.clear();
506 myPolyIndices.clear();
507 myPolyQuantities.clear();
508 myPolyFacetOri.clear();
511 myExternalFaces = false;
513 myAllFacesNodeIndices_F = 0;
514 myAllFacesNodeIndices_RE = 0;
515 myAllFacesNbNodes = 0;
517 myCurFace.myIndex = -1;
518 myCurFace.myNodeIndices = NULL;
519 myCurFace.myNodes.clear();
522 if ( !theVolume || theVolume->GetType() != SMDSAbs_Volume )
525 myVolume = theVolume;
526 myNbFaces = theVolume->NbFaces();
527 if ( myVolume->IsPoly() )
529 myPolyedre = SMDS_Mesh::DownCast<SMDS_MeshVolume>( myVolume );
530 myPolyFacetOri.resize( myNbFaces, 0 );
534 myVolumeNodes.resize( myVolume->NbNodes() );
537 if ( otherNodes->size() != myVolumeNodes.size() )
538 return ( myVolume = 0 );
539 for ( size_t i = 0; i < otherNodes->size(); ++i )
540 if ( ! ( myVolumeNodes[i] = (*otherNodes)[0] ))
541 return ( myVolume = 0 );
545 myVolumeNodes.assign( myVolume->begin_nodes(), myVolume->end_nodes() );
550 return ( myVolume = 0 );
554 // define volume orientation
556 if ( GetFaceNormal( 0, botNormal.x, botNormal.y, botNormal.z ))
558 const SMDS_MeshNode* botNode = myVolumeNodes[ 0 ];
559 int topNodeIndex = myVolume->NbCornerNodes() - 1;
560 while ( !IsLinked( 0, topNodeIndex, /*ignoreMediumNodes=*/true )) --topNodeIndex;
561 const SMDS_MeshNode* topNode = myVolumeNodes[ topNodeIndex ];
562 XYZ upDir (topNode->X() - botNode->X(),
563 topNode->Y() - botNode->Y(),
564 topNode->Z() - botNode->Z() );
565 myVolForward = ( botNormal.Dot( upDir ) < 0 );
568 myCurFace.myIndex = -1; // previous setFace(0) didn't take myVolForward into account
573 //=======================================================================
575 //purpose : Inverse volume
576 //=======================================================================
578 #define SWAP_NODES(nodes,i1,i2) \
580 const SMDS_MeshNode* tmp = nodes[ i1 ]; \
581 nodes[ i1 ] = nodes[ i2 ]; \
584 void SMDS_VolumeTool::Inverse ()
586 if ( !myVolume ) return;
588 if (myVolume->IsPoly()) {
589 MESSAGE("Warning: attempt to inverse polyhedral volume");
593 myVolForward = !myVolForward;
594 myCurFace.myIndex = -1;
596 // inverse top and bottom faces
597 switch ( myVolumeNodes.size() ) {
599 SWAP_NODES( myVolumeNodes, 1, 2 );
602 SWAP_NODES( myVolumeNodes, 1, 3 );
605 SWAP_NODES( myVolumeNodes, 1, 2 );
606 SWAP_NODES( myVolumeNodes, 4, 5 );
609 SWAP_NODES( myVolumeNodes, 1, 3 );
610 SWAP_NODES( myVolumeNodes, 5, 7 );
613 SWAP_NODES( myVolumeNodes, 1, 5 );
614 SWAP_NODES( myVolumeNodes, 2, 4 );
615 SWAP_NODES( myVolumeNodes, 7, 11 );
616 SWAP_NODES( myVolumeNodes, 8, 10 );
620 SWAP_NODES( myVolumeNodes, 1, 2 );
621 SWAP_NODES( myVolumeNodes, 4, 6 );
622 SWAP_NODES( myVolumeNodes, 8, 9 );
625 SWAP_NODES( myVolumeNodes, 1, 3 );
626 SWAP_NODES( myVolumeNodes, 5, 8 );
627 SWAP_NODES( myVolumeNodes, 6, 7 );
628 SWAP_NODES( myVolumeNodes, 10, 12 );
631 SWAP_NODES( myVolumeNodes, 1, 2 );
632 SWAP_NODES( myVolumeNodes, 4, 5 );
633 SWAP_NODES( myVolumeNodes, 6, 8 );
634 SWAP_NODES( myVolumeNodes, 9, 11 );
635 SWAP_NODES( myVolumeNodes, 13, 14 );
638 SWAP_NODES( myVolumeNodes, 1, 3 );
639 SWAP_NODES( myVolumeNodes, 5, 7 );
640 SWAP_NODES( myVolumeNodes, 8, 11 );
641 SWAP_NODES( myVolumeNodes, 9, 10 );
642 SWAP_NODES( myVolumeNodes, 12, 15 );
643 SWAP_NODES( myVolumeNodes, 13, 14 );
644 SWAP_NODES( myVolumeNodes, 17, 19 );
647 SWAP_NODES( myVolumeNodes, 1, 3 );
648 SWAP_NODES( myVolumeNodes, 5, 7 );
649 SWAP_NODES( myVolumeNodes, 8, 11 );
650 SWAP_NODES( myVolumeNodes, 9, 10 );
651 SWAP_NODES( myVolumeNodes, 12, 15 );
652 SWAP_NODES( myVolumeNodes, 13, 14 );
653 SWAP_NODES( myVolumeNodes, 17, 19 );
654 SWAP_NODES( myVolumeNodes, 21, 24 );
655 SWAP_NODES( myVolumeNodes, 22, 23 );
661 //=======================================================================
662 //function : GetVolumeType
664 //=======================================================================
666 SMDS_VolumeTool::VolumeType SMDS_VolumeTool::GetVolumeType() const
671 switch( myVolumeNodes.size() ) {
672 case 4: return TETRA;
673 case 5: return PYRAM;
674 case 6: return PENTA;
676 case 12: return HEX_PRISM;
677 case 10: return QUAD_TETRA;
678 case 13: return QUAD_PYRAM;
679 case 15: return QUAD_PENTA;
680 case 20: return QUAD_HEXA;
681 case 27: return QUAD_HEXA;
688 //=======================================================================
689 //function : getTetraVolume
691 //=======================================================================
693 static double getTetraVolume(const SMDS_MeshNode* n1,
694 const SMDS_MeshNode* n2,
695 const SMDS_MeshNode* n3,
696 const SMDS_MeshNode* n4)
698 double p1[3], p2[3], p3[3], p4[3];
704 double Q1 = -(p1[ 0 ]-p2[ 0 ])*(p3[ 1 ]*p4[ 2 ]-p4[ 1 ]*p3[ 2 ]);
705 double Q2 = (p1[ 0 ]-p3[ 0 ])*(p2[ 1 ]*p4[ 2 ]-p4[ 1 ]*p2[ 2 ]);
706 double R1 = -(p1[ 0 ]-p4[ 0 ])*(p2[ 1 ]*p3[ 2 ]-p3[ 1 ]*p2[ 2 ]);
707 double R2 = -(p2[ 0 ]-p3[ 0 ])*(p1[ 1 ]*p4[ 2 ]-p4[ 1 ]*p1[ 2 ]);
708 double S1 = (p2[ 0 ]-p4[ 0 ])*(p1[ 1 ]*p3[ 2 ]-p3[ 1 ]*p1[ 2 ]);
709 double S2 = -(p3[ 0 ]-p4[ 0 ])*(p1[ 1 ]*p2[ 2 ]-p2[ 1 ]*p1[ 2 ]);
711 return (Q1+Q2+R1+R2+S1+S2)/6.0;
714 //=======================================================================
716 //purpose : Return element volume
717 //=======================================================================
718 double SMDS_VolumeTool::GetSize() const
724 if ( myVolume->IsPoly() )
729 SaveFacet savedFacet( myCurFace );
731 // split a polyhedron into tetrahedrons
734 SMDS_VolumeTool* me = const_cast< SMDS_VolumeTool* > ( this );
735 for ( int f = 0; f < NbFaces(); ++f )
738 XYZ area (0,0,0), p1( myCurFace.myNodes[0] );
739 for ( int n = 0; n < myCurFace.myNbNodes; ++n )
741 XYZ p2( myCurFace.myNodes[ n+1 ]);
742 area = area + p1.Crossed( p2 );
746 oriOk = oriOk && IsFaceExternal( f );
749 if ( !oriOk && V > 0 )
754 const static int ind[] = {
755 0, 1, 3, 6, 11, 23, 31, 44, 58, 78 };
756 const static int vtab[][4] = { // decomposition into tetra in the order of enum VolumeType
789 // quadratic tetrahedron
814 // quadratic pentahedron
831 // quadratic hexahedron
856 int type = GetVolumeType();
858 int n2 = ind[type+1];
860 for (int i = n1; i < n2; i++) {
861 V -= getTetraVolume( myVolumeNodes[ vtab[i][0] ],
862 myVolumeNodes[ vtab[i][1] ],
863 myVolumeNodes[ vtab[i][2] ],
864 myVolumeNodes[ vtab[i][3] ]);
871 //=======================================================================
872 //function : getTetraScaledJacobian
873 //purpose : Given the smesh nodes in the canonical order of the tetrahedron, return the scaled jacobian
874 //=======================================================================
875 static double getTetraScaledJacobian(const SMDS_MeshNode* n0,
876 const SMDS_MeshNode* n1,
877 const SMDS_MeshNode* n2,
878 const SMDS_MeshNode* n3)
880 const double sqrt = std::sqrt(2.0);
881 // Get the coordinates
886 // Define the edges connecting the nodes
889 XYZ L2 = p2-p0; // invert the definition of doc to get the proper orientation of the crossed product
893 double Jacobian = L2.Crossed( L0 ).Dot( L3 );
894 double norm0 = L0.Magnitude();
895 double norm1 = L1.Magnitude();
896 double norm2 = L2.Magnitude();
897 double norm3 = L3.Magnitude();
898 double norm4 = L4.Magnitude();
899 double norm5 = L5.Magnitude();
901 std::array<double, 5> norms{};
903 norms[1] = norm3*norm4*norm5;
904 norms[2] = norm1*norm2*norm5;
905 norms[3] = norm0*norm1*norm4;
906 norms[4] = norm0*norm2*norm3;
908 auto findMaxNorm = std::max_element(norms.begin(), norms.end());
909 double maxNorm = *findMaxNorm;
911 if ( std::fabs( maxNorm ) < std::numeric_limits<double>::min() )
912 maxNorm = std::numeric_limits<double>::max();
914 return Jacobian * sqrt / maxNorm;
917 //=======================================================================
918 //function : getPyramidScaledJacobian
919 //purpose : Given the pyramid, compute the scaled jacobian of the four tetrahedrons and return the minimun value.
920 //=======================================================================
921 static double getPyramidScaledJacobian(const SMDS_MeshNode* n0,
922 const SMDS_MeshNode* n1,
923 const SMDS_MeshNode* n2,
924 const SMDS_MeshNode* n3,
925 const SMDS_MeshNode* n4)
927 const double sqrt = std::sqrt(2.0);
928 std::array<double, 4> tetScaledJacobian{};
929 tetScaledJacobian[0] = getTetraScaledJacobian(n0, n1, n3, n4);
930 tetScaledJacobian[1] = getTetraScaledJacobian(n1, n2, n0, n4);
931 tetScaledJacobian[2] = getTetraScaledJacobian(n2, n3, n1, n4);
932 tetScaledJacobian[3] = getTetraScaledJacobian(n3, n0, n2, n4);
934 auto minEntry = std::min_element(tetScaledJacobian.begin(), tetScaledJacobian.end());
936 double scaledJacobian = (*minEntry) * 2.0/sqrt;
937 return scaledJacobian < 1.0 ? scaledJacobian : 1.0 - (scaledJacobian - 1.0);
942 //=======================================================================
943 //function : getHexaScaledJacobian
944 //purpose : Evaluate the scaled jacobian on the eight vertices of the hexahedron and return the minimal registered value
945 //remark : Follow the reference numeration described at the top of the class.
946 //=======================================================================
947 static double getHexaScaledJacobian(const SMDS_MeshNode* n0,
948 const SMDS_MeshNode* n1,
949 const SMDS_MeshNode* n2,
950 const SMDS_MeshNode* n3,
951 const SMDS_MeshNode* n4,
952 const SMDS_MeshNode* n5,
953 const SMDS_MeshNode* n6,
954 const SMDS_MeshNode* n7)
956 // Scaled jacobian is an scalar quantity measuring the deviation of the geometry from the perfect geometry
957 // Get the coordinates
967 // Define the edges connecting the nodes
968 XYZ L0 = (p1-p0).Normalize();
969 XYZ L1 = (p2-p1).Normalize();
970 XYZ L2 = (p3-p2).Normalize();
971 XYZ L3 = (p3-p0).Normalize();
972 XYZ L4 = (p4-p0).Normalize();
973 XYZ L5 = (p5-p1).Normalize();
974 XYZ L6 = (p6-p2).Normalize();
975 XYZ L7 = (p7-p3).Normalize();
976 XYZ L8 = (p5-p4).Normalize();
977 XYZ L9 = (p6-p5).Normalize();
978 XYZ L10 = (p7-p6).Normalize();
979 XYZ L11 = (p7-p4).Normalize();
980 XYZ X0 = (p1-p0+p2-p3+p6-p7+p5-p4).Normalize();
981 XYZ X1 = (p3-p0+p2-p1+p7-p4+p6-p5).Normalize();
982 XYZ X2 = (p4-p0+p7-p3+p5-p1+p6-p2).Normalize();
984 std::array<double, 9> scaledJacobian{};
985 //Scaled jacobian of nodes following their numeration
986 scaledJacobian[0] = L4.Crossed( L3).Dot( L0 ); // For L0
987 scaledJacobian[1] = L5.Crossed(-L0).Dot( L1 ); // For L1
988 scaledJacobian[2] = L6.Crossed(-L1).Dot( L2 ); // For L2
989 scaledJacobian[3] = L7.Crossed(-L2).Dot(-L3 ); // For L3
990 scaledJacobian[4] = -L4.Crossed( L8).Dot( L11 ); // For L11
991 scaledJacobian[5] = -L5.Crossed( L9).Dot(-L8 ); // For L8
992 scaledJacobian[6] = -L6.Crossed(L10).Dot(-L9 ); // For L9
993 scaledJacobian[7] = -L7.Crossed(-L11).Dot(-L10 ); // For L10
994 scaledJacobian[8] = X2.Crossed( X1).Dot( X0 ); // For principal axes
996 auto minScaledJacobian = std::min_element(scaledJacobian.begin(), scaledJacobian.end());
997 return *minScaledJacobian;
1001 //=======================================================================
1002 //function : getTetraNormalizedJacobian
1003 //purpose : Return the jacobian of the tetrahedron based on normalized vectors
1004 //=======================================================================
1005 static double getTetraNormalizedJacobian(const SMDS_MeshNode* n0,
1006 const SMDS_MeshNode* n1,
1007 const SMDS_MeshNode* n2,
1008 const SMDS_MeshNode* n3)
1010 const double sqrt = std::sqrt(2.0);
1011 // Get the coordinates
1016 // Define the normalized edges connecting the nodes
1017 XYZ L0 = (p1-p0).Normalize();
1018 XYZ L2 = (p2-p0).Normalize(); // invert the definition of doc to get the proper orientation of the crossed product
1019 XYZ L3 = (p3-p0).Normalize();
1020 return L2.Crossed( L0 ).Dot( L3 );
1023 //=======================================================================
1024 //function : getPentaScaledJacobian
1025 //purpose : Evaluate the scaled jacobian on the pentahedron based on decomposed tetrahedrons
1026 //=======================================================================
1033 // N0 +---------+ N2
1034 // | | | NUMERATION RERENCE FOLLOWING POSSITIVE RIGHT HAND RULE
1036 // | / \ | PENTAHEDRON
1040 // N3 +---------+ N5
1047 // N0 +--|---+ N2 TETRAHEDRON ASSOCIATED TO N0
1048 // \ | / Numeration passed to getTetraScaledJacobian
1049 // \ | / N0=N0; N1=N2; N2=N3; N3=N1
1060 // N2 +---|---+ N5 TETRAHEDRON ASSOCIATED TO N2
1061 // \ | / Numeration passed to getTetraScaledJacobian
1062 // \ | / N0=N2; N1=N5; N2=N0; N3=N1
1073 // N3 +---|---+ N0 TETRAHEDRON ASSOCIATED TO N3
1074 // \ | / Numeration passed to getTetraScaledJacobian
1075 // \ | / N0=N3; N1=N0; N2=N5; N3=N4
1086 // N1 +---|---+ N2 TETRAHEDRON ASSOCIATED TO N1
1087 // \ | / Numeration passed to getTetraScaledJacobian
1088 // \ | / N0=N1; N1=N2; N2=N0; N3=N3
1096 static double getPentaScaledJacobian(const SMDS_MeshNode* n0,
1097 const SMDS_MeshNode* n1,
1098 const SMDS_MeshNode* n2,
1099 const SMDS_MeshNode* n3,
1100 const SMDS_MeshNode* n4,
1101 const SMDS_MeshNode* n5)
1103 std::array<double, 6> scaledJacobianOfReferenceTetra{};
1104 scaledJacobianOfReferenceTetra[0] = getTetraNormalizedJacobian(n0, n2, n3, n1); // For n0
1105 scaledJacobianOfReferenceTetra[1] = getTetraNormalizedJacobian(n2, n5, n0, n1); // For n2
1106 scaledJacobianOfReferenceTetra[2] = getTetraNormalizedJacobian(n3, n0, n5, n4); // For n3
1107 scaledJacobianOfReferenceTetra[3] = getTetraNormalizedJacobian(n5, n3, n2, n4); // For n5
1108 scaledJacobianOfReferenceTetra[4] = getTetraNormalizedJacobian(n1, n2, n0, n3); // For n1
1109 scaledJacobianOfReferenceTetra[5] = getTetraNormalizedJacobian(n4, n3, n5, n2); // For n4
1111 auto minScaledJacobian = std::min_element(scaledJacobianOfReferenceTetra.begin(), scaledJacobianOfReferenceTetra.end());
1112 double minScalJac = (*minScaledJacobian)* 2.0 / std::sqrt(3.0);
1115 return std::min(minScalJac, std::numeric_limits<double>::max());
1117 return std::max(minScalJac, -std::numeric_limits<double>::max());
1120 //=======================================================================
1121 //function : getHexaPrismScaledJacobian
1122 //purpose : Evaluate the scaled jacobian on the hexaprism by decomposing the goemetry into three 1hexa + 2 pentahedrons
1123 //=======================================================================
1124 static double getHexaPrismScaledJacobian(const SMDS_MeshNode* n0,
1125 const SMDS_MeshNode* n1,
1126 const SMDS_MeshNode* n2,
1127 const SMDS_MeshNode* n3,
1128 const SMDS_MeshNode* n4,
1129 const SMDS_MeshNode* n5,
1130 const SMDS_MeshNode* n6,
1131 const SMDS_MeshNode* n7,
1132 const SMDS_MeshNode* n8,
1133 const SMDS_MeshNode* n9,
1134 const SMDS_MeshNode* n10,
1135 const SMDS_MeshNode* n11)
1137 // The Pentahedron from the left
1138 // n0=n0; n1=n1; n2=n2; n3=n6; n4=n7, n5=n8;
1139 double scaledJacobianPentleft = getPentaScaledJacobian( n0, n1, n2, n6, n7, n8 );
1140 // The core Hexahedron
1141 // n0=n0; n1=n2, n2=n3; n3=n5; n4=n6; n5=n8; n6=n9; n7=n11
1142 double scaledJacobianHexa = getHexaScaledJacobian( n0, n2, n3, n5, n6, n8, n9, n11 );
1143 // The Pentahedron from the right
1144 // n0=n5; n1=n4; n2=n3; n3=n11; n4=n10; n5=n9
1145 double scaledJacobianPentright = getPentaScaledJacobian( n5, n4, n3, n11, n10, n9 );
1147 return std::min( scaledJacobianHexa, std::min( scaledJacobianPentleft, scaledJacobianPentright ) );
1151 //=======================================================================
1152 //function : GetScaledJacobian
1153 //purpose : Return element Scaled Jacobian using the generic definition given
1154 // in https://gitlab.kitware.com/third-party/verdict/-/blob/master/SAND2007-2853p.pdf
1155 //=======================================================================
1157 double SMDS_VolumeTool::GetScaledJacobian() const
1160 // For Tetra, call directly the getTetraScaledJacobian
1161 double scaledJacobian = 0.;
1163 VolumeType type = GetVolumeType();
1168 scaledJacobian = getTetraScaledJacobian( myVolumeNodes[0], myVolumeNodes[1], myVolumeNodes[2], myVolumeNodes[3] );
1172 scaledJacobian = getHexaScaledJacobian( myVolumeNodes[0], myVolumeNodes[1], myVolumeNodes[2], myVolumeNodes[3],
1173 myVolumeNodes[4], myVolumeNodes[5], myVolumeNodes[6], myVolumeNodes[7] );
1177 scaledJacobian = getPyramidScaledJacobian( myVolumeNodes[0], myVolumeNodes[1], myVolumeNodes[2], myVolumeNodes[3], myVolumeNodes[4] );
1181 scaledJacobian = getPentaScaledJacobian( myVolumeNodes[0], myVolumeNodes[1],
1182 myVolumeNodes[2], myVolumeNodes[3],
1183 myVolumeNodes[4], myVolumeNodes[5] );
1186 scaledJacobian = getHexaPrismScaledJacobian( myVolumeNodes[0], myVolumeNodes[1], myVolumeNodes[2], myVolumeNodes[3],
1187 myVolumeNodes[4], myVolumeNodes[5], myVolumeNodes[6], myVolumeNodes[7],
1188 myVolumeNodes[8], myVolumeNodes[9], myVolumeNodes[10], myVolumeNodes[11]);
1194 return scaledJacobian;
1198 //=======================================================================
1199 //function : GetBaryCenter
1201 //=======================================================================
1203 bool SMDS_VolumeTool::GetBaryCenter(double & X, double & Y, double & Z) const
1209 for ( size_t i = 0; i < myVolumeNodes.size(); i++ ) {
1210 X += myVolumeNodes[ i ]->X();
1211 Y += myVolumeNodes[ i ]->Y();
1212 Z += myVolumeNodes[ i ]->Z();
1214 X /= myVolumeNodes.size();
1215 Y /= myVolumeNodes.size();
1216 Z /= myVolumeNodes.size();
1221 //================================================================================
1223 * \brief Classify a point
1224 * \param tol - thickness of faces
1226 //================================================================================
1228 bool SMDS_VolumeTool::IsOut(double X, double Y, double Z, double tol) const
1230 // LIMITATION: for convex volumes only
1232 for ( int iF = 0; iF < myNbFaces; ++iF )
1235 if ( !GetFaceNormal( iF, faceNormal.x, faceNormal.y, faceNormal.z ))
1237 if ( !IsFaceExternal( iF ))
1238 faceNormal = XYZ() - faceNormal; // reverse
1240 XYZ face2p( p - XYZ( myCurFace.myNodes[0] ));
1241 if ( face2p.Dot( faceNormal ) > tol )
1247 //=======================================================================
1248 //function : SetExternalNormal
1249 //purpose : Node order will be so that faces normals are external
1250 //=======================================================================
1252 void SMDS_VolumeTool::SetExternalNormal ()
1254 myExternalFaces = true;
1255 myCurFace.myIndex = -1;
1258 //=======================================================================
1259 //function : NbFaceNodes
1260 //purpose : Return number of nodes in the array of face nodes
1261 //=======================================================================
1263 int SMDS_VolumeTool::NbFaceNodes( int faceIndex ) const
1265 if ( !setFace( faceIndex ))
1267 return myCurFace.myNbNodes;
1270 //=======================================================================
1271 //function : GetFaceNodes
1272 //purpose : Return pointer to the array of face nodes.
1273 // To comfort link iteration, the array
1274 // length == NbFaceNodes( faceIndex ) + 1 and
1275 // the last node == the first one.
1276 //=======================================================================
1278 const SMDS_MeshNode** SMDS_VolumeTool::GetFaceNodes( int faceIndex ) const
1280 if ( !setFace( faceIndex ))
1282 return &myCurFace.myNodes[0];
1285 //=======================================================================
1286 //function : GetFaceNodesIndices
1287 //purpose : Return pointer to the array of face nodes indices
1288 // To comfort link iteration, the array
1289 // length == NbFaceNodes( faceIndex ) + 1 and
1290 // the last node index == the first one.
1291 //=======================================================================
1293 const int* SMDS_VolumeTool::GetFaceNodesIndices( int faceIndex ) const
1295 if ( !setFace( faceIndex ))
1298 return myCurFace.myNodeIndices;
1301 //=======================================================================
1302 //function : GetFaceNodes
1303 //purpose : Return a set of face nodes.
1304 //=======================================================================
1306 bool SMDS_VolumeTool::GetFaceNodes (int faceIndex,
1307 std::set<const SMDS_MeshNode*>& theFaceNodes ) const
1309 if ( !setFace( faceIndex ))
1312 theFaceNodes.clear();
1313 theFaceNodes.insert( myCurFace.myNodes.begin(), myCurFace.myNodes.end() );
1320 struct NLink : public std::pair<smIdType,smIdType>
1323 NLink(const SMDS_MeshNode* n1=0, const SMDS_MeshNode* n2=0, int ori=1 )
1327 if (( myOri = ( n1->GetID() < n2->GetID() )))
1329 first = n1->GetID();
1330 second = n2->GetID();
1335 first = n2->GetID();
1336 second = n1->GetID();
1342 myOri = first = second = 0;
1345 //int Node1() const { return myOri == -1 ? second : first; }
1347 //bool IsSameOri( const std::pair<int,int>& link ) const { return link.first == Node1(); }
1351 //=======================================================================
1352 //function : IsFaceExternal
1353 //purpose : Check normal orientation of a given face
1354 //=======================================================================
1356 bool SMDS_VolumeTool::IsFaceExternal( int faceIndex ) const
1358 if ( myExternalFaces || !myVolume )
1361 if ( !myPolyedre ) // all classical volumes have external facet normals
1364 SMDS_VolumeTool* me = const_cast< SMDS_VolumeTool* >( this );
1366 if ( myPolyFacetOri[ faceIndex ])
1367 return myPolyFacetOri[ faceIndex ] > 0;
1369 int ori = 0; // -1-in, +1-out, 0-undef
1370 double minProj, maxProj;
1371 if ( projectNodesToNormal( faceIndex, minProj, maxProj ))
1373 // all nodes are on the same side of the facet
1374 ori = ( minProj < 0 ? +1 : -1 );
1375 me->myPolyFacetOri[ faceIndex ] = ori;
1377 if ( !myFwdLinks.empty() ) // concave polyhedron; collect oriented links
1378 for ( int i = 0; i < myCurFace.myNbNodes; ++i )
1380 NLink link( myCurFace.myNodes[i], myCurFace.myNodes[i+1], ori );
1381 me->myFwdLinks.insert( make_pair( link, link.myOri ));
1386 SaveFacet savedFacet( myCurFace );
1388 // concave polyhedron
1390 if ( myFwdLinks.empty() ) // get links of the least ambiguously oriented facet
1392 for ( size_t i = 0; i < myPolyFacetOri.size() && !ori; ++i )
1393 ori = myPolyFacetOri[ i ];
1395 if ( !ori ) // none facet is oriented yet
1397 // find the least ambiguously oriented facet
1398 int faceMostConvex = -1;
1399 std::map< double, int > convexity2face;
1400 for ( size_t iF = 0; iF < myPolyFacetOri.size() && faceMostConvex < 0; ++iF )
1402 if ( projectNodesToNormal( iF, minProj, maxProj ))
1404 // all nodes are on the same side of the facet
1405 me->myPolyFacetOri[ iF ] = ( minProj < 0 ? +1 : -1 );
1406 faceMostConvex = iF;
1410 ori = ( -minProj < maxProj ? -1 : +1 );
1411 double convexity = std::min( -minProj, maxProj ) / std::max( -minProj, maxProj );
1412 convexity2face.insert( std::make_pair( convexity, iF * ori ));
1415 if ( faceMostConvex < 0 ) // none facet has nodes on the same side
1417 // use the least ambiguous facet
1418 faceMostConvex = convexity2face.begin()->second;
1419 ori = ( faceMostConvex < 0 ? -1 : +1 );
1420 faceMostConvex = std::abs( faceMostConvex );
1421 me->myPolyFacetOri[ faceMostConvex ] = ori;
1424 // collect links of the oriented facets in myFwdLinks
1425 for ( size_t iF = 0; iF < myPolyFacetOri.size(); ++iF )
1427 ori = myPolyFacetOri[ iF ];
1428 if ( !ori ) continue;
1430 for ( int i = 0; i < myCurFace.myNbNodes; ++i )
1432 NLink link( myCurFace.myNodes[i], myCurFace.myNodes[i+1], ori );
1433 me->myFwdLinks.insert( make_pair( link, link.myOri ));
1438 // compare orientation of links of the facet with myFwdLinks
1440 setFace( faceIndex );
1441 std::vector< NLink > links( myCurFace.myNbNodes ), links2;
1442 for ( int i = 0; i < myCurFace.myNbNodes && !ori; ++i )
1444 NLink link( myCurFace.myNodes[i], myCurFace.myNodes[i+1] );
1445 std::map<Link, int>::const_iterator l2o = myFwdLinks.find( link );
1446 if ( l2o != myFwdLinks.end() )
1447 ori = link.myOri * l2o->second * -1;
1450 while ( !ori ) // the facet has no common links with already oriented facets
1452 // orient and collect links of other non-oriented facets
1453 for ( size_t iF = 0; iF < myPolyFacetOri.size(); ++iF )
1455 if ( myPolyFacetOri[ iF ] ) continue; // already oriented
1459 for ( int i = 0; i < myCurFace.myNbNodes && !ori; ++i )
1461 NLink link( myCurFace.myNodes[i], myCurFace.myNodes[i+1] );
1462 std::map<Link, int>::const_iterator l2o = myFwdLinks.find( link );
1463 if ( l2o != myFwdLinks.end() )
1464 ori = link.myOri * l2o->second * -1;
1465 links2.push_back( link );
1467 if ( ori ) // one more facet oriented
1469 me->myPolyFacetOri[ iF ] = ori;
1470 for ( size_t i = 0; i < links2.size(); ++i )
1471 me->myFwdLinks.insert( make_pair( links2[i], links2[i].myOri * ori ));
1476 return false; // error in algorithm: infinite loop
1478 // try to orient the facet again
1480 for ( size_t i = 0; i < links.size() && !ori; ++i )
1482 std::map<Link, int>::const_iterator l2o = myFwdLinks.find( links[i] );
1483 if ( l2o != myFwdLinks.end() )
1484 ori = links[i].myOri * l2o->second * -1;
1486 me->myPolyFacetOri[ faceIndex ] = ori;
1492 //=======================================================================
1493 //function : projectNodesToNormal
1494 //purpose : compute min and max projections of all nodes to normal of a facet.
1495 //=======================================================================
1497 bool SMDS_VolumeTool::projectNodesToNormal( int faceIndex,
1500 double* normalXYZ ) const
1502 minProj = std::numeric_limits<double>::max();
1503 maxProj = std::numeric_limits<double>::min();
1506 if ( !GetFaceNormal( faceIndex, normal.x, normal.y, normal.z ))
1509 memcpy( normalXYZ, normal.data(), 3*sizeof(double));
1511 XYZ p0 ( myCurFace.myNodes[0] );
1512 for ( size_t i = 0; i < myVolumeNodes.size(); ++i )
1514 if ( std::find( myCurFace.myNodes.begin() + 1,
1515 myCurFace.myNodes.end(),
1516 myVolumeNodes[ i ] ) != myCurFace.myNodes.end() )
1517 continue; // node of the faceIndex-th facet
1519 double proj = normal.Dot( XYZ( myVolumeNodes[ i ]) - p0 );
1520 if ( proj < minProj ) minProj = proj;
1521 if ( proj > maxProj ) maxProj = proj;
1523 const double tol = 1e-7;
1526 bool diffSize = ( minProj * maxProj < 0 );
1529 // minProj = -minProj;
1531 // else if ( minProj < 0 )
1533 // minProj = -minProj;
1534 // maxProj = -maxProj;
1537 return !diffSize; // ? 0 : (minProj >= 0);
1540 //=======================================================================
1541 //function : GetFaceNormal
1542 //purpose : Return a normal to a face
1543 //=======================================================================
1545 bool SMDS_VolumeTool::GetFaceNormal (int faceIndex, double & X, double & Y, double & Z) const
1547 if ( !setFace( faceIndex ))
1550 const int iQuad = ( !myPolyedre && myCurFace.myNbNodes > 6 ) ? 2 : 1;
1551 XYZ p1 ( myCurFace.myNodes[0*iQuad] );
1552 XYZ p2 ( myCurFace.myNodes[1*iQuad] );
1553 XYZ p3 ( myCurFace.myNodes[2*iQuad] );
1554 XYZ aVec12( p2 - p1 );
1555 XYZ aVec13( p3 - p1 );
1556 XYZ cross = aVec12.Crossed( aVec13 );
1558 for ( int i = 3*iQuad; i < myCurFace.myNbNodes; i += iQuad )
1560 XYZ p4 ( myCurFace.myNodes[i] );
1561 XYZ aVec14( p4 - p1 );
1562 XYZ cross2 = aVec13.Crossed( aVec14 );
1563 cross = cross + cross2;
1567 double size = cross.Magnitude();
1568 if ( size <= std::numeric_limits<double>::min() )
1578 //================================================================================
1580 * \brief Return barycenter of a face
1582 //================================================================================
1584 bool SMDS_VolumeTool::GetFaceBaryCenter (int faceIndex, double & X, double & Y, double & Z) const
1586 if ( !setFace( faceIndex ))
1590 for ( int i = 0; i < myCurFace.myNbNodes; ++i )
1592 X += myCurFace.myNodes[i]->X() / myCurFace.myNbNodes;
1593 Y += myCurFace.myNodes[i]->Y() / myCurFace.myNbNodes;
1594 Z += myCurFace.myNodes[i]->Z() / myCurFace.myNbNodes;
1599 //=======================================================================
1600 //function : GetFaceArea
1601 //purpose : Return face area
1602 //=======================================================================
1604 double SMDS_VolumeTool::GetFaceArea( int faceIndex ) const
1607 if ( !setFace( faceIndex ))
1610 XYZ p1 ( myCurFace.myNodes[0] );
1611 XYZ p2 ( myCurFace.myNodes[1] );
1612 XYZ p3 ( myCurFace.myNodes[2] );
1613 XYZ aVec12( p2 - p1 );
1614 XYZ aVec13( p3 - p1 );
1615 area += aVec12.Crossed( aVec13 ).Magnitude();
1617 if (myVolume->IsPoly())
1619 for ( int i = 3; i < myCurFace.myNbNodes; ++i )
1621 XYZ pI ( myCurFace.myNodes[i] );
1622 XYZ aVecI( pI - p1 );
1623 area += aVec13.Crossed( aVecI ).Magnitude();
1629 if ( myCurFace.myNbNodes == 4 ) {
1630 XYZ p4 ( myCurFace.myNodes[3] );
1631 XYZ aVec14( p4 - p1 );
1632 area += aVec14.Crossed( aVec13 ).Magnitude();
1638 //================================================================================
1640 * \brief Return index of the node located at face center of a quadratic element like HEX27
1642 //================================================================================
1644 int SMDS_VolumeTool::GetCenterNodeIndex( int faceIndex ) const
1646 if ( myAllFacesNbNodes && myVolumeNodes.size() == 27 ) // classic element with 27 nodes
1648 switch ( faceIndex ) {
1652 return faceIndex + 19;
1658 //=======================================================================
1659 //function : GetOppFaceIndex
1660 //purpose : Return index of the opposite face if it exists, else -1.
1661 //=======================================================================
1663 int SMDS_VolumeTool::GetOppFaceIndex( int faceIndex ) const
1667 MESSAGE("Warning: attempt to obtain opposite face on polyhedral volume");
1671 const int nbHoriFaces = 2;
1673 if ( faceIndex >= 0 && faceIndex < NbFaces() ) {
1674 switch ( myVolumeNodes.size() ) {
1677 if ( faceIndex == 0 || faceIndex == 1 )
1678 ind = 1 - faceIndex;
1682 if ( faceIndex <= 1 ) // top or bottom
1683 ind = 1 - faceIndex;
1685 const int nbSideFaces = myAllFacesNbNodes[0];
1686 ind = ( faceIndex - nbHoriFaces + nbSideFaces/2 ) % nbSideFaces + nbHoriFaces;
1691 ind = GetOppFaceIndexOfHex( faceIndex );
1699 //=======================================================================
1700 //function : GetOppFaceIndexOfHex
1701 //purpose : Return index of the opposite face of the hexahedron
1702 //=======================================================================
1704 int SMDS_VolumeTool::GetOppFaceIndexOfHex( int faceIndex )
1706 return Hexa_oppF[ faceIndex ];
1709 //=======================================================================
1710 //function : IsLinked
1711 //purpose : return true if theNode1 is linked with theNode2
1712 // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
1713 //=======================================================================
1715 bool SMDS_VolumeTool::IsLinked (const SMDS_MeshNode* theNode1,
1716 const SMDS_MeshNode* theNode2,
1717 const bool theIgnoreMediumNodes) const
1722 if (myVolume->IsPoly()) {
1724 MESSAGE("Warning: bad volumic element");
1727 if ( !myAllFacesNbNodes ) {
1728 SMDS_VolumeTool* me = const_cast< SMDS_VolumeTool* >( this );
1729 me->myPolyQuantities = myPolyedre->GetQuantities();
1730 myAllFacesNbNodes = &myPolyQuantities[0];
1732 int from, to = 0, d1 = 1, d2 = 2;
1733 if ( myPolyedre->IsQuadratic() ) {
1734 if ( theIgnoreMediumNodes ) {
1740 std::vector<const SMDS_MeshNode*>::const_iterator i;
1741 for (int iface = 0; iface < myNbFaces; iface++)
1744 to += myPolyQuantities[iface];
1745 i = std::find( myVolumeNodes.begin() + from, myVolumeNodes.begin() + to, theNode1 );
1746 if ( i != myVolumeNodes.end() )
1748 if (( theNode2 == *( i-d1 ) ||
1749 theNode2 == *( i+d1 )))
1752 (( theNode2 == *( i-d2 ) ||
1753 theNode2 == *( i+d2 ))))
1760 // find nodes indices
1761 int i1 = -1, i2 = -1, nbFound = 0;
1762 for ( size_t i = 0; i < myVolumeNodes.size() && nbFound < 2; i++ )
1764 if ( myVolumeNodes[ i ] == theNode1 )
1766 else if ( myVolumeNodes[ i ] == theNode2 )
1769 return IsLinked( i1, i2 );
1772 //=======================================================================
1773 //function : IsLinked
1774 //purpose : return true if the node with theNode1Index is linked
1775 // with the node with theNode2Index
1776 // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
1777 //=======================================================================
1779 bool SMDS_VolumeTool::IsLinked (const int theNode1Index,
1780 const int theNode2Index,
1781 bool theIgnoreMediumNodes) const
1783 if ( myVolume->IsPoly() ) {
1784 return IsLinked(myVolumeNodes[theNode1Index], myVolumeNodes[theNode2Index]);
1787 int minInd = std::min( theNode1Index, theNode2Index );
1788 int maxInd = std::max( theNode1Index, theNode2Index );
1790 if ( minInd < 0 || maxInd > (int)myVolumeNodes.size() - 1 || maxInd == minInd )
1793 VolumeType type = GetVolumeType();
1794 if ( myVolume->IsQuadratic() )
1796 int firstMediumInd = myVolume->NbCornerNodes();
1797 if ( minInd >= firstMediumInd )
1798 return false; // both nodes are medium - not linked
1799 if ( maxInd < firstMediumInd ) // both nodes are corners
1801 if ( theIgnoreMediumNodes )
1802 type = quadToLinear(type); // to check linkage of corner nodes only
1804 return false; // corner nodes are not linked directly in a quadratic cell
1812 switch ( maxInd - minInd ) {
1813 case 1: return minInd != 3;
1814 case 3: return minInd == 0 || minInd == 4;
1815 case 4: return true;
1822 switch ( maxInd - minInd ) {
1824 case 3: return true;
1829 switch ( maxInd - minInd ) {
1830 case 1: return minInd != 2;
1831 case 2: return minInd == 0 || minInd == 3;
1832 case 3: return true;
1839 case 0: return ( maxInd==4 || maxInd==6 || maxInd==7 );
1840 case 1: return ( maxInd==4 || maxInd==5 || maxInd==8 );
1841 case 2: return ( maxInd==5 || maxInd==6 || maxInd==9 );
1842 case 3: return ( maxInd==7 || maxInd==8 || maxInd==9 );
1850 case 0: return ( maxInd==8 || maxInd==11 || maxInd==16 );
1851 case 1: return ( maxInd==8 || maxInd==9 || maxInd==17 );
1852 case 2: return ( maxInd==9 || maxInd==10 || maxInd==18 );
1853 case 3: return ( maxInd==10 || maxInd==11 || maxInd==19 );
1854 case 4: return ( maxInd==12 || maxInd==15 || maxInd==16 );
1855 case 5: return ( maxInd==12 || maxInd==13 || maxInd==17 );
1856 case 6: return ( maxInd==13 || maxInd==14 || maxInd==18 );
1857 case 7: return ( maxInd==14 || maxInd==15 || maxInd==19 );
1865 case 0: return ( maxInd==5 || maxInd==8 || maxInd==9 );
1866 case 1: return ( maxInd==5 || maxInd==6 || maxInd==10 );
1867 case 2: return ( maxInd==6 || maxInd==7 || maxInd==11 );
1868 case 3: return ( maxInd==7 || maxInd==8 || maxInd==12 );
1869 case 4: return ( maxInd==9 || maxInd==10 || maxInd==11 || maxInd==12 );
1877 case 0: return ( maxInd==6 || maxInd==8 || maxInd==12 );
1878 case 1: return ( maxInd==6 || maxInd==7 || maxInd==13 );
1879 case 2: return ( maxInd==7 || maxInd==8 || maxInd==14 );
1880 case 3: return ( maxInd==9 || maxInd==11 || maxInd==12 );
1881 case 4: return ( maxInd==9 || maxInd==10 || maxInd==13 );
1882 case 5: return ( maxInd==10 || maxInd==11 || maxInd==14 );
1889 const int diff = maxInd-minInd;
1890 if ( diff > 6 ) return false;// not linked top and bottom
1891 if ( diff == 6 ) return true; // linked top and bottom
1892 return diff == 1 || diff == 7;
1899 //=======================================================================
1900 //function : GetNodeIndex
1901 //purpose : Return an index of theNode
1902 //=======================================================================
1904 int SMDS_VolumeTool::GetNodeIndex(const SMDS_MeshNode* theNode) const
1907 for ( size_t i = 0; i < myVolumeNodes.size(); i++ ) {
1908 if ( myVolumeNodes[ i ] == theNode )
1915 //================================================================================
1917 * \brief Fill vector with boundary faces existing in the mesh
1918 * \param faces - vector of found nodes
1919 * \retval int - nb of found faces
1921 //================================================================================
1923 int SMDS_VolumeTool::GetAllExistingFaces(std::vector<const SMDS_MeshElement*> & faces) const
1926 SaveFacet savedFacet( myCurFace );
1928 for ( int iF = 0; iF < NbFaces(); ++iF ) {
1930 if ( const SMDS_MeshElement* face = SMDS_Mesh::FindFace( myCurFace.myNodes ))
1931 faces.push_back( face );
1934 for ( int iF = 0; iF < NbFaces(); ++iF ) {
1935 const SMDS_MeshFace* face = 0;
1936 const SMDS_MeshNode** nodes = GetFaceNodes( iF );
1937 switch ( NbFaceNodes( iF )) {
1939 face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2] ); break;
1941 face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2], nodes[3] ); break;
1943 face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2],
1944 nodes[3], nodes[4], nodes[5]); break;
1946 face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2], nodes[3],
1947 nodes[4], nodes[5], nodes[6], nodes[7]); break;
1950 faces.push_back( face );
1952 return faces.size();
1956 //================================================================================
1958 * \brief Fill vector with boundary edges existing in the mesh
1959 * \param edges - vector of found edges
1960 * \retval int - nb of found faces
1962 //================================================================================
1964 int SMDS_VolumeTool::GetAllExistingEdges(std::vector<const SMDS_MeshElement*> & edges) const
1967 edges.reserve( myVolumeNodes.size() * 2 );
1968 for ( size_t i = 0; i < myVolumeNodes.size()-1; ++i ) {
1969 for ( size_t j = i + 1; j < myVolumeNodes.size(); ++j ) {
1970 if ( IsLinked( i, j )) {
1971 const SMDS_MeshElement* edge =
1972 SMDS_Mesh::FindEdge( myVolumeNodes[i], myVolumeNodes[j] );
1974 edges.push_back( edge );
1978 return edges.size();
1981 //================================================================================
1983 * \brief Return minimal square distance between connected corner nodes
1985 //================================================================================
1987 double SMDS_VolumeTool::MinLinearSize2() const
1989 double minSize = 1e+100;
1990 int iQ = myVolume->IsQuadratic() ? 2 : 1;
1992 SaveFacet savedFacet( myCurFace );
1994 // it seems that compute distance twice is faster than organization of a sole computing
1995 myCurFace.myIndex = -1;
1996 for ( int iF = 0; iF < myNbFaces; ++iF )
1999 for ( int iN = 0; iN < myCurFace.myNbNodes; iN += iQ )
2001 XYZ n1( myCurFace.myNodes[ iN ]);
2002 XYZ n2( myCurFace.myNodes[(iN + iQ) % myCurFace.myNbNodes]);
2003 minSize = std::min( minSize, (n1 - n2).SquareMagnitude());
2010 //================================================================================
2012 * \brief Return maximal square distance between connected corner nodes
2014 //================================================================================
2016 double SMDS_VolumeTool::MaxLinearSize2() const
2018 double maxSize = -1e+100;
2019 int iQ = myVolume->IsQuadratic() ? 2 : 1;
2021 SaveFacet savedFacet( myCurFace );
2023 // it seems that compute distance twice is faster than organization of a sole computing
2024 myCurFace.myIndex = -1;
2025 for ( int iF = 0; iF < myNbFaces; ++iF )
2028 for ( int iN = 0; iN < myCurFace.myNbNodes; iN += iQ )
2030 XYZ n1( myCurFace.myNodes[ iN ]);
2031 XYZ n2( myCurFace.myNodes[(iN + iQ) % myCurFace.myNbNodes]);
2032 maxSize = std::max( maxSize, (n1 - n2).SquareMagnitude());
2039 //================================================================================
2041 * \brief Fast quickly check that only one volume is built on the face nodes
2042 * This check is valid for conformal meshes only
2044 //================================================================================
2046 bool SMDS_VolumeTool::IsFreeFace( int faceIndex, const SMDS_MeshElement** otherVol/*=0*/ ) const
2048 const bool isFree = true;
2050 if ( !setFace( faceIndex ))
2053 const SMDS_MeshNode** nodes = GetFaceNodes( faceIndex );
2055 const int di = myVolume->IsQuadratic() ? 2 : 1;
2056 const int nbN = ( myCurFace.myNbNodes/di <= 4 && !IsPoly()) ? 3 : myCurFace.myNbNodes/di; // nb nodes to check
2058 SMDS_ElemIteratorPtr eIt = nodes[0]->GetInverseElementIterator( SMDSAbs_Volume );
2059 while ( eIt->more() )
2061 const SMDS_MeshElement* vol = eIt->next();
2062 if ( vol == myVolume )
2065 for ( iN = 1; iN < nbN; ++iN )
2066 if ( vol->GetNodeIndex( nodes[ iN*di ]) < 0 )
2068 if ( iN == nbN ) // nbN nodes are shared with vol
2070 // if ( vol->IsPoly() || vol->NbFaces() > 6 ) // vol is polyhed or hex prism
2072 // int nb = myCurFace.myNbNodes;
2073 // if ( myVolume->GetEntityType() != vol->GetEntityType() )
2074 // nb -= ( GetCenterNodeIndex(0) > 0 );
2075 // std::set<const SMDS_MeshNode*> faceNodes( nodes, nodes + nb );
2076 // if ( SMDS_VolumeTool( vol ).GetFaceIndex( faceNodes ) < 0 )
2079 if ( otherVol ) *otherVol = vol;
2083 if ( otherVol ) *otherVol = 0;
2087 //================================================================================
2089 * \brief Thorough check that only one volume is built on the face nodes
2091 //================================================================================
2093 bool SMDS_VolumeTool::IsFreeFaceAdv( int faceIndex, const SMDS_MeshElement** otherVol/*=0*/ ) const
2095 const bool isFree = true;
2097 if (!setFace( faceIndex ))
2100 const SMDS_MeshNode** nodes = GetFaceNodes( faceIndex );
2101 const int nbFaceNodes = myCurFace.myNbNodes;
2103 // evaluate nb of face nodes shared by other volumes
2104 int maxNbShared = -1;
2105 typedef std::map< const SMDS_MeshElement*, int > TElemIntMap;
2106 TElemIntMap volNbShared;
2107 TElemIntMap::iterator vNbIt;
2108 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ ) {
2109 const SMDS_MeshNode* n = nodes[ iNode ];
2110 SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator( SMDSAbs_Volume );
2111 while ( eIt->more() ) {
2112 const SMDS_MeshElement* elem = eIt->next();
2113 if ( elem != myVolume ) {
2114 vNbIt = volNbShared.insert( std::make_pair( elem, 0 )).first;
2116 if ( vNbIt->second > maxNbShared )
2117 maxNbShared = vNbIt->second;
2121 if ( maxNbShared < 3 )
2122 return isFree; // is free
2124 // find volumes laying on the opposite side of the face
2125 // and sharing all nodes
2126 XYZ intNormal; // internal normal
2127 GetFaceNormal( faceIndex, intNormal.x, intNormal.y, intNormal.z );
2128 if ( IsFaceExternal( faceIndex ))
2129 intNormal = XYZ( -intNormal.x, -intNormal.y, -intNormal.z );
2130 XYZ p0 ( nodes[0] ), baryCenter;
2131 for ( vNbIt = volNbShared.begin(); vNbIt != volNbShared.end(); ) {
2132 const int& nbShared = (*vNbIt).second;
2133 if ( nbShared >= 3 ) {
2134 SMDS_VolumeTool volume( (*vNbIt).first );
2135 volume.GetBaryCenter( baryCenter.x, baryCenter.y, baryCenter.z );
2136 XYZ intNormal2( baryCenter - p0 );
2137 if ( intNormal.Dot( intNormal2 ) < 0 ) {
2139 if ( nbShared >= nbFaceNodes )
2141 // a volume shares the whole facet
2142 if ( otherVol ) *otherVol = vNbIt->first;
2149 // remove a volume from volNbShared map
2150 volNbShared.erase( vNbIt++ );
2153 // here volNbShared contains only volumes laying on the opposite side of
2154 // the face and sharing 3 or more but not all face nodes with myVolume
2155 if ( volNbShared.size() < 2 ) {
2156 return isFree; // is free
2159 // check if the whole area of a face is shared
2160 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ )
2162 const SMDS_MeshNode* n = nodes[ iNode ];
2163 // check if n is shared by one of volumes of volNbShared
2164 bool isShared = false;
2165 SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator( SMDSAbs_Volume );
2166 while ( eIt->more() && !isShared )
2167 isShared = volNbShared.count( eIt->next() );
2171 if ( otherVol ) *otherVol = volNbShared.begin()->first;
2174 // if ( !myVolume->IsPoly() )
2176 // bool isShared[] = { false, false, false, false }; // 4 triangle parts of a quadrangle
2177 // for ( vNbIt = volNbShared.begin(); vNbIt != volNbShared.end(); vNbIt++ ) {
2178 // SMDS_VolumeTool volume( (*vNbIt).first );
2179 // bool prevLinkShared = false;
2180 // int nbSharedLinks = 0;
2181 // for ( int iNode = 0; iNode < nbFaceNodes; iNode++ ) {
2182 // bool linkShared = volume.IsLinked( nodes[ iNode ], nodes[ iNode + 1] );
2183 // if ( linkShared )
2185 // if ( linkShared && prevLinkShared &&
2186 // volume.IsLinked( nodes[ iNode - 1 ], nodes[ iNode + 1] ))
2187 // isShared[ iNode ] = true;
2188 // prevLinkShared = linkShared;
2190 // if ( nbSharedLinks == nbFaceNodes )
2191 // return !free; // is not free
2192 // if ( nbFaceNodes == 4 ) {
2193 // // check traingle parts 1 & 3
2194 // if ( isShared[1] && isShared[3] )
2195 // return !free; // is not free
2196 // // check triangle parts 0 & 2;
2197 // // 0 part could not be checked in the loop; check it here
2198 // if ( isShared[2] && prevLinkShared &&
2199 // volume.IsLinked( nodes[ 0 ], nodes[ 1 ] ) &&
2200 // volume.IsLinked( nodes[ 1 ], nodes[ 3 ] ) )
2201 // return !free; // is not free
2208 //=======================================================================
2209 //function : GetFaceIndex
2210 //purpose : Return index of a face formed by theFaceNodes
2211 //=======================================================================
2213 int SMDS_VolumeTool::GetFaceIndex( const std::set<const SMDS_MeshNode*>& theFaceNodes,
2214 const int theFaceIndexHint ) const
2216 if ( theFaceIndexHint >= 0 )
2218 int nbNodes = NbFaceNodes( theFaceIndexHint );
2219 if ( nbNodes == (int) theFaceNodes.size() )
2221 const SMDS_MeshNode** nodes = GetFaceNodes( theFaceIndexHint );
2223 if ( theFaceNodes.count( nodes[ nbNodes-1 ]))
2228 return theFaceIndexHint;
2231 for ( int iFace = 0; iFace < myNbFaces; iFace++ )
2233 if ( iFace == theFaceIndexHint )
2235 int nbNodes = NbFaceNodes( iFace );
2236 if ( nbNodes == (int) theFaceNodes.size() )
2238 const SMDS_MeshNode** nodes = GetFaceNodes( iFace );
2240 if ( theFaceNodes.count( nodes[ nbNodes-1 ]))
2251 //=======================================================================
2252 //function : GetFaceIndex
2253 //purpose : Return index of a face formed by theFaceNodes
2254 //=======================================================================
2256 /*int SMDS_VolumeTool::GetFaceIndex( const std::set<int>& theFaceNodesIndices )
2258 for ( int iFace = 0; iFace < myNbFaces; iFace++ ) {
2259 const int* nodes = GetFaceNodesIndices( iFace );
2260 int nbFaceNodes = NbFaceNodes( iFace );
2261 std::set<int> nodeSet;
2262 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ )
2263 nodeSet.insert( nodes[ iNode ] );
2264 if ( theFaceNodesIndices == nodeSet )
2270 //=======================================================================
2271 //function : setFace
2273 //=======================================================================
2275 bool SMDS_VolumeTool::setFace( int faceIndex ) const
2280 if ( myCurFace.myIndex == faceIndex )
2283 myCurFace.myIndex = -1;
2285 if ( faceIndex < 0 || faceIndex >= NbFaces() )
2288 if (myVolume->IsPoly())
2290 if ( !myPolyedre ) {
2291 MESSAGE("Warning: bad volumic element");
2296 SMDS_VolumeTool* me = const_cast< SMDS_VolumeTool* >( this );
2297 if ( !myAllFacesNbNodes ) {
2298 me->myPolyQuantities = myPolyedre->GetQuantities();
2299 myAllFacesNbNodes = &myPolyQuantities[0];
2301 myCurFace.myNbNodes = myAllFacesNbNodes[ faceIndex ];
2302 myCurFace.myNodes.resize( myCurFace.myNbNodes + 1 );
2303 me->myPolyIndices.resize( myCurFace.myNbNodes + 1 );
2304 myCurFace.myNodeIndices = & me->myPolyIndices[0];
2305 int shift = std::accumulate( myAllFacesNbNodes, myAllFacesNbNodes+faceIndex, 0 );
2306 for ( int iNode = 0; iNode < myCurFace.myNbNodes; iNode++ )
2308 myCurFace.myNodes [ iNode ] = myVolumeNodes[ shift + iNode ];
2309 myCurFace.myNodeIndices[ iNode ] = shift + iNode;
2311 myCurFace.myNodes [ myCurFace.myNbNodes ] = myCurFace.myNodes[ 0 ]; // last = first
2312 myCurFace.myNodeIndices[ myCurFace.myNbNodes ] = myCurFace.myNodeIndices[ 0 ];
2314 // check orientation
2315 if (myExternalFaces)
2317 myCurFace.myIndex = faceIndex; // avoid infinite recursion in IsFaceExternal()
2318 myExternalFaces = false; // force normal computation by IsFaceExternal()
2319 if ( !IsFaceExternal( faceIndex ))
2320 std::reverse( myCurFace.myNodes.begin(), myCurFace.myNodes.end() );
2321 myExternalFaces = true;
2326 if ( !myAllFacesNodeIndices_F )
2328 // choose data for an element type
2329 switch ( myVolumeNodes.size() ) {
2331 myAllFacesNodeIndices_F = &Tetra_F [0][0];
2332 //myAllFacesNodeIndices_FE = &Tetra_F [0][0];
2333 myAllFacesNodeIndices_RE = &Tetra_RE[0][0];
2334 myAllFacesNbNodes = Tetra_nbN;
2335 myMaxFaceNbNodes = sizeof(Tetra_F[0])/sizeof(Tetra_F[0][0]);
2338 myAllFacesNodeIndices_F = &Pyramid_F [0][0];
2339 //myAllFacesNodeIndices_FE = &Pyramid_F [0][0];
2340 myAllFacesNodeIndices_RE = &Pyramid_RE[0][0];
2341 myAllFacesNbNodes = Pyramid_nbN;
2342 myMaxFaceNbNodes = sizeof(Pyramid_F[0])/sizeof(Pyramid_F[0][0]);
2345 myAllFacesNodeIndices_F = &Penta_F [0][0];
2346 //myAllFacesNodeIndices_FE = &Penta_FE[0][0];
2347 myAllFacesNodeIndices_RE = &Penta_RE[0][0];
2348 myAllFacesNbNodes = Penta_nbN;
2349 myMaxFaceNbNodes = sizeof(Penta_F[0])/sizeof(Penta_F[0][0]);
2352 myAllFacesNodeIndices_F = &Hexa_F [0][0];
2353 ///myAllFacesNodeIndices_FE = &Hexa_FE[0][0];
2354 myAllFacesNodeIndices_RE = &Hexa_RE[0][0];
2355 myAllFacesNbNodes = Hexa_nbN;
2356 myMaxFaceNbNodes = sizeof(Hexa_F[0])/sizeof(Hexa_F[0][0]);
2359 myAllFacesNodeIndices_F = &QuadTetra_F [0][0];
2360 //myAllFacesNodeIndices_FE = &QuadTetra_F [0][0];
2361 myAllFacesNodeIndices_RE = &QuadTetra_RE[0][0];
2362 myAllFacesNbNodes = QuadTetra_nbN;
2363 myMaxFaceNbNodes = sizeof(QuadTetra_F[0])/sizeof(QuadTetra_F[0][0]);
2366 myAllFacesNodeIndices_F = &QuadPyram_F [0][0];
2367 //myAllFacesNodeIndices_FE = &QuadPyram_F [0][0];
2368 myAllFacesNodeIndices_RE = &QuadPyram_RE[0][0];
2369 myAllFacesNbNodes = QuadPyram_nbN;
2370 myMaxFaceNbNodes = sizeof(QuadPyram_F[0])/sizeof(QuadPyram_F[0][0]);
2373 myAllFacesNodeIndices_F = &QuadPenta_F [0][0];
2374 //myAllFacesNodeIndices_FE = &QuadPenta_FE[0][0];
2375 myAllFacesNodeIndices_RE = &QuadPenta_RE[0][0];
2376 myAllFacesNbNodes = QuadPenta_nbN;
2377 myMaxFaceNbNodes = sizeof(QuadPenta_F[0])/sizeof(QuadPenta_F[0][0]);
2381 myAllFacesNodeIndices_F = &QuadHexa_F [0][0];
2382 //myAllFacesNodeIndices_FE = &QuadHexa_FE[0][0];
2383 myAllFacesNodeIndices_RE = &QuadHexa_RE[0][0];
2384 myAllFacesNbNodes = QuadHexa_nbN;
2385 myMaxFaceNbNodes = sizeof(QuadHexa_F[0])/sizeof(QuadHexa_F[0][0]);
2386 if ( !myIgnoreCentralNodes && myVolumeNodes.size() == 27 )
2388 myAllFacesNodeIndices_F = &TriQuadHexa_F [0][0];
2389 //myAllFacesNodeIndices_FE = &TriQuadHexa_FE[0][0];
2390 myAllFacesNodeIndices_RE = &TriQuadHexa_RE[0][0];
2391 myAllFacesNbNodes = TriQuadHexa_nbN;
2392 myMaxFaceNbNodes = sizeof(TriQuadHexa_F[0])/sizeof(TriQuadHexa_F[0][0]);
2396 myAllFacesNodeIndices_F = &HexPrism_F [0][0];
2397 //myAllFacesNodeIndices_FE = &HexPrism_FE[0][0];
2398 myAllFacesNodeIndices_RE = &HexPrism_RE[0][0];
2399 myAllFacesNbNodes = HexPrism_nbN;
2400 myMaxFaceNbNodes = sizeof(HexPrism_F[0])/sizeof(HexPrism_F[0][0]);
2406 myCurFace.myNbNodes = myAllFacesNbNodes[ faceIndex ];
2407 // if ( myExternalFaces )
2408 // myCurFace.myNodeIndices = (int*)( myVolForward ? myAllFacesNodeIndices_FE + faceIndex*myMaxFaceNbNodes : myAllFacesNodeIndices_RE + faceIndex*myMaxFaceNbNodes );
2410 // myCurFace.myNodeIndices = (int*)( myAllFacesNodeIndices_F + faceIndex*myMaxFaceNbNodes );
2411 myCurFace.myNodeIndices = (int*)( myVolForward ? myAllFacesNodeIndices_F + faceIndex*myMaxFaceNbNodes : myAllFacesNodeIndices_RE + faceIndex*myMaxFaceNbNodes );
2414 myCurFace.myNodes.resize( myCurFace.myNbNodes + 1 );
2415 for ( int iNode = 0; iNode < myCurFace.myNbNodes; iNode++ )
2416 myCurFace.myNodes[ iNode ] = myVolumeNodes[ myCurFace.myNodeIndices[ iNode ]];
2417 myCurFace.myNodes[ myCurFace.myNbNodes ] = myCurFace.myNodes[ 0 ];
2420 myCurFace.myIndex = faceIndex;
2425 //=======================================================================
2426 //function : GetType
2427 //purpose : return VolumeType by nb of nodes in a volume
2428 //=======================================================================
2430 SMDS_VolumeTool::VolumeType SMDS_VolumeTool::GetType(int nbNodes)
2432 switch ( nbNodes ) {
2433 case 4: return TETRA;
2434 case 5: return PYRAM;
2435 case 6: return PENTA;
2436 case 8: return HEXA;
2437 case 10: return QUAD_TETRA;
2438 case 13: return QUAD_PYRAM;
2439 case 15: return QUAD_PENTA;
2441 case 27: return QUAD_HEXA;
2442 case 12: return HEX_PRISM;
2443 default:return UNKNOWN;
2447 //=======================================================================
2448 //function : NbFaces
2449 //purpose : return nb of faces by volume type
2450 //=======================================================================
2452 int SMDS_VolumeTool::NbFaces( VolumeType type )
2456 case QUAD_TETRA: return 4;
2458 case QUAD_PYRAM: return 5;
2460 case QUAD_PENTA: return 5;
2462 case QUAD_HEXA : return 6;
2463 case HEX_PRISM : return 8;
2468 //================================================================================
2470 * \brief Useful to know nb of corner nodes of a quadratic volume
2471 * \param type - volume type
2472 * \retval int - nb of corner nodes
2474 //================================================================================
2476 int SMDS_VolumeTool::NbCornerNodes(VolumeType type)
2480 case QUAD_TETRA: return 4;
2482 case QUAD_PYRAM: return 5;
2484 case QUAD_PENTA: return 6;
2486 case QUAD_HEXA : return 8;
2487 case HEX_PRISM : return 12;
2494 //=======================================================================
2495 //function : GetFaceNodesIndices
2496 //purpose : Return the array of face nodes indices
2497 // To comfort link iteration, the array
2498 // length == NbFaceNodes( faceIndex ) + 1 and
2499 // the last node index == the first one.
2500 //=======================================================================
2502 const int* SMDS_VolumeTool::GetFaceNodesIndices(VolumeType type,
2507 case TETRA: return Tetra_F[ faceIndex ];
2508 case PYRAM: return Pyramid_F[ faceIndex ];
2509 case PENTA: return external ? Penta_F[ faceIndex ] : Penta_F[ faceIndex ];
2510 case HEXA: return external ? Hexa_F[ faceIndex ] : Hexa_F[ faceIndex ];
2511 case QUAD_TETRA: return QuadTetra_F[ faceIndex ];
2512 case QUAD_PYRAM: return QuadPyram_F[ faceIndex ];
2513 case QUAD_PENTA: return external ? QuadPenta_F[ faceIndex ] : QuadPenta_F[ faceIndex ];
2514 // what about SMDSEntity_TriQuad_Hexa?
2515 case QUAD_HEXA: return external ? QuadHexa_F[ faceIndex ] : QuadHexa_F[ faceIndex ];
2516 case HEX_PRISM: return external ? HexPrism_F[ faceIndex ] : HexPrism_F[ faceIndex ];
2522 //=======================================================================
2523 //function : NbFaceNodes
2524 //purpose : Return number of nodes in the array of face nodes
2525 //=======================================================================
2527 int SMDS_VolumeTool::NbFaceNodes(VolumeType type,
2531 case TETRA: return Tetra_nbN[ faceIndex ];
2532 case PYRAM: return Pyramid_nbN[ faceIndex ];
2533 case PENTA: return Penta_nbN[ faceIndex ];
2534 case HEXA: return Hexa_nbN[ faceIndex ];
2535 case QUAD_TETRA: return QuadTetra_nbN[ faceIndex ];
2536 case QUAD_PYRAM: return QuadPyram_nbN[ faceIndex ];
2537 case QUAD_PENTA: return QuadPenta_nbN[ faceIndex ];
2538 // what about SMDSEntity_TriQuad_Hexa?
2539 case QUAD_HEXA: return QuadHexa_nbN[ faceIndex ];
2540 case HEX_PRISM: return HexPrism_nbN[ faceIndex ];
2546 //=======================================================================
2547 //function : Element
2548 //purpose : return element
2549 //=======================================================================
2551 const SMDS_MeshVolume* SMDS_VolumeTool::Element() const
2553 return static_cast<const SMDS_MeshVolume*>( myVolume );
2556 //=======================================================================
2558 //purpose : return element ID
2559 //=======================================================================
2561 smIdType SMDS_VolumeTool::ID() const
2563 return myVolume ? myVolume->GetID() : 0;