1 // Copyright (C) 2007-2008 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
19 #ifndef __MESHUTILS_HXX__
20 #define __MESHUTILS_HXX__
22 #include "InterpolationUtils.hxx"
24 namespace INTERP_KERNEL
27 * Returns the global number of the node of an element.
29 * @param node the node for which the global number is sought (ALWAYS in C mode)
30 * @param element an element of the mesh (in numPol policy)
32 * @return the node's global number so that (its coordinates in the coordinates array are at [SPACEDIM*globalNumber, SPACEDIM*globalNumber + 2]
34 template<class MyMeshType>
35 inline typename MyMeshType::MyConnType getGlobalNumberOfNode(typename MyMeshType::MyConnType node, typename MyMeshType::MyConnType element, const MyMeshType& mesh)
37 typedef typename MyMeshType::MyConnType ConnType;
38 const NumberingPolicy numPol=MyMeshType::My_numPol;
39 const ConnType elemIdx=OTT<ConnType,numPol>::conn2C(mesh.getConnectivityIndexPtr()[OTT<ConnType,numPol>::ind2C(element)]);
40 return OTT<ConnType,numPol>::coo2C(mesh.getConnectivityPtr()[elemIdx + node]);
44 * Returns the coordinates of a node of an element
46 * @param node the node for which the coordinates are sought. In C mode.
47 * @param element an element of the mesh. In mesh policy.
49 * @return pointer to an array of 3 doubles containing the coordinates of the node
51 template<class MyMeshType>
52 inline const double* getCoordsOfNode(typename MyMeshType::MyConnType node, typename MyMeshType::MyConnType element, const MyMeshType& mesh)
54 typedef typename MyMeshType::MyConnType ConnType;
55 const ConnType connIdx = getGlobalNumberOfNode(node, element, mesh);
56 return mesh.getCoordinatesPtr()+MyMeshType::MY_SPACEDIM*connIdx;
60 * Returns the coordinates of a node of an element
62 * @param node the node for which the coordinates are sought. In C mode.
63 * @param element an element of the mesh. In mesh policy.
65 * @param nodeId globale nodeId in whole mesh point of view in C mode.
66 * @return pointer to an array of 3 doubles containing the coordinates of the node
68 template<class MyMeshType>
69 inline const double* getCoordsOfNode2(typename MyMeshType::MyConnType node, typename MyMeshType::MyConnType element, const MyMeshType& mesh, typename MyMeshType::MyConnType& nodeId)
71 typedef typename MyMeshType::MyConnType ConnType;
72 nodeId= getGlobalNumberOfNode(node, element, mesh);
73 return mesh.getCoordinatesPtr()+MyMeshType::MY_SPACEDIM*nodeId;
77 * Returns the barycentric coordinates of a point within a triangle or tetrahedron
79 * @param point the point for which the barycentric coordinates are sought
80 * @param element an element of the mesh
82 * @param barycentricCoords an array of 3 doubles containing the coordinates of the node
84 template<class MyMeshType, int NB_NODES>
85 inline void getBarycentricCoordinates(const double* point,
86 typename MyMeshType::MyConnType element,
87 const MyMeshType& mesh,
88 double* barycentricCoords)
90 std::vector<const double*> nodes( NB_NODES );
91 typedef typename MyMeshType::MyConnType ConnType;
92 for ( int node = 0; node < NB_NODES; ++node )
94 nodes[ node ] = getCoordsOfNode( node, element, mesh );
96 barycentric_coords( nodes, point, barycentricCoords );