1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef __MESHUTILS_HXX__
21 #define __MESHUTILS_HXX__
23 #include "InterpolationUtils.hxx"
25 namespace INTERP_KERNEL
28 * Returns the global number of the node of an element.
30 * @param node the node for which the global number is sought (ALWAYS in C mode)
31 * @param element an element of the mesh (in numPol policy)
33 * @return the node's global number so that (its coordinates in the coordinates array are at [SPACEDIM*globalNumber, SPACEDIM*globalNumber + SPACEDIM]
35 template<class MyMeshType>
36 inline typename MyMeshType::MyConnType getGlobalNumberOfNode(typename MyMeshType::MyConnType node, typename MyMeshType::MyConnType element, const MyMeshType& mesh)
38 typedef typename MyMeshType::MyConnType ConnType;
39 const NumberingPolicy numPol=MyMeshType::My_numPol;
40 const ConnType elemIdx=OTT<ConnType,numPol>::conn2C(mesh.getConnectivityIndexPtr()[OTT<ConnType,numPol>::ind2C(element)]);
41 if(mesh.getTypeOfElement(element)!=INTERP_KERNEL::NORM_POLYHED)
42 return OTT<ConnType,numPol>::coo2C(mesh.getConnectivityPtr()[elemIdx + node]);
45 const ConnType *startNodalConnOfElem=mesh.getConnectivityPtr()+elemIdx;
47 while(startNodalConnOfElem[ret]==-1 || ptr!=node)
50 if(startNodalConnOfElem[ret]!=-1)
53 return OTT<ConnType,numPol>::coo2C(startNodalConnOfElem[ret]);
58 * Returns the coordinates of a node of an element
60 * @param node the node for which the coordinates are sought. In C mode.
61 * @param element an element of the mesh. In mesh policy.
63 * @return pointer to an array of 3 doubles containing the coordinates of the node
65 template<class MyMeshType>
66 inline const double* getCoordsOfNode(typename MyMeshType::MyConnType node, typename MyMeshType::MyConnType element, const MyMeshType& mesh)
68 typedef typename MyMeshType::MyConnType ConnType;
69 const ConnType connIdx = getGlobalNumberOfNode(node, element, mesh);
70 const double *ret=mesh.getCoordinatesPtr()+MyMeshType::MY_SPACEDIM*connIdx;
75 * Returns the coordinates of a node of an element
77 * @param node the node for which the coordinates are sought. In C mode.
78 * @param element an element of the mesh. In mesh policy.
80 * @param nodeId globale nodeId in whole mesh point of view in C mode.
81 * @return pointer to an array of 3 doubles containing the coordinates of the node
83 template<class MyMeshType>
84 inline const double* getCoordsOfNode2(typename MyMeshType::MyConnType node, typename MyMeshType::MyConnType element, const MyMeshType& mesh, typename MyMeshType::MyConnType& nodeId)
86 typedef typename MyMeshType::MyConnType ConnType;
87 nodeId= getGlobalNumberOfNode(node, element, mesh);
88 return mesh.getCoordinatesPtr()+MyMeshType::MY_SPACEDIM*nodeId;
92 * Returns the barycentric coordinates of a point within a triangle or tetrahedron
94 * @param point the point for which the barycentric coordinates are sought
95 * @param element an element of the mesh
97 * @param barycentricCoords an array of 3 doubles containing the coordinates of the node
99 template<class MyMeshType, int NB_NODES>
100 inline void getBarycentricCoordinates(const double* point,
101 typename MyMeshType::MyConnType element,
102 const MyMeshType& mesh,
103 double* barycentricCoords)
105 std::vector<const double*> nodes( NB_NODES );
106 for ( int node = 0; node < NB_NODES; ++node )
108 nodes[ node ] = getCoordsOfNode( node, element, mesh );
110 barycentric_coords( nodes, point, barycentricCoords );