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