Back to index

salome-smesh  6.5.0
SMDS_QuadraticVolumeOfNodes.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SMESH SMDS : implementaion of Salome mesh data structure
00024 // File:      SMDS_QuadraticVolumeOfNodes.cxx
00025 // Created:   17.01.06 09:46:11
00026 // Author:    Sergey KUUL
00027 //
00028 #include "SMDS_QuadraticVolumeOfNodes.hxx"
00029 
00030 #include "SMDS_IteratorOfElements.hxx"
00031 #include "SMDS_MeshNode.hxx"
00032 #include "SMDS_SetIterator.hxx"
00033 #include "SMDS_VolumeTool.hxx"
00034 
00035 #include "utilities.h"
00036 
00037 using namespace std;
00038 
00039 
00040 //=======================================================================
00041 //function : SMDS_QuadraticVolumeOfNodes()
00042 //purpose  : Constructor tetrahedron of 10 nodes
00043 //=======================================================================
00044 
00045 SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes
00046                                                (const SMDS_MeshNode * n1,
00047                                                 const SMDS_MeshNode * n2,
00048                                                 const SMDS_MeshNode * n3,
00049                                                 const SMDS_MeshNode * n4,
00050                                                 const SMDS_MeshNode * n12,
00051                                                 const SMDS_MeshNode * n23,
00052                                                 const SMDS_MeshNode * n31,
00053                                                 const SMDS_MeshNode * n14, 
00054                                                 const SMDS_MeshNode * n24,
00055                                                 const SMDS_MeshNode * n34)
00056 {
00057   //MESSAGE("*********************************************** SMDS_QuadraticVolumeOfNodes");
00058   myNodes.resize( 10 );
00059   myNodes[ 0 ] = n1;
00060   myNodes[ 1 ] = n2;
00061   myNodes[ 2 ] = n3;
00062   myNodes[ 3 ] = n4;
00063   myNodes[ 4 ] = n12;
00064   myNodes[ 5 ] = n23;
00065   myNodes[ 6 ] = n31;
00066   myNodes[ 7 ] = n14;
00067   myNodes[ 8 ] = n24;
00068   myNodes[ 9 ] = n34;
00069 }
00070 
00071 
00072 //=======================================================================
00073 //function : SMDS_QuadraticVolumeOfNodes()
00074 //purpose  : Constructor pyramid of 13 nodes
00075 //=======================================================================
00076 
00077 SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes
00078                                                (const SMDS_MeshNode * n1,
00079                                                 const SMDS_MeshNode * n2,
00080                                                 const SMDS_MeshNode * n3,
00081                                                 const SMDS_MeshNode * n4,
00082                                                 const SMDS_MeshNode * n5,
00083                                                 const SMDS_MeshNode * n12,
00084                                                 const SMDS_MeshNode * n23,
00085                                                 const SMDS_MeshNode * n34,
00086                                                 const SMDS_MeshNode * n41, 
00087                                                 const SMDS_MeshNode * n15,
00088                                                 const SMDS_MeshNode * n25,
00089                                                 const SMDS_MeshNode * n35,
00090                                                 const SMDS_MeshNode * n45)
00091 {
00092   //MESSAGE("*********************************************** SMDS_QuadraticVolumeOfNodes");
00093   myNodes.resize( 13 );
00094   myNodes[ 0 ] = n1;
00095   myNodes[ 1 ] = n2;
00096   myNodes[ 2 ] = n3;
00097   myNodes[ 3 ] = n4;
00098   myNodes[ 4 ] = n5;
00099   myNodes[ 5 ] = n12;
00100   myNodes[ 6 ] = n23;
00101   myNodes[ 7 ] = n34;
00102   myNodes[ 8 ] = n41;
00103   myNodes[ 9 ] = n15;
00104   myNodes[ 10 ] = n25;
00105   myNodes[ 11 ] = n35;
00106   myNodes[ 12 ] = n45;
00107 }
00108 
00109 
00110 //=======================================================================
00111 //function : SMDS_QuadraticVolumeOfNodes()
00112 //purpose  : Constructor Pentahedron with 15 nodes
00113 //=======================================================================
00114 
00115 SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes
00116                                                (const SMDS_MeshNode * n1,
00117                                                 const SMDS_MeshNode * n2,
00118                                                 const SMDS_MeshNode * n3,
00119                                                 const SMDS_MeshNode * n4,
00120                                                 const SMDS_MeshNode * n5,
00121                                                 const SMDS_MeshNode * n6, 
00122                                                 const SMDS_MeshNode * n12,
00123                                                 const SMDS_MeshNode * n23,
00124                                                 const SMDS_MeshNode * n31, 
00125                                                 const SMDS_MeshNode * n45,
00126                                                 const SMDS_MeshNode * n56,
00127                                                 const SMDS_MeshNode * n64, 
00128                                                 const SMDS_MeshNode * n14,
00129                                                 const SMDS_MeshNode * n25,
00130                                                 const SMDS_MeshNode * n36)
00131 {
00132   //MESSAGE("*********************************************** SMDS_QuadraticVolumeOfNodes");
00133   myNodes.resize( 15 );
00134   myNodes[ 0 ] = n1;
00135   myNodes[ 1 ] = n2;
00136   myNodes[ 2 ] = n3;
00137   myNodes[ 3 ] = n4;
00138   myNodes[ 4 ] = n5;
00139   myNodes[ 5 ] = n6;
00140   myNodes[ 6 ] = n12;
00141   myNodes[ 7 ] = n23;
00142   myNodes[ 8 ] = n31;
00143   myNodes[ 9 ] = n45;
00144   myNodes[ 10 ] = n56;
00145   myNodes[ 11 ] = n64;
00146   myNodes[ 12 ] = n14;
00147   myNodes[ 13 ] = n25;
00148   myNodes[ 14 ] = n36;
00149 }
00150 
00151 
00152 //=======================================================================
00153 //function : SMDS_QuadraticVolumeOfNodes()
00154 //purpose  : Constructor Hexahedrons with 20 nodes
00155 //=======================================================================
00156 
00157 SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes
00158                                                (const SMDS_MeshNode * n1,
00159                                                 const SMDS_MeshNode * n2,
00160                                                 const SMDS_MeshNode * n3,
00161                                                 const SMDS_MeshNode * n4,
00162                                                 const SMDS_MeshNode * n5,
00163                                                 const SMDS_MeshNode * n6,
00164                                                 const SMDS_MeshNode * n7,
00165                                                 const SMDS_MeshNode * n8, 
00166                                                 const SMDS_MeshNode * n12,
00167                                                 const SMDS_MeshNode * n23,
00168                                                 const SMDS_MeshNode * n34,
00169                                                 const SMDS_MeshNode * n41, 
00170                                                 const SMDS_MeshNode * n56,
00171                                                 const SMDS_MeshNode * n67,
00172                                                 const SMDS_MeshNode * n78,
00173                                                 const SMDS_MeshNode * n85, 
00174                                                 const SMDS_MeshNode * n15,
00175                                                 const SMDS_MeshNode * n26,
00176                                                 const SMDS_MeshNode * n37,
00177                                                 const SMDS_MeshNode * n48)
00178 {
00179   //MESSAGE("*********************************************** SMDS_QuadraticVolumeOfNodes");
00180   myNodes.resize( 20 );
00181   myNodes[ 0 ] = n1;
00182   myNodes[ 1 ] = n2;
00183   myNodes[ 2 ] = n3;
00184   myNodes[ 3 ] = n4;
00185   myNodes[ 4 ] = n5;
00186   myNodes[ 5 ] = n6;
00187   myNodes[ 6 ] = n7;
00188   myNodes[ 7 ] = n8;
00189   myNodes[ 8 ] = n12;
00190   myNodes[ 9 ] = n23;
00191   myNodes[ 10 ] = n34;
00192   myNodes[ 11 ] = n41;
00193   myNodes[ 12 ] = n56;
00194   myNodes[ 13 ] = n67;
00195   myNodes[ 14 ] = n78;
00196   myNodes[ 15 ] = n85;
00197   myNodes[ 16 ] = n15;
00198   myNodes[ 17 ] = n26;
00199   myNodes[ 18 ] = n37;
00200   myNodes[ 19 ] = n48;
00201 }
00202 
00203 
00204 //=======================================================================
00205 //function : IsMediumNode
00206 //purpose  : 
00207 //=======================================================================
00208 
00209 bool SMDS_QuadraticVolumeOfNodes::IsMediumNode(const SMDS_MeshNode* node) const
00210 {
00211   int nbCorners = 0;
00212   switch (myNodes.size()) {
00213   case 10: nbCorners = 4; break;
00214   case 13: nbCorners = 5; break;
00215   case 15: nbCorners = 6; break;
00216   default: nbCorners = 8;
00217   }
00218   for ( int i = nbCorners; i<myNodes.size(); i++) {
00219     if(myNodes[i]==node) return true;
00220   }
00221   return false;
00222 }
00223 
00224 
00225 //=======================================================================
00226 //function : ChangeNodes
00227 //purpose  : 
00228 //=======================================================================
00229 
00230 bool SMDS_QuadraticVolumeOfNodes::ChangeNodes(const SMDS_MeshNode* nodes[],
00231                                               const int            nbNodes)
00232 {
00233   if( nbNodes==10 || nbNodes==13 || nbNodes==15 || nbNodes==20 ) {
00234     myNodes.resize(nbNodes);
00235     int i=0;
00236     for(; i<nbNodes; i++) {
00237       myNodes[i] = nodes[i];
00238     }
00239     return true;
00240   }
00241   return false;
00242 }
00243 
00244 
00245 //=======================================================================
00246 //function : NbNodes
00247 //purpose  : 
00248 //=======================================================================
00249 int SMDS_QuadraticVolumeOfNodes::NbNodes() const
00250 {
00251   return myNodes.size();
00252 }
00253 
00254 
00255 //=======================================================================
00256 //function : NbEdges
00257 //purpose  : 
00258 //=======================================================================
00259 int SMDS_QuadraticVolumeOfNodes::NbEdges() const
00260 {
00261   if(myNodes.size()==10)
00262     return 6;
00263   else if(myNodes.size()==13)
00264     return 8;
00265   else if(myNodes.size()==15)
00266     return 9;
00267   else
00268     return 12;
00269 }
00270 
00271 
00272 //=======================================================================
00273 //function : NbFaces
00274 //purpose  : 
00275 //=======================================================================
00276 int SMDS_QuadraticVolumeOfNodes::NbFaces() const
00277 {
00278   if(myNodes.size()==10)
00279     return 4;
00280   else if(myNodes.size()==20)
00281     return 6;
00282   else
00283     return 5;
00284 }
00285 
00286 //=======================================================================
00287 //function : Print
00288 //purpose  : 
00289 //=======================================================================
00290 void SMDS_QuadraticVolumeOfNodes::Print(ostream & OS) const
00291 {
00292   OS << "quadratic volume <" << GetID() << " > : ";
00293   int i, nbNodes = myNodes.size();
00294   for (i = 0; i < nbNodes - 1; i++)
00295     OS << myNodes[i] << ",";
00296   OS << myNodes[i] << ") " << endl;
00297 }
00298 
00299 
00300 //=======================================================================
00301 //private class : SMDS_QuadraticVolumeOfNodes_MyIterator
00302 //purpose  : 
00303 //=======================================================================
00304 
00305 class SMDS_QuadraticVolumeOfNodes_MyIterator : public SMDS_NodeVectorElemIterator
00306 {
00307 public:
00308   SMDS_QuadraticVolumeOfNodes_MyIterator(const vector<const SMDS_MeshNode *>& s):
00309     SMDS_NodeVectorElemIterator( s.begin(), s.end() ) {}
00310 };
00311 
00313 
00316 
00317 
00318 class _MySubIterator : public SMDS_ElemIterator
00319 {
00320   vector< const SMDS_MeshElement* > myElems;
00321   int myIndex;
00322 public:
00323   _MySubIterator(const SMDS_MeshVolume* vol, SMDSAbs_ElementType type):myIndex(0) {
00324     SMDS_VolumeTool vTool(vol);
00325     if (type == SMDSAbs_Face)
00326       vTool.GetAllExistingFaces( myElems );
00327     else
00328       vTool.GetAllExistingFaces( myElems );
00329   }
00331   virtual bool more() { return myIndex < myElems.size(); }
00332 
00334   virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
00335 };
00336 
00337 //=======================================================================
00338 //function : elementsIterator
00339 //purpose  : 
00340 //=======================================================================
00341 
00342 SMDS_ElemIteratorPtr SMDS_QuadraticVolumeOfNodes::elementsIterator
00343                                          (SMDSAbs_ElementType type) const
00344 {
00345   switch(type)
00346   {
00347   case SMDSAbs_Volume:
00348     return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume);
00349   case SMDSAbs_Node:
00350     return SMDS_ElemIteratorPtr(new SMDS_QuadraticVolumeOfNodes_MyIterator(myNodes));
00351   case SMDSAbs_Edge:
00352     return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Edge));
00353     break;
00354   case SMDSAbs_Face:
00355     return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Face));
00356     break;
00357   default:
00358     return SMDS_ElemIteratorPtr
00359       (new SMDS_IteratorOfElements
00360        (this,type,SMDS_ElemIteratorPtr
00361         (new SMDS_QuadraticVolumeOfNodes_MyIterator(myNodes))));
00362   }
00363   return SMDS_ElemIteratorPtr();
00364 }
00365 
00371 const SMDS_MeshNode* SMDS_QuadraticVolumeOfNodes::GetNode(const int ind) const
00372 {
00373   return myNodes[ ind ];
00374 }
00375 
00376 SMDSAbs_EntityType SMDS_QuadraticVolumeOfNodes::GetEntityType() const
00377 {
00378   SMDSAbs_EntityType aType = SMDSEntity_Quad_Tetra;
00379   switch(NbNodes())
00380   {
00381   case 10: aType = SMDSEntity_Quad_Tetra;   break;
00382   case 13: aType = SMDSEntity_Quad_Pyramid; break;
00383   case 15: aType = SMDSEntity_Quad_Penta;   break;
00384   case 20:
00385   default: aType = SMDSEntity_Quad_Hexa;    break;
00386   }
00387   return aType;
00388 }