Salome HOME
6cf35469bf0eee8128a21cabaa2c7e66baf7e8e7
[tools/medcoupling.git] / src / INTERP_KERNEL / PlanarIntersectorP1P0PL.txx
1 // Copyright (C) 2007-2019  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 __PLANARINTERSECTORP1P0PL_TXX__
21 #define __PLANARINTERSECTORP1P0PL_TXX__
22
23 #include "PlanarIntersectorP1P0PL.hxx"
24 #include "PlanarIntersector.txx"
25 #include "CellModel.hxx"
26
27 #include "PointLocatorAlgos.txx"
28 #include "InterpKernelGeo2DQuadraticPolygon.hxx"
29 #include "MeshUtils.hxx"
30
31 namespace INTERP_KERNEL
32 {
33   template<class MyMeshType, class MyMatrix>
34   PlanarIntersectorP1P0PL<MyMeshType,MyMatrix>::PlanarIntersectorP1P0PL(const MyMeshType& meshT, const MyMeshType& meshS,
35                                                                         double dimCaracteristic, double md3DSurf, double minDot3DSurf,
36                                                                         double medianPlane, double precision, int orientation):
37     PlanarIntersector<MyMeshType,MyMatrix>(meshT,meshS,dimCaracteristic,precision,md3DSurf,minDot3DSurf,medianPlane,true,orientation,0)
38   {
39   }
40
41   template<class MyMeshType, class MyMatrix>
42   void PlanarIntersectorP1P0PL<MyMeshType,MyMatrix>::intersectCells(ConnType icellT, const std::vector<ConnType>& icellsS, MyMatrix& res)
43   {
44     std::vector<double> CoordsT;
45     typename MyMatrix::value_type& resRow=res[icellT];
46     PlanarIntersector<MyMeshType,MyMatrix>::getRealTargetCoordinates(OTT<ConnType,numPol>::indFC(icellT),CoordsT);
47     double baryT[SPACEDIM];
48     double baryTTmp[SPACEDIM];
49     calculateBarycenterDyn2<SPACEDIM>(&CoordsT[0],ToConnType(CoordsT.size())/SPACEDIM,baryT);
50     for(typename std::vector<ConnType>::const_iterator iter=icellsS.begin();iter!=icellsS.end();iter++)
51       {
52         NormalizedCellType tS=PlanarIntersector<MyMeshType,MyMatrix>::_meshS.getTypeOfElement(OTT<ConnType,numPol>::indFC(*iter));
53         if(tS!=NORM_TRI3)
54           throw INTERP_KERNEL::Exception("Invalid source cell detected for meshdim==2. Only TRI3 supported !");
55         std::vector<double> CoordsS;
56         PlanarIntersector<MyMeshType,MyMatrix>::getRealSourceCoordinates(OTT<ConnType,numPol>::indFC(*iter),CoordsS);
57         if(SPACEDIM==2)
58           {
59             std::copy(baryT,baryT+SPACEDIM,baryTTmp);
60           }
61         else
62           {
63             double littleTargetCell[9];
64             std::copy(baryT,baryT+SPACEDIM,littleTargetCell);
65             std::copy(CoordsT.begin(),CoordsT.begin()+3,littleTargetCell+3);
66             std::copy(CoordsT.begin()+3,CoordsT.begin()+6,littleTargetCell+6);
67             PlanarIntersector<MyMeshType,MyMatrix>::projectionThis(&CoordsS[0],littleTargetCell,3,3);
68             std::copy(littleTargetCell,littleTargetCell+3,baryTTmp);
69           }
70         if(PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg2D(baryTTmp,&CoordsS[0],3,PlanarIntersector<MyMeshType,MyMatrix>::_precision))
71           {
72             double resLoc[3];
73             barycentric_coords<SPACEDIM>(&CoordsS[0],baryTTmp,resLoc);
74             const ConnType *startOfCellNodeConnS=PlanarIntersector<MyMeshType,MyMatrix>::_connectS+OTT<ConnType,numPol>::conn2C(PlanarIntersector<MyMeshType,MyMatrix>::_connIndexS[*iter]);
75             for(int nodeIdS=0;nodeIdS<3;nodeIdS++)
76               {
77                 if(fabs(resLoc[nodeIdS])>PlanarIntersector<MyMeshType,MyMatrix>::_precision)
78                   {
79                     ConnType curNodeSInCmode=OTT<ConnType,numPol>::coo2C(startOfCellNodeConnS[nodeIdS]);
80                     typename MyMatrix::value_type::const_iterator iterRes=resRow.find(OTT<ConnType,numPol>::indFC(curNodeSInCmode));
81                     if(iterRes==resRow.end())
82                       resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(curNodeSInCmode),resLoc[nodeIdS]));
83                     else
84                       {
85                         double val=(*iterRes).second+resLoc[nodeIdS];
86                         resRow.erase(OTT<ConnType,numPol>::indFC(curNodeSInCmode));
87                         resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(curNodeSInCmode),val));
88                       }
89                   }
90               }
91           }
92       }
93   }
94
95   template<class MyMeshType, class MyMatrix>
96   typename MyMeshType::MyConnType PlanarIntersectorP1P0PL<MyMeshType,MyMatrix>::getNumberOfRowsOfResMatrix() const
97   {
98     return PlanarIntersector<MyMeshType,MyMatrix>::_meshT.getNumberOfElements();
99   }
100   
101   template<class MyMeshType, class MyMatrix>
102   typename MyMeshType::MyConnType PlanarIntersectorP1P0PL<MyMeshType,MyMatrix>::getNumberOfColsOfResMatrix() const
103   {
104     return PlanarIntersector<MyMeshType,MyMatrix>::_meshS.getNumberOfNodes();
105   }
106 }
107
108 #endif