]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/INTERP_KERNEL/MappedBarycentric3DIntersectorP1P1.txx
Salome HOME
Copyright update 2020
[tools/medcoupling.git] / src / INTERP_KERNEL / MappedBarycentric3DIntersectorP1P1.txx
1 // Copyright (C) 2007-2020  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 : Adrien Bruneton (CEA/DEN)
20
21 #ifndef __MAPPEDBARYCENTRIC3DINTERSECTORP1P1_TXX__
22 #define __MAPPEDBARYCENTRIC3DINTERSECTORP1P1_TXX__
23
24 #include "MappedBarycentric3DIntersectorP1P1.hxx"
25 #include "Intersector3DP1P1.txx"
26 #include "MeshUtils.hxx"
27
28 namespace INTERP_KERNEL
29 {
30
31   /**
32    * Constructor creating object from target cell global number 
33    * 
34    * @param targetMesh  mesh containing the target elements
35    * @param srcMesh     mesh containing the source elements
36    * @param policy      splitting policy to be used
37    */
38   template<class MyMeshType, class MyMatrix>
39   MappedBarycentric3DIntersectorP1P1<MyMeshType,MyMatrix>::MappedBarycentric3DIntersectorP1P1(const MyMeshType& targetMesh, const MyMeshType& srcMesh, double precision):
40     Intersector3DP1P1<MyMeshType,MyMatrix>(targetMesh,srcMesh),_precision(precision)
41   {
42   }
43
44   template<class MyMeshType, class MyMatrix>
45   MappedBarycentric3DIntersectorP1P1<MyMeshType,MyMatrix>::~MappedBarycentric3DIntersectorP1P1()
46   {
47   }
48
49   /**
50    * @param targetCell in C mode.
51    * @param srcCells in C mode.
52    */
53   template<class MyMeshType, class MyMatrix>
54   void MappedBarycentric3DIntersectorP1P1<MyMeshType,MyMatrix>::intersectCells(ConnType targetCell, const std::vector<ConnType>& srcCells, MyMatrix& res)
55   {
56     std::vector<double> CoordsT;
57     const ConnType *startOfCellNodeConnT=Intersector3DP1P1<MyMeshType,MyMatrix>::getStartConnOfTargetCell(targetCell);
58     Intersector3DP1P1<MyMeshType,MyMatrix>::getRealTargetCoordinates(OTT<ConnType,numPol>::indFC(targetCell),CoordsT);
59     std::size_t nbOfNodesT=CoordsT.size()/SPACEDIM;
60     const double *coordsS=Intersector3DP1P1<MyMeshType,MyMatrix>::_src_mesh.getCoordinatesPtr();
61     for(std::size_t nodeIdT=0;nodeIdT<nbOfNodesT;nodeIdT++)
62       {
63         typename MyMatrix::value_type& resRow=res[OTT<ConnType,numPol>::ind2C(startOfCellNodeConnT[nodeIdT])];
64         if(!resRow.empty())
65           continue;
66         for(typename std::vector<ConnType>::const_iterator iterCellS=srcCells.begin();iterCellS!=srcCells.end();iterCellS++)
67           {
68             NormalizedCellType tS=Intersector3DP1P1<MyMeshType,MyMatrix>::_src_mesh.getTypeOfElement(OTT<ConnType,numPol>::indFC(*iterCellS));
69             if(tS!=NORM_HEXA8)
70               throw INTERP_KERNEL::Exception("Invalid source cell detected for meshdim==3. Only HEXA8 supported !");
71             const CellModel& cmTypeS=CellModel::GetCellModel(tS);
72             //
73             std::vector<ConnType> connOfCurCellS;
74             Intersector3DP1P1<MyMeshType,MyMatrix>::getConnOfSourceCell(OTT<ConnType,numPol>::indFC(*iterCellS),connOfCurCellS);
75             if( PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg3D(&CoordsT[nodeIdT*SPACEDIM],&connOfCurCellS[0],ToConnType(connOfCurCellS.size()),coordsS,cmTypeS,_precision) )
76               {
77                 double mco[3];  // mapped coordinates in the hexa8
78                 std::vector<double> localCoordsS;
79                 Intersector3DP1P1<MyMeshType,MyMatrix>::getRealSourceCoordinates(OTT<ConnType,numPol>::indFC(*iterCellS),localCoordsS);
80                 std::vector<const double*> coo(8);
81                 coo[0]=&localCoordsS[0]; coo[1]=&localCoordsS[3]; coo[2]=&localCoordsS[6]; coo[3]=&localCoordsS[9];
82                 coo[4]=&localCoordsS[12]; coo[5]=&localCoordsS[15]; coo[6]=&localCoordsS[18]; coo[7]=&localCoordsS[21];
83                 cuboid_mapped_coords(coo,&CoordsT[nodeIdT*SPACEDIM],mco);
84
85                 // Now use the form function of the HEXA8 to map the field values
86                 double resLoc[8];
87                 // See HEXA8 standard connectivity and cuboid_mapped_coords() convention:
88                 resLoc[5] = (1.-mco[0]) * (1.-mco[1]) * (1.-mco[2]);
89                 resLoc[6] =  mco[0]     * (1.-mco[1]) * (1.-mco[2]);
90                 resLoc[7] =  mco[0]     *   mco[1]    * (1.-mco[2]);
91                 resLoc[4] = (1.-mco[0]) *   mco[1]    * (1.-mco[2]);
92
93                 resLoc[1] = (1.-mco[0]) * (1.-mco[1]) * mco[2];
94                 resLoc[2] =  mco[0]     * (1.-mco[1]) * mco[2];
95                 resLoc[3] =  mco[0]     *   mco[1]    * mco[2];
96                 resLoc[0] = (1.-mco[0]) *   mco[1]    * mco[2];
97
98                 const ConnType *startOfCellNodeConnS=Intersector3DP1P1<MyMeshType,MyMatrix>::getStartConnOfSourceCell(*iterCellS);
99                 for(int nodeIdS=0;nodeIdS<8;nodeIdS++)
100                   {
101                     if(fabs(resLoc[nodeIdS])>_precision)
102                       {
103                         ConnType curNodeSInCmode=OTT<ConnType,numPol>::coo2C(startOfCellNodeConnS[nodeIdS]);
104                         resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(curNodeSInCmode),resLoc[nodeIdS]));
105                       }
106                   }
107               }
108           }
109       }
110   }
111 }
112
113 #endif