1 // Copyright (C) 2007-2014 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 : Anthony Geay (CEA/DEN)
21 #ifndef __PlanarIntersectorP0P1Bary_TXX__
22 #define __PlanarIntersectorP0P1Bary_TXX__
24 #include "PlanarIntersectorP0P1Bary.hxx"
25 #include "InterpolationUtils.hxx"
27 namespace INTERP_KERNEL
29 template<class MyMeshType, class MyMatrix, class ConcreteP0P1Intersector>
30 PlanarIntersectorP0P1Bary<MyMeshType,MyMatrix,ConcreteP0P1Intersector>::PlanarIntersectorP0P1Bary(const MyMeshType& meshT, const MyMeshType& meshS,
31 double dimCaracteristic, double precision,
32 double md3DSurf, double minDot3DSurf, double medianPlane,
33 bool doRotate, int orientation, int printLevel):
34 PlanarIntersector<MyMeshType,MyMatrix>(meshT,meshS,dimCaracteristic,precision,md3DSurf,minDot3DSurf,
35 medianPlane,doRotate,orientation,printLevel)
38 // "Limitation. For the P0P1 barycentric improvement only triangle target cells in 2D and
39 // tetrahedrons in 3D will be supported by interpolators. If a non
40 // triangle/tetrahedron source cell is detected an INTERP_KERNEL::Exception should be thrown."
42 // Check types of source elements here rather than in intersectCells() since a wrong type can be
43 // found late after a long time of calculation.
45 const unsigned long numTrgElems = meshT.getNumberOfElements();
46 for(unsigned long i = 0 ; i < numTrgElems ; ++i)
47 if ( meshT.getTypeOfElement( OTT<ConnType,numPol>::indFC( i )) != NORM_TRI3 )
48 throw INTERP_KERNEL::Exception("P0P1 barycentric algorithm works only with triangular target meshes");
51 template<class MyMeshType, class MyMatrix, class ConcreteP0P1Intersector>
52 int PlanarIntersectorP0P1Bary<MyMeshType,MyMatrix,ConcreteP0P1Intersector>::getNumberOfRowsOfResMatrix() const
54 return PlanarIntersector<MyMeshType,MyMatrix>::_meshT.getNumberOfNodes();
57 template<class MyMeshType, class MyMatrix, class ConcreteP0P1Intersector>
58 int PlanarIntersectorP0P1Bary<MyMeshType,MyMatrix,ConcreteP0P1Intersector>::getNumberOfColsOfResMatrix() const
60 return PlanarIntersector<MyMeshType,MyMatrix>::_meshS.getNumberOfElements();
64 * This method computes a value per each node of each source triangle for target.
66 template<class MyMeshType, class MyMatrix, class ConcreteP0P1Intersector>
67 void PlanarIntersectorP0P1Bary<MyMeshType,MyMatrix,ConcreteP0P1Intersector>::intersectCells(ConnType icellT, const std::vector<ConnType>& icellsS, MyMatrix& res)
70 std::vector<double> trgTriaCoords,trgTriaCoordsTmp;
72 PlanarIntersector<MyMeshType,MyMatrix>::getRealTargetCoordinates(OTT<ConnType,numPol>::indFC(icellT),trgTriaCoords);
73 std::vector<double> *tgtCoords(&trgTriaCoords);
74 const ConnType *startOfCellNodeConn=PlanarIntersector<MyMeshType,MyMatrix>::_connectT+OTT<ConnType,numPol>::conn2C(PlanarIntersector<MyMeshType,MyMatrix>::_connIndexT[icellT]);
75 // treat each source cells
76 for(typename std::vector<ConnType>::const_iterator iter=icellsS.begin();iter!=icellsS.end();iter++)
78 std::vector<double> srcCellCoords,srcCellCoordsTmp,nodeCeffs;
80 NormalizedCellType tS=PlanarIntersector<MyMeshType,MyMatrix>::_meshS.getTypeOfElement(OTT<ConnType,numPol>::indFC(iS));
81 bool isSourceQuad=CellModel::GetCellModel(tS).isQuadratic();
82 PlanarIntersector<MyMeshType,MyMatrix>::getRealSourceCoordinates(OTT<ConnType,numPol>::indFC(iS),srcCellCoords);
83 std::vector<double> *srcCoords(&srcCellCoords);
84 int srcNbNodes = srcCellCoords.size()/SPACEDIM;
87 srcCellCoordsTmp=srcCellCoords;
88 trgTriaCoordsTmp=trgTriaCoords;
89 srcCoords=&srcCellCoordsTmp;
90 tgtCoords=&trgTriaCoordsTmp;
91 orientation=PlanarIntersector<MyMeshType,MyMatrix>::projectionThis(&trgTriaCoordsTmp[0],&srcCellCoordsTmp[0],
94 //double surf=orientation*intersectGeometryWithQuadrangle(quadrangle,targetCellCoordsTmp,isTargetQuad);
95 double surf=orientation*intersectGeoBary(*srcCoords,isSourceQuad,&((*tgtCoords)[0]),nodeCeffs);
96 surf=PlanarIntersector<MyMeshType,MyMatrix>::getValueRegardingOption(surf);
99 for(int nodeIdT=0;nodeIdT<3;nodeIdT++)
101 ConnType curNodeT=startOfCellNodeConn[nodeIdT];
102 typename MyMatrix::value_type& resRow=res[curNodeT];
103 typename MyMatrix::value_type::const_iterator iterRes=resRow.find(*iter);
104 if(iterRes!=resRow.end())
106 nodeCeffs[*iter] += iterRes->second;
109 resRow.insert(std::make_pair(*iter,nodeCeffs[nodeIdT]));