Salome HOME
3a941337d517d00a370afc71d4a410deb3631979
[modules/med.git] / src / INTERP_KERNEL / PointLocator3DIntersectorP1P0.txx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #ifndef __POINTLOCATOR3DINTERSECTORP1P0_TXX__
20 #define __POINTLOCATOR3DINTERSECTORP1P0_TXX__
21
22 #include "PointLocator3DIntersectorP1P0.hxx"
23 #include "Intersector3DP1P0.txx"
24 #include "MeshUtils.hxx"
25
26 namespace INTERP_KERNEL
27 {
28   /**
29    * @param targetMesh  mesh containing the target elements
30    * @param srcMesh     mesh containing the source elements
31    * @param policy      splitting policy to be used
32    *
33    * WARNING : in _split attribute, sourceMesh and targetMesh are switched in order to fit intersectCells feature.
34    */
35   template<class MyMeshType, class MyMatrix>
36   PointLocator3DIntersectorP1P0<MyMeshType,MyMatrix>::PointLocator3DIntersectorP1P0(const MyMeshType& targetMesh, const MyMeshType& srcMesh, double precision):Intersector3DP1P0<MyMeshType,MyMatrix>(targetMesh,srcMesh),_precision(precision)
37   {
38   }
39
40   template<class MyMeshType, class MyMatrix>
41   PointLocator3DIntersectorP1P0<MyMeshType,MyMatrix>::~PointLocator3DIntersectorP1P0()
42   {
43   }
44
45   /**
46    * @param targetCell in C mode.
47    * @param srcCells in C mode.
48    *
49    * WARNING : for all methods on _split object source and target are switched !
50    */
51   template<class MyMeshType, class MyMatrix>
52   void PointLocator3DIntersectorP1P0<MyMeshType,MyMatrix>::intersectCells(ConnType targetCell, const std::vector<ConnType>& srcCells, MyMatrix& res)
53   {
54     std::vector<double> CoordsT;
55     typename MyMatrix::value_type& resRow=res[targetCell];
56     const double *coordsS=Intersector3DP1P0<MyMeshType,MyMatrix>::_src_mesh.getCoordinatesPtr();
57     Intersector3DP1P0<MyMeshType,MyMatrix>::getRealTargetCoordinates(OTT<ConnType,numPol>::indFC(targetCell),CoordsT);
58     double baryT[SPACEDIM];
59     calculateBarycenterDyn2<SPACEDIM>(&CoordsT[0],CoordsT.size()/SPACEDIM,baryT);
60     for(typename std::vector<ConnType>::const_iterator iterCellS=srcCells.begin();iterCellS!=srcCells.end();iterCellS++)
61       {
62         NormalizedCellType tS=Intersector3DP1P0<MyMeshType,MyMatrix>::_src_mesh.getTypeOfElement(OTT<ConnType,numPol>::indFC(*iterCellS));
63         if(tS!=NORM_TETRA4)
64           throw INTERP_KERNEL::Exception("Invalid source cell detected for meshdim==3. Only TETRA4 supported !");
65         const CellModel& cmTypeS=CellModel::GetCellModel(tS);
66         std::vector<ConnType> connOfCurCellS;
67         Intersector3DP1P0<MyMeshType,MyMatrix>::getConnOfSourceCell(OTT<ConnType,numPol>::indFC(*iterCellS),connOfCurCellS);
68         if( PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg3D(baryT,&connOfCurCellS[0],connOfCurCellS.size(),coordsS,cmTypeS,_precision) )
69           {
70             double resLoc[4];
71             std::vector<double> srcCell;
72             Intersector3DP1P0<MyMeshType,MyMatrix>::getRealSourceCoordinates(OTT<ConnType,numPol>::indFC(*iterCellS),srcCell);
73             std::vector<const double*> eap(4);
74             eap[0]=&srcCell[0]; eap[1]=&srcCell[3]; eap[2]=&srcCell[6]; eap[3]=&srcCell[9];
75             barycentric_coords(eap,baryT,resLoc);
76             const ConnType *startOfCellNodeConn=Intersector3DP1P0<MyMeshType,MyMatrix>::getStartConnOfSourceCell(*iterCellS);
77             for(int nodeIdS=0;nodeIdS<4;nodeIdS++)
78               {
79                 if(fabs(resLoc[nodeIdS])>_precision)
80                   {
81                     ConnType curNodeSInCmode=OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[nodeIdS]);
82                     typename MyMatrix::value_type::const_iterator iterRes=resRow.find(OTT<ConnType,numPol>::indFC(curNodeSInCmode));
83                     if(iterRes==resRow.end())
84                       resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(curNodeSInCmode),resLoc[nodeIdS]));
85                     else
86                       {
87                         double val=(*iterRes).second+resLoc[nodeIdS];
88                         resRow.erase(OTT<ConnType,numPol>::indFC(curNodeSInCmode));
89                         resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(curNodeSInCmode),val));
90                       }
91                   }
92               }
93           }
94       }
95   }
96 }
97
98 #endif