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
19 // Author : Anthony Geay (CEA/DEN)
20 #ifndef __PolyhedronIntersectorP1P0Bary_TXX__
21 #define __PolyhedronIntersectorP1P0Bary_TXX__
23 #include "PolyhedronIntersectorP1P0Bary.hxx"
24 #include "Intersector3DP1P0Bary.txx"
25 #include "MeshUtils.hxx"
27 #include "SplitterTetra.txx"
29 namespace INTERP_KERNEL
33 * Constructor creating object from target cell global number
34 * The constructor first calculates the necessary nodes,
35 * (depending on the splitting policy) and then splits the hexahedron into
36 * tetrahedra, placing these in the internal vector _tetra.
38 * @param targetMesh mesh containing the target elements
39 * @param srcMesh mesh containing the source elements
40 * @param policy splitting policy to be used
42 * WARNING : in _split attribute, sourceMesh and targetMesh are switched in order to fit intersectCells feature.
44 template<class MyMeshType, class MyMatrix>
45 PolyhedronIntersectorP1P0Bary<MyMeshType,MyMatrix>::PolyhedronIntersectorP1P0Bary(const MyMeshType& targetMesh,
46 const MyMeshType& srcMesh,
47 SplittingPolicy policy)
48 :Intersector3DP1P0Bary<MyMeshType,MyMatrix>(targetMesh,srcMesh),_split(targetMesh,srcMesh,policy)
51 // "Limitation. For the P1P0 barycentric improvement only triangle source cells in 2D and
52 // tetrahedrons in 3D will be supported by interpolators. If a non
53 // triangle/tetrahedron source cell is detected an INTERP_KERNEL::Exception should be thrown."
55 // Check types of source elements here rather than in intersectCells() since a wrong type can be
56 // found late after a long time of calculation.
58 const unsigned long numSrcElems = srcMesh.getNumberOfElements();
59 for(unsigned long i = 0 ; i < numSrcElems ; ++i)
60 if ( srcMesh.getTypeOfElement( OTT<ConnType,numPol>::indFC(i) ) != NORM_TETRA4 )
61 throw INTERP_KERNEL::Exception("P1P0 barycentric algorithm works only with tetrahedral source meshes");
66 * Liberates the SplitterTetra objects and potential sub-node points that have been allocated.
69 template<class MyMeshType, class MyMatrix>
70 PolyhedronIntersectorP1P0Bary<MyMeshType,MyMatrix>::~PolyhedronIntersectorP1P0Bary()
75 template<class MyMeshType, class MyMatrix>
76 void PolyhedronIntersectorP1P0Bary<MyMeshType,MyMatrix>::releaseArrays()
78 for(typename std::vector< SplitterTetra<MyMeshType>* >::iterator iter = _tetra.begin(); iter != _tetra.end(); ++iter)
80 _split.releaseArrays();
84 //================================================================================
86 * \brief This method computes a value per each node of source cell for each target cell.
87 * \param srcCell - a source tetrahedron
88 * \param tgtCells - target elements
89 * \param res - matrix to fill in
91 //================================================================================
93 template<class MyMeshType, class MyMatrix>
94 void PolyhedronIntersectorP1P0Bary<MyMeshType,MyMatrix>::intersectCells(ConnType tgtCell,
95 const std::vector<ConnType>& srcCells,
98 typename MyMatrix::value_type& resRow=res[tgtCell];
100 int nbOfNodesT=Intersector3D<MyMeshType,MyMatrix>::_target_mesh.getNumberOfNodesOfElement(OTT<ConnType,numPol>::indFC(tgtCell));
102 _split.splitTargetCell(tgtCell,nbOfNodesT,_tetra);
104 for(typename std::vector<ConnType>::const_iterator iterCellS=srcCells.begin();iterCellS!=srcCells.end();iterCellS++)
106 // intersect a source tetrahedron with each target tetrahedron: get intersection volume and barycenter
107 double baryCentre[SPACEDIM], total_baryCentre[3] = { 0., 0., 0.};
108 double interVolume = 0;
109 for(typename std::vector<SplitterTetra<MyMeshType>*>::iterator iterTetraT = _tetra.begin(); iterTetraT != _tetra.end(); ++iterTetraT)
111 SplitterTetra<MyMeshType> *tmp=*iterTetraT;
112 tmp->clearVolumesCache();
113 double volume = tmp->intersectSourceCell(*iterCellS, baryCentre);
116 interVolume += volume;
117 for ( int i = 0; i < SPACEDIM; ++i )
118 total_baryCentre[i] += baryCentre[i]*volume;
123 for ( int i = 0; i < SPACEDIM; ++i )
124 total_baryCentre[i] /= interVolume;
126 // coordinates of the source tetrahedron
127 std::vector<const double*> srcCellCoords(4);
128 for ( int n = 0; n < 4; ++n )
129 srcCellCoords[ n ] = getCoordsOfNode( n, *iterCellS, Intersector3D<MyMeshType,MyMatrix>::_src_mesh );
131 // compute barycentric coordinates
132 double baryCoords[4];
133 barycentric_coords( srcCellCoords, total_baryCentre, baryCoords);
135 // store coeffs of each node of the source tetrahedron
136 const ConnType *srcCellNodes=Intersector3D<MyMeshType,MyMatrix>::_src_mesh.getConnectivityPtr()+OTT<ConnType,numPol>::conn2C(Intersector3D<MyMeshType,MyMatrix>::_src_mesh.getConnectivityIndexPtr()[*iterCellS]);
137 for ( int n = 0; n < 4; ++n )
139 double val = baryCoords[n] * interVolume;
140 ConnType curNodeS = srcCellNodes[n];
141 typename MyMatrix::value_type::const_iterator iterRes=resRow.find(curNodeS);
142 if(iterRes!=resRow.end())
144 val += iterRes->second;
145 resRow.erase( curNodeS );
147 resRow.insert(std::make_pair(curNodeS,val));