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