Salome HOME
Update copyrights 2014.
[modules/med.git] / src / INTERP_KERNEL / PointLocator3DIntersectorP1P1.txx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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 // Author : Anthony Geay (CEA/DEN)
20 #ifndef __POINTLOCATOR3DINTERSECTORP1P1_TXX__
21 #define __POINTLOCATOR3DINTERSECTORP1P1_TXX__
22
23 #include "PointLocator3DIntersectorP1P1.hxx"
24 #include "Intersector3DP1P1.txx"
25 #include "MeshUtils.hxx"
26
27 namespace INTERP_KERNEL
28 {
29
30   /**
31    * Constructor creating object from target cell global number 
32    * 
33    * @param targetMesh  mesh containing the target elements
34    * @param srcMesh     mesh containing the source elements
35    * @param policy      splitting policy to be used
36    */
37   template<class MyMeshType, class MyMatrix>
38   PointLocator3DIntersectorP1P1<MyMeshType,MyMatrix>::PointLocator3DIntersectorP1P1(const MyMeshType& targetMesh, const MyMeshType& srcMesh, double precision):
39     Intersector3DP1P1<MyMeshType,MyMatrix>(targetMesh,srcMesh),_precision(precision)
40   {
41   }
42
43   template<class MyMeshType, class MyMatrix>
44   PointLocator3DIntersectorP1P1<MyMeshType,MyMatrix>::~PointLocator3DIntersectorP1P1()
45   {
46   }
47
48   /**
49    * @param targetCell in C mode.
50    * @param srcCells in C mode.
51    */
52   template<class MyMeshType, class MyMatrix>
53   void PointLocator3DIntersectorP1P1<MyMeshType,MyMatrix>::intersectCells(ConnType targetCell, const std::vector<ConnType>& srcCells, MyMatrix& res)
54   {
55     std::vector<double> CoordsT;
56     Intersector3DP1P1<MyMeshType,MyMatrix>::getRealTargetCoordinates(OTT<ConnType,numPol>::indFC(targetCell),CoordsT);
57     int nbOfNodesT=CoordsT.size()/SPACEDIM;
58     const double *coordsS=Intersector3DP1P1<MyMeshType,MyMatrix>::_src_mesh.getCoordinatesPtr();
59     for(typename std::vector<ConnType>::const_iterator iterCellS=srcCells.begin();iterCellS!=srcCells.end();iterCellS++)
60       {
61         NormalizedCellType tS=Intersector3DP1P1<MyMeshType,MyMatrix>::_src_mesh.getTypeOfElement(OTT<ConnType,numPol>::indFC(*iterCellS));
62         if(tS!=NORM_TETRA4)
63           throw INTERP_KERNEL::Exception("Invalid source cell detected for meshdim==3. Only TETRA4 supported !");
64         const CellModel& cmTypeS=CellModel::GetCellModel(tS);
65         const ConnType *startOfCellNodeConnT=Intersector3DP1P1<MyMeshType,MyMatrix>::getStartConnOfTargetCell(targetCell);
66         for(int nodeIdT=0;nodeIdT<nbOfNodesT;nodeIdT++)
67           {
68             typename MyMatrix::value_type& resRow=res[OTT<ConnType,numPol>::ind2C(startOfCellNodeConnT[nodeIdT])];
69             std::vector<ConnType> connOfCurCellS;
70             Intersector3DP1P1<MyMeshType,MyMatrix>::getConnOfSourceCell(OTT<ConnType,numPol>::indFC(*iterCellS),connOfCurCellS);
71             if( PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg3D(&CoordsT[nodeIdT*SPACEDIM],&connOfCurCellS[0],connOfCurCellS.size(),coordsS,cmTypeS,_precision) )
72               {
73                 double resLoc[4];
74                 std::vector<double> localCoordsS;
75                 Intersector3DP1P1<MyMeshType,MyMatrix>::getRealSourceCoordinates(OTT<ConnType,numPol>::indFC(*iterCellS),localCoordsS);
76                 std::vector<const double*> eap(4);
77                 eap[0]=&localCoordsS[0]; eap[1]=&localCoordsS[3]; eap[2]=&localCoordsS[6]; eap[3]=&localCoordsS[9];
78                 barycentric_coords(eap,&CoordsT[nodeIdT*SPACEDIM],resLoc);
79                 const ConnType *startOfCellNodeConnS=Intersector3DP1P1<MyMeshType,MyMatrix>::getStartConnOfSourceCell(*iterCellS);
80                 for(int nodeIdS=0;nodeIdS<4;nodeIdS++)
81                   {
82                     if(fabs(resLoc[nodeIdS])>_precision)
83                       {
84                         ConnType curNodeSInCmode=OTT<ConnType,numPol>::coo2C(startOfCellNodeConnS[nodeIdS]);
85                         typename MyMatrix::value_type::const_iterator iterRes=resRow.find(OTT<ConnType,numPol>::indFC(curNodeSInCmode));
86                         if(iterRes==resRow.end())
87                           resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(curNodeSInCmode),resLoc[nodeIdS]));
88                         else
89                           {
90                             double val=(*iterRes).second+resLoc[nodeIdS];
91                             resRow.erase(OTT<ConnType,numPol>::indFC(curNodeSInCmode));
92                             resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(curNodeSInCmode),val));
93                           }
94                       }
95                   }
96               }
97           }
98       }
99   }
100 }
101
102 #endif