Salome HOME
2f9d0d9236e151e8953e2e719156a5d6fa9caa25
[tools/medcoupling.git] / src / INTERP_KERNEL / CurveIntersectorP1P1PL.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 (EDF R&D)
20
21 #pragma once
22
23 #include "CurveIntersectorP1P1PL.hxx"
24 #include "CurveIntersector.txx"
25
26 #include <cassert>
27
28 namespace INTERP_KERNEL
29 {
30   template<class MyMeshType, class MyMatrix>
31   CurveIntersectorP1P1PL<MyMeshType,MyMatrix>::CurveIntersectorP1P1PL(const MyMeshType& meshT, const MyMeshType& meshS, double precision, double tolerance, double medianLine, int printLevel):CurveIntersector<MyMeshType,MyMatrix>(meshT, meshS, precision, tolerance, medianLine, printLevel)
32   {
33   }
34
35   template<class MyMeshType, class MyMatrix>
36   typename MyMeshType::MyConnType CurveIntersectorP1P1PL<MyMeshType,MyMatrix>::getNumberOfRowsOfResMatrix() const
37   {
38     return this->_meshT.getNumberOfNodes();
39   }
40
41   template<class MyMeshType, class MyMatrix>
42   typename MyMeshType::MyConnType CurveIntersectorP1P1PL<MyMeshType,MyMatrix>::getNumberOfColsOfResMatrix() const
43   {
44     return this->_meshS.getNumberOfNodes();
45   }
46
47   template<class MyMeshType, class MyMatrix>
48   void CurveIntersectorP1P1PL<MyMeshType,MyMatrix>::AppendValueInMatrix2(typename MyMatrix::value_type& resRow, ConnType nodeIdS0, double val0)
49   {
50     typename MyMatrix::value_type::const_iterator iterRes(resRow.find(OTT<ConnType,numPol>::indFC(nodeIdS0)));    
51     if(iterRes==resRow.end())
52       {
53         resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(nodeIdS0),val0));
54       }
55     else
56       {
57         double val((*iterRes).second+val0);
58         resRow.erase(OTT<ConnType,numPol>::indFC(nodeIdS0));
59         resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(nodeIdS0),val));
60       }
61   }
62
63   template<class MyMeshType, class MyMatrix>
64   void CurveIntersectorP1P1PL<MyMeshType,MyMatrix>::AppendValueInMatrix(MyMatrix& res, ConnType nodeIdT, ConnType nodeIdS0, double val0, ConnType nodeIdS1, double val1)
65   {
66     typename MyMatrix::value_type& resRow(res[nodeIdT]);
67     if(std::abs(val0)>0.)
68       AppendValueInMatrix2(resRow,nodeIdS0,val0);
69     if(std::abs(val1)>0.)
70       AppendValueInMatrix2(resRow,nodeIdS1,val1);
71   }
72
73   template<class MyMeshType, class MyMatrix>
74   void CurveIntersectorP1P1PL<MyMeshType,MyMatrix>::intersectCells(ConnType icellT, const std::vector<ConnType>& icellsS, MyMatrix& res)
75   {
76     std::vector<double> coordsT;
77     if(this->getRealTargetCoordinates(icellT,coordsT))
78       throw INTERP_KERNEL::Exception("Invalid target cell detected for meshdim==1. Only SEG2 supported !");
79     mcIdType nbOfNodesT(ToIdType(coordsT.size()/SPACEDIM));
80     for(typename std::vector<ConnType>::const_iterator iter=icellsS.begin();iter!=icellsS.end();iter++)
81       {
82         std::vector<double> coordsS;
83         if(this->getRealSourceCoordinates(*iter,coordsS))
84           throw INTERP_KERNEL::Exception("Invalid source cell detected for meshdim==1. Only SEG2 supported !");
85         assert(coordsS.size()/SPACEDIM==2);
86         ConnType nodeIdS0(this->getNodeIdOfSourceCellAt(*iter,0));
87         ConnType nodeIdS1(this->getNodeIdOfSourceCellAt(*iter,1));
88         for(mcIdType nodeIdT = 0 ; nodeIdT<nbOfNodesT ; ++nodeIdT)
89           {
90             ConnType nodeIdT0(this->getNodeIdOfTargetCellAt(icellT,nodeIdT));
91             double xs0,xs1,xt;
92             if( this->isPtIncludedInSeg(coordsT.data()+nodeIdT*SPACEDIM,coordsS.data(),xs0,xs1,xt) )
93               {
94                 double a,b;
95                 this->ComputeBaryCoordsOf(xs0,xs1,xt,a,b);
96                 AppendValueInMatrix(res,nodeIdT0,nodeIdS0,a,nodeIdS1,b);
97               }
98           }
99       }
100   }
101 }