Salome HOME
4939806e9b5eb03e84181eda06ff784812e6137b
[tools/medcoupling.git] / src / INTERP_KERNEL / MappedBarycentric2DIntersectorP1P1.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 : Adrien Bruneton (CEA/DEN)
20
21 #ifndef __MappedBarycentric2DIntersectorP1P1_TXX__
22 #define __MappedBarycentric2DIntersectorP1P1_TXX__
23
24 #include "MappedBarycentric2DIntersectorP1P1.hxx"
25 #include "PlanarIntersector.txx"
26 #include "CellModel.hxx"
27
28 #include "PointLocatorAlgos.txx"
29 #include "MeshUtils.hxx"
30
31 namespace INTERP_KERNEL
32 {
33   template<class MyMeshType, class MyMatrix>
34   MappedBarycentric2DIntersectorP1P1<MyMeshType,MyMatrix>::MappedBarycentric2DIntersectorP1P1(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 MappedBarycentric2DIntersectorP1P1<MyMeshType,MyMatrix>::intersectCells(ConnType icellT, const std::vector<ConnType>& icellsS, MyMatrix& res)
43   {
44     std::vector<double> CoordsT;
45     PlanarIntersector<MyMeshType,MyMatrix>::getRealTargetCoordinates(OTT<ConnType,numPol>::indFC(icellT),CoordsT);
46     ConnType nbOfNodesT=ToConnType(CoordsT.size())/SPACEDIM;
47     for(typename std::vector<ConnType>::const_iterator iter=icellsS.begin();iter!=icellsS.end();iter++)
48       {
49         NormalizedCellType tS=PlanarIntersector<MyMeshType,MyMatrix>::_meshS.getTypeOfElement(OTT<ConnType,numPol>::indFC(*iter));
50         if(tS!=NORM_QUAD4)
51           throw INTERP_KERNEL::Exception("Invalid source cell detected for meshdim==2. Only QUAD4 supported !");
52         std::vector<double> CoordsS;
53         PlanarIntersector<MyMeshType,MyMatrix>::getRealSourceCoordinates(OTT<ConnType,numPol>::indFC(*iter),CoordsS);
54         std::vector<double> CoordsTTmp(CoordsT);
55         if(SPACEDIM==3)
56           PlanarIntersector<MyMeshType,MyMatrix>::projectionThis(&CoordsS[0],&CoordsTTmp[0],ToConnType(CoordsS.size())/SPACEDIM,nbOfNodesT);
57         const ConnType *startOfCellNodeConnT=PlanarIntersector<MyMeshType,MyMatrix>::_connectT+OTT<ConnType,numPol>::conn2C(PlanarIntersector<MyMeshType,MyMatrix>::_connIndexT[icellT]);
58         for(ConnType nodeIdT=0;nodeIdT<nbOfNodesT;nodeIdT++)
59           {
60             typename MyMatrix::value_type& resRow=res[OTT<ConnType,numPol>::ind2C(startOfCellNodeConnT[nodeIdT])];
61             if( PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg2D(&CoordsTTmp[nodeIdT*SPACEDIM],&CoordsS[0],4,PlanarIntersector<MyMeshType,MyMatrix>::_precision) )
62               {
63                 double mco[2];  // mapped coordinates in the quad4
64                 std::vector<const double*> coo(4);
65                 coo[0]=&CoordsS[0]; coo[1]=&CoordsS[SPACEDIM]; coo[2]=&CoordsS[2*SPACEDIM]; coo[3]=&CoordsS[3*SPACEDIM];
66                 quad_mapped_coords(coo,&CoordsTTmp[nodeIdT*SPACEDIM],mco);
67
68                 // Now use the form function of the QUAD4 to map the field values
69                 double resLoc[4];
70                 // See QUAD4 standard connectivity and cuboid_mapped_coords() convention:
71                 resLoc[0] = (1.-mco[0]) * (1.-mco[1]);
72                 resLoc[1] = (1.-mco[0]) *   mco[1]   ;
73                 resLoc[2] =  mco[0]     *   mco[1]   ;
74                 resLoc[3] =  mco[0]     * (1.-mco[1]);
75
76                 const ConnType *startOfCellNodeConnS=PlanarIntersector<MyMeshType,MyMatrix>::_connectS+OTT<ConnType,numPol>::conn2C(PlanarIntersector<MyMeshType,MyMatrix>::_connIndexS[*iter]);
77                 for(ConnType nodeIdS=0;nodeIdS<4;nodeIdS++)
78                   {
79                     if(fabs(resLoc[nodeIdS])>PlanarIntersector<MyMeshType,MyMatrix>::_precision)
80                       {
81                         ConnType curNodeSInCmode=OTT<ConnType,numPol>::coo2C(startOfCellNodeConnS[nodeIdS]);
82                         typename MyMatrix::value_type::const_iterator iterRes=resRow.find(OTT<ConnType,numPol>::indFC(curNodeSInCmode));
83                         if(iterRes==resRow.end())
84                           resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(curNodeSInCmode),resLoc[nodeIdS]));
85                         else
86                           {
87                             double val=(*iterRes).second+resLoc[nodeIdS];
88                             resRow.erase(OTT<ConnType,numPol>::indFC(curNodeSInCmode));
89                             resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(curNodeSInCmode),val));
90                           }
91                       }
92                   }
93               }
94           }
95       }
96   }
97
98   template<class MyMeshType, class MyMatrix>
99   typename MyMeshType::MyConnType MappedBarycentric2DIntersectorP1P1<MyMeshType,MyMatrix>::getNumberOfRowsOfResMatrix() const
100   {
101     return PlanarIntersector<MyMeshType,MyMatrix>::_meshT.getNumberOfNodes();
102   }
103
104   template<class MyMeshType, class MyMatrix>
105   typename MyMeshType::MyConnType MappedBarycentric2DIntersectorP1P1<MyMeshType,MyMatrix>::getNumberOfColsOfResMatrix() const
106   {
107     return PlanarIntersector<MyMeshType,MyMatrix>::_meshS.getNumberOfNodes();
108   }
109 }
110
111 #endif