Salome HOME
fcf888b1d277e17a28b04ef5a6639e4b3fcf4cae
[tools/medcoupling.git] / src / INTERP_KERNEL / CurveIntersectorP1P1PL.txx
1 // Copyright (C) 2007-2016  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 #ifndef __CURVEINTERSECTORP1P1PL_TXX__
22 #define __CURVEINTERSECTORP1P1PL_TXX__
23
24 #include "CurveIntersectorP1P1PL.hxx"
25 #include "CurveIntersector.txx"
26
27 #include <cassert>
28
29 namespace INTERP_KERNEL
30 {
31   template<class MyMeshType, class MyMatrix>
32   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)
33   {
34   }
35
36   template<class MyMeshType, class MyMatrix>
37   int CurveIntersectorP1P1PL<MyMeshType,MyMatrix>::getNumberOfRowsOfResMatrix() const
38   {
39     return CurveIntersector<MyMeshType,MyMatrix>::_meshT.getNumberOfNodes();
40   }
41
42   template<class MyMeshType, class MyMatrix>
43   int CurveIntersectorP1P1PL<MyMeshType,MyMatrix>::getNumberOfColsOfResMatrix() const
44   {
45     return CurveIntersector<MyMeshType,MyMatrix>::_meshS.getNumberOfNodes();
46   }
47
48   template<class MyMeshType, class MyMatrix>
49   void CurveIntersectorP1P1PL<MyMeshType,MyMatrix>::AppendValueInMatrix2(typename MyMatrix::value_type& resRow, ConnType nodeIdS0, double val0)
50   {
51     typename MyMatrix::value_type::const_iterator iterRes(resRow.find(OTT<ConnType,numPol>::indFC(nodeIdS0)));    
52     if(iterRes==resRow.end())
53       {
54         resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(nodeIdS0),val0));
55       }
56     else
57       {
58         double val((*iterRes).second+val0);
59         resRow.erase(OTT<ConnType,numPol>::indFC(nodeIdS0));
60         resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(nodeIdS0),val));
61       }
62   }
63
64   template<class MyMeshType, class MyMatrix>
65   void CurveIntersectorP1P1PL<MyMeshType,MyMatrix>::AppendValueInMatrix(MyMatrix& res, ConnType nodeIdT, ConnType nodeIdS0, double val0, ConnType nodeIdS1, double val1)
66   {
67     typename MyMatrix::value_type& resRow(res[nodeIdT]);
68     AppendValueInMatrix2(resRow,nodeIdS0,val0);
69     AppendValueInMatrix2(resRow,nodeIdS1,val1);
70   }
71
72   template<class MyMeshType, class MyMatrix>
73   void CurveIntersectorP1P1PL<MyMeshType,MyMatrix>::intersectCells(ConnType icellT, const std::vector<ConnType>& icellsS, MyMatrix& res)
74   {
75     std::vector<double> coordsT;
76     if(CurveIntersector<MyMeshType,MyMatrix>::getRealTargetCoordinates(icellT,coordsT))
77       throw INTERP_KERNEL::Exception("Invalid target cell detected for meshdim==1. Only SEG2 supported !");
78     assert(coordsT.size()/SPACEDIM==2);
79     for(typename std::vector<ConnType>::const_iterator iter=icellsS.begin();iter!=icellsS.end();iter++)
80       {
81         std::vector<double> coordsS;
82         if(CurveIntersector<MyMeshType,MyMatrix>::getRealSourceCoordinates(*iter,coordsS))
83           throw INTERP_KERNEL::Exception("Invalid source cell detected for meshdim==1. Only SEG2 supported !");
84         assert(coordsS.size()/SPACEDIM==2);
85         double xs0,xs1,xt0,xt1;
86         double lgth(CurveIntersector<MyMeshType,MyMatrix>::intersectSegmentsInternal(&coordsT[0],&coordsS[0],xs0,xs1,xt0,xt1));
87         ConnType nodeIdS0(CurveIntersector<MyMeshType,MyMatrix>::getNodeIdOfSourceCellAt(*iter,0));
88         ConnType nodeIdS1(CurveIntersector<MyMeshType,MyMatrix>::getNodeIdOfSourceCellAt(*iter,1));
89         if(lgth>0.)
90           {
91             double a,b;
92             // for first
93             ConnType nodeIdT0(CurveIntersector<MyMeshType,MyMatrix>::getNodeIdOfTargetCellAt(icellT,0));
94             if(CurveIntersector<MyMeshType,MyMatrix>::ComputeBaryCoordsOf(xs0,xs1,xt0,a,b))
95               {
96                 a*=lgth; b*=lgth;
97                 AppendValueInMatrix(res,nodeIdT0,nodeIdS0,a,nodeIdS1,b);
98               }
99             //
100             ConnType nodeIdT1(CurveIntersector<MyMeshType,MyMatrix>::getNodeIdOfTargetCellAt(icellT,1));
101             typename MyMatrix::value_type& resRow1=res[nodeIdT1];
102             if(CurveIntersector<MyMeshType,MyMatrix>::ComputeBaryCoordsOf(xs0,xs1,xt1,a,b))
103               {
104                 a*=lgth; b*=lgth;
105                 AppendValueInMatrix(res,nodeIdT1,nodeIdS0,a,nodeIdS1,b);
106               }
107           }
108       }
109   }
110 }
111
112 #endif