Salome HOME
Copyright update 2021
[tools/medcoupling.git] / src / INTERP_KERNEL / PlanarIntersectorP1P0.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 __PLANARINTERSECTORP1P0_TXX__
21 #define __PLANARINTERSECTORP1P0_TXX__
22
23 #include "PlanarIntersectorP1P0.hxx"
24 #include "InterpolationUtils.hxx"
25
26 namespace INTERP_KERNEL
27 {
28   template<class MyMeshType, class MyMatrix, class ConcreteP1P0Intersector>
29   PlanarIntersectorP1P0<MyMeshType,MyMatrix,ConcreteP1P0Intersector>::PlanarIntersectorP1P0(const MyMeshType& meshT, const MyMeshType& meshS,
30                                                                                             double dimCaracteristic, double precision, double md3DSurf, double minDot3DSurf, double medianPlane,
31                                                                                             bool doRotate, int orientation, int printLevel):
32     PlanarIntersector<MyMeshType,MyMatrix>(meshT,meshS,dimCaracteristic,precision,md3DSurf,minDot3DSurf,medianPlane,doRotate,orientation,printLevel)
33   {
34   }
35
36   template<class MyMeshType, class MyMatrix, class ConcreteP1P0Intersector>
37   typename MyMeshType::MyConnType PlanarIntersectorP1P0<MyMeshType,MyMatrix,ConcreteP1P0Intersector>::getNumberOfRowsOfResMatrix() const
38   {
39     return PlanarIntersector<MyMeshType,MyMatrix>::_meshT.getNumberOfElements();
40   }
41
42   template<class MyMeshType, class MyMatrix, class ConcreteP1P0Intersector>
43   typename MyMeshType::MyConnType PlanarIntersectorP1P0<MyMeshType,MyMatrix,ConcreteP1P0Intersector>::getNumberOfColsOfResMatrix() const
44   {
45     return PlanarIntersector<MyMeshType,MyMatrix>::_meshS.getNumberOfNodes();
46   }
47
48   /*!
49    * This methods split on the fly, into triangles in order to compute dual mesh of target cell (with icellT id in target mesh in C mode).
50    */
51   template<class MyMeshType, class MyMatrix, class ConcreteP1P0Intersector>
52   void PlanarIntersectorP1P0<MyMeshType,MyMatrix,ConcreteP1P0Intersector>::intersectCells(ConnType icellT, const std::vector<ConnType>& icellsS, MyMatrix& res)
53   {
54     double triangle[9];
55     double quadrangle[12];
56     std::vector<double> targetCellCoords;
57     int orientation=1;
58     PlanarIntersector<MyMeshType,MyMatrix>::getRealTargetCoordinates(OTT<ConnType,numPol>::indFC(icellT),targetCellCoords);
59     NormalizedCellType tT=PlanarIntersector<MyMeshType,MyMatrix>::_meshT.getTypeOfElement(OTT<ConnType,numPol>::indFC(icellT));
60     bool isTargetQuad=CellModel::GetCellModel(tT).isQuadratic();
61     typename MyMatrix::value_type& resRow=res[icellT];
62     for(typename std::vector<ConnType>::const_iterator iter=icellsS.begin();iter!=icellsS.end();iter++)
63       {
64         ConnType iS=*iter;
65         ConnType nbNodesS=PlanarIntersector<MyMeshType,MyMatrix>::_connIndexS[iS+1]-PlanarIntersector<MyMeshType,MyMatrix>::_connIndexS[iS];
66         const ConnType *startOfCellNodeConn=PlanarIntersector<MyMeshType,MyMatrix>::_connectS+OTT<ConnType,numPol>::conn2C(PlanarIntersector<MyMeshType,MyMatrix>::_connIndexS[iS]);
67         for(ConnType nodeIdS=0;nodeIdS<nbNodesS;nodeIdS++)
68           {
69             ConnType curNodeSInCmode=OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[nodeIdS]);
70             std::copy(PlanarIntersector<MyMeshType,MyMatrix>::_coordsS+curNodeSInCmode*SPACEDIM,
71                       PlanarIntersector<MyMeshType,MyMatrix>::_coordsS+curNodeSInCmode*SPACEDIM+SPACEDIM,triangle);
72             for(ConnType subTriS=1;subTriS<=nbNodesS-2;subTriS++)
73               {
74                 std::copy(PlanarIntersector<MyMeshType,MyMatrix>::_coordsS+OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[(nodeIdS+subTriS)%nbNodesS])*SPACEDIM,
75                           PlanarIntersector<MyMeshType,MyMatrix>::_coordsS+OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[(nodeIdS+subTriS)%nbNodesS])*SPACEDIM+SPACEDIM,
76                           triangle+SPACEDIM);
77                 std::copy(PlanarIntersector<MyMeshType,MyMatrix>::_coordsS+OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[(nodeIdS+subTriS+1)%nbNodesS])*SPACEDIM,
78                           PlanarIntersector<MyMeshType,MyMatrix>::_coordsS+OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[(nodeIdS+subTriS+1)%nbNodesS])*SPACEDIM+SPACEDIM,
79                           triangle+2*SPACEDIM);
80                 fillDualCellOfTri<SPACEDIM>(triangle,quadrangle);
81                 std::vector<double> targetCellCoordsTmp(targetCellCoords);
82                 if(SPACEDIM==3)
83                   orientation=PlanarIntersector<MyMeshType,MyMatrix>::projectionThis(&targetCellCoordsTmp[0],quadrangle,ToConnType(targetCellCoords.size())/SPACEDIM,4);
84                 double surf=orientation*intersectGeometryWithQuadrangle(quadrangle,targetCellCoordsTmp,isTargetQuad);
85                 surf=PlanarIntersector<MyMeshType,MyMatrix>::getValueRegardingOption(surf);
86                 if(surf!=0.)
87                   {
88                     typename MyMatrix::value_type::const_iterator iterRes=resRow.find(OTT<ConnType,numPol>::indFC(curNodeSInCmode));
89                     if(iterRes==resRow.end())
90                       resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(curNodeSInCmode),surf));
91                     else
92                       {
93                         double val=(*iterRes).second+surf;
94                         resRow.erase(OTT<ConnType,numPol>::indFC(curNodeSInCmode));
95                         resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(curNodeSInCmode),val));
96                       }
97                   }
98               }
99           }
100       }
101   }
102 }
103
104 #endif