1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Adrien Bruneton (CEA/DEN)
21 #ifndef __MappedBarycentric2DIntersectorP1P1_TXX__
22 #define __MappedBarycentric2DIntersectorP1P1_TXX__
24 #include "MappedBarycentric2DIntersectorP1P1.hxx"
25 #include "PlanarIntersector.txx"
26 #include "CellModel.hxx"
28 #include "PointLocatorAlgos.txx"
29 #include "MeshUtils.hxx"
31 namespace INTERP_KERNEL
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)
41 template<class MyMeshType, class MyMatrix>
42 void MappedBarycentric2DIntersectorP1P1<MyMeshType,MyMatrix>::intersectCells(ConnType icellT, const std::vector<ConnType>& icellsS, MyMatrix& res)
44 std::vector<double> CoordsT;
45 PlanarIntersector<MyMeshType,MyMatrix>::getRealTargetCoordinates(OTT<ConnType,numPol>::indFC(icellT),CoordsT);
46 int nbOfNodesT=CoordsT.size()/SPACEDIM;
47 for(typename std::vector<ConnType>::const_iterator iter=icellsS.begin();iter!=icellsS.end();iter++)
49 NormalizedCellType tS=PlanarIntersector<MyMeshType,MyMatrix>::_meshS.getTypeOfElement(OTT<ConnType,numPol>::indFC(*iter));
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);
56 PlanarIntersector<MyMeshType,MyMatrix>::projectionThis(&CoordsS[0],&CoordsTTmp[0],CoordsS.size()/SPACEDIM,nbOfNodesT);
57 const ConnType *startOfCellNodeConnT=PlanarIntersector<MyMeshType,MyMatrix>::_connectT+OTT<ConnType,numPol>::conn2C(PlanarIntersector<MyMeshType,MyMatrix>::_connIndexT[icellT]);
58 for(int nodeIdT=0;nodeIdT<nbOfNodesT;nodeIdT++)
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) )
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);
68 // Now use the form function of the QUAD4 to map the field values
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]);
76 const ConnType *startOfCellNodeConnS=PlanarIntersector<MyMeshType,MyMatrix>::_connectS+OTT<ConnType,numPol>::conn2C(PlanarIntersector<MyMeshType,MyMatrix>::_connIndexS[*iter]);
77 for(int nodeIdS=0;nodeIdS<4;nodeIdS++)
79 if(fabs(resLoc[nodeIdS])>PlanarIntersector<MyMeshType,MyMatrix>::_precision)
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]));
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));
98 template<class MyMeshType, class MyMatrix>
99 int MappedBarycentric2DIntersectorP1P1<MyMeshType,MyMatrix>::getNumberOfRowsOfResMatrix() const
101 return PlanarIntersector<MyMeshType,MyMatrix>::_meshT.getNumberOfNodes();
104 template<class MyMeshType, class MyMatrix>
105 int MappedBarycentric2DIntersectorP1P1<MyMeshType,MyMatrix>::getNumberOfColsOfResMatrix() const
107 return PlanarIntersector<MyMeshType,MyMatrix>::_meshS.getNumberOfNodes();