Salome HOME
48343d92af343c47d43cda83ff8de72ad55154d5
[modules/med.git] / src / INTERP_KERNEL / PlanarIntersectorP0P1.txx
1 // Copyright (C) 2007-2012  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.
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 #ifndef __PLANARINTERSECTORP0P1_TXX__
20 #define __PLANARINTERSECTORP0P1_TXX__
21
22 #include "PlanarIntersectorP0P1.hxx"
23 #include "InterpolationUtils.hxx"
24 #include "CellModel.hxx"
25
26 namespace INTERP_KERNEL
27 {
28   template<class MyMeshType, class MyMatrix, class ConcreteP0P1Intersector>
29   PlanarIntersectorP0P1<MyMeshType,MyMatrix,ConcreteP0P1Intersector>::PlanarIntersectorP0P1(const MyMeshType& meshT, const MyMeshType& meshS,
30                                                                                             double dimCaracteristic, double precision, double md3DSurf, double medianPlane,
31                                                                                             bool doRotate, int orientation, int printLevel):
32     PlanarIntersector<MyMeshType,MyMatrix>(meshT,meshS,dimCaracteristic,precision,md3DSurf,medianPlane,doRotate,orientation,printLevel)
33   {
34   }
35
36   template<class MyMeshType, class MyMatrix, class ConcreteP0P1Intersector>
37   int PlanarIntersectorP0P1<MyMeshType,MyMatrix,ConcreteP0P1Intersector>::getNumberOfRowsOfResMatrix() const
38   {
39     return PlanarIntersector<MyMeshType,MyMatrix>::_meshT.getNumberOfNodes();
40   }
41
42   template<class MyMeshType, class MyMatrix, class ConcreteP0P1Intersector>
43   int PlanarIntersectorP0P1<MyMeshType,MyMatrix,ConcreteP0P1Intersector>::getNumberOfColsOfResMatrix() const
44   {
45     return PlanarIntersector<MyMeshType,MyMatrix>::_meshS.getNumberOfElements();
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 ConcreteP0P1Intersector>
52   void PlanarIntersectorP0P1<MyMeshType,MyMatrix,ConcreteP0P1Intersector>::intersectCells(ConnType icellT, const std::vector<ConnType>& icellsS, MyMatrix& res)
53   {
54     int nbNodesT=PlanarIntersector<MyMeshType,MyMatrix>::_connIndexT[icellT+1]-PlanarIntersector<MyMeshType,MyMatrix>::_connIndexT[icellT];
55     double triangle[9];
56     double quadrangle[12];
57     std::vector<double> sourceCellCoords;
58     int orientation=1;
59     const ConnType *startOfCellNodeConn=PlanarIntersector<MyMeshType,MyMatrix>::_connectT+OTT<ConnType,numPol>::conn2C(PlanarIntersector<MyMeshType,MyMatrix>::_connIndexT[icellT]);
60     for(int nodeIdT=0;nodeIdT<nbNodesT;nodeIdT++)
61       {
62         ConnType curNodeTInCmode=OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[nodeIdT]);
63         std::copy(PlanarIntersector<MyMeshType,MyMatrix>::_coordsT+curNodeTInCmode*SPACEDIM,
64                   PlanarIntersector<MyMeshType,MyMatrix>::_coordsT+curNodeTInCmode*SPACEDIM+SPACEDIM,triangle);
65         typename MyMatrix::value_type& resRow=res[curNodeTInCmode];
66         for(typename std::vector<ConnType>::const_iterator iter=icellsS.begin();iter!=icellsS.end();iter++)
67           {
68             int iS=*iter;
69             PlanarIntersector<MyMeshType,MyMatrix>::getRealSourceCoordinates(OTT<ConnType,numPol>::indFC(iS),sourceCellCoords);
70             for(int subTriT=1;subTriT<=nbNodesT-2;subTriT++)
71               {
72                 std::copy(PlanarIntersector<MyMeshType,MyMatrix>::_coordsT+OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[(nodeIdT+subTriT)%nbNodesT])*SPACEDIM,
73                           PlanarIntersector<MyMeshType,MyMatrix>::_coordsT+OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[(nodeIdT+subTriT)%nbNodesT])*SPACEDIM+SPACEDIM,
74                           triangle+SPACEDIM);
75                 std::copy(PlanarIntersector<MyMeshType,MyMatrix>::_coordsT+OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[(nodeIdT+subTriT+1)%nbNodesT])*SPACEDIM,
76                           PlanarIntersector<MyMeshType,MyMatrix>::_coordsT+OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[(nodeIdT+subTriT+1)%nbNodesT])*SPACEDIM+SPACEDIM,
77                           triangle+2*SPACEDIM);
78                 fillDualCellOfTri<SPACEDIM>(triangle,quadrangle);
79                 std::vector<double> sourceCellCoordsTmp(sourceCellCoords);
80                 if(SPACEDIM==3)
81                   orientation=PlanarIntersector<MyMeshType,MyMatrix>::projectionThis(&sourceCellCoordsTmp[0],quadrangle,sourceCellCoords.size()/SPACEDIM,4);
82                 NormalizedCellType tS=PlanarIntersector<MyMeshType,MyMatrix>::_meshS.getTypeOfElement(OTT<ConnType,numPol>::indFC(iS));
83                 double surf=orientation*intersectGeometryWithQuadrangle(quadrangle,sourceCellCoordsTmp,CellModel::GetCellModel(tS).isQuadratic());
84                 surf=PlanarIntersector<MyMeshType,MyMatrix>::getValueRegardingOption(surf);
85                 if(surf!=0.)
86                   {
87                     typename MyMatrix::value_type::const_iterator iterRes=resRow.find(OTT<ConnType,numPol>::indFC(iS));
88                     if(iterRes==resRow.end())
89                       resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(iS),surf));
90                     else
91                       {
92                         double val=(*iterRes).second+surf;
93                         resRow.erase(OTT<ConnType,numPol>::indFC(iS));
94                         resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(iS),val));
95                       }
96                   }
97               }
98           }
99       }
100   }
101 }
102
103 #endif