Back to index

salome-med  6.5.0
MeshUtils.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #ifndef __MESHUTILS_HXX__
00021 #define __MESHUTILS_HXX__
00022 
00023 #include "InterpolationUtils.hxx"
00024 
00025 namespace INTERP_KERNEL
00026 {
00035   template<class MyMeshType>
00036   inline typename MyMeshType::MyConnType getGlobalNumberOfNode(typename MyMeshType::MyConnType node, typename MyMeshType::MyConnType element, const MyMeshType& mesh)
00037   {
00038     typedef typename MyMeshType::MyConnType ConnType;
00039     const NumberingPolicy numPol=MyMeshType::My_numPol;
00040     const ConnType elemIdx=OTT<ConnType,numPol>::conn2C(mesh.getConnectivityIndexPtr()[OTT<ConnType,numPol>::ind2C(element)]);
00041     if(mesh.getTypeOfElement(element)!=INTERP_KERNEL::NORM_POLYHED)
00042       return OTT<ConnType,numPol>::coo2C(mesh.getConnectivityPtr()[elemIdx + node]);
00043     else
00044       {
00045         const ConnType *startNodalConnOfElem=mesh.getConnectivityPtr()+elemIdx;
00046         ConnType ptr=0,ret=0;
00047         while(startNodalConnOfElem[ret]==-1 || ptr!=node)
00048           {
00049             ret++;
00050             if(startNodalConnOfElem[ret]!=-1)
00051               ptr++;
00052           }
00053         return OTT<ConnType,numPol>::coo2C(startNodalConnOfElem[ret]);
00054       }
00055   }
00056 
00065   template<class MyMeshType>
00066   inline const double* getCoordsOfNode(typename MyMeshType::MyConnType node, typename MyMeshType::MyConnType element, const MyMeshType& mesh)
00067   {
00068     typedef typename MyMeshType::MyConnType ConnType;
00069     const ConnType connIdx = getGlobalNumberOfNode(node, element, mesh);
00070     const double *ret=mesh.getCoordinatesPtr()+MyMeshType::MY_SPACEDIM*connIdx;
00071     return ret;
00072   }
00073 
00083   template<class MyMeshType>
00084   inline const double* getCoordsOfNode2(typename MyMeshType::MyConnType node, typename MyMeshType::MyConnType element, const MyMeshType& mesh, typename MyMeshType::MyConnType& nodeId)
00085   {
00086     typedef typename MyMeshType::MyConnType ConnType;
00087     nodeId= getGlobalNumberOfNode(node, element, mesh);
00088     return mesh.getCoordinatesPtr()+MyMeshType::MY_SPACEDIM*nodeId;
00089   }
00090 
00099   template<class MyMeshType, int NB_NODES>
00100   inline void getBarycentricCoordinates(const double*                   point,
00101                                         typename MyMeshType::MyConnType element,
00102                                         const MyMeshType&               mesh,
00103                                         double*                         barycentricCoords)
00104   {
00105     std::vector<const double*> nodes( NB_NODES );
00106     for ( int node = 0; node < NB_NODES; ++node )
00107       {
00108         nodes[ node ] = getCoordsOfNode( node, element, mesh );
00109       }
00110     barycentric_coords( nodes, point, barycentricCoords );
00111   }
00112     
00113 }
00114 
00115 #endif