Salome HOME
962fd76e5cdd017d631a25699166bf6114167439
[modules/med.git] / src / INTERP_KERNEL / PolyhedronIntersectorP1P0.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 __POLYHEDRONINTERSECTORP1P0_TXX__
20 #define __POLYHEDRONINTERSECTORP1P0_TXX__
21
22 #include "PolyhedronIntersectorP1P0.hxx"
23 #include "Intersector3DP1P0.txx"
24 #include "MeshUtils.hxx"
25
26 #include "SplitterTetra.txx"
27
28 namespace INTERP_KERNEL
29 {
30
31   /**
32    * Constructor creating object from target cell global number 
33    * The constructor first calculates the necessary nodes, 
34    * (depending on the splitting policy) and then splits the hexahedron into 
35    * tetrahedra, placing these in the internal vector _tetra.
36    * 
37    * @param targetMesh  mesh containing the target elements
38    * @param srcMesh     mesh containing the source elements
39    * @param policy      splitting policy to be used
40    *
41    * WARNING : in _split attribute, sourceMesh and targetMesh are switched in order to fit intersectCells feature.
42    */
43   template<class MyMeshType, class MyMatrix>
44   PolyhedronIntersectorP1P0<MyMeshType,MyMatrix>::PolyhedronIntersectorP1P0(const MyMeshType& targetMesh, const MyMeshType& srcMesh, SplittingPolicy policy):Intersector3DP1P0<MyMeshType,MyMatrix>(targetMesh,srcMesh),_split(srcMesh,targetMesh,policy)
45   {
46   }
47
48   /**
49    * Destructor.
50    * Liberates the SplitterTetra objects and potential sub-node points that have been allocated.
51    *
52    */
53   template<class MyMeshType, class MyMatrix>
54   PolyhedronIntersectorP1P0<MyMeshType,MyMatrix>::~PolyhedronIntersectorP1P0()
55   {
56     releaseArrays();
57   }
58     
59   template<class MyMeshType, class MyMatrix>
60   void PolyhedronIntersectorP1P0<MyMeshType,MyMatrix>::releaseArrays()
61   {
62     for(typename std::vector< SplitterTetra<MyMeshType>* >::iterator iter = _tetra.begin(); iter != _tetra.end(); ++iter)
63       delete *iter;
64     _split.releaseArrays();
65     _tetra.clear();
66   }
67
68   /**
69    * Calculates the volume of intersection of an element in the source mesh and the target element
70    * represented by the object.
71    * The calculation is performed by calling the corresponding method for
72    * each SplitterTetra object created by the splitting.
73    * 
74    * @param targetCell in C mode.
75    * @param srcCells in C mode.
76    *
77    * WARNING : for all methods on _split object source and target are switched !
78    */
79   template<class MyMeshType, class MyMatrix>
80   void PolyhedronIntersectorP1P0<MyMeshType,MyMatrix>::intersectCells(ConnType targetCell, const std::vector<ConnType>& srcCells, MyMatrix& res)
81   {
82     SplitterTetra<MyMeshType>* subTetras[24];
83     typename MyMatrix::value_type& resRow=res[targetCell];
84     for(typename std::vector<ConnType>::const_iterator iterCellS=srcCells.begin();iterCellS!=srcCells.end();iterCellS++)
85       {
86         releaseArrays();
87         int nbOfNodesS=Intersector3D<MyMeshType,MyMatrix>::_src_mesh.getNumberOfNodesOfElement(OTT<ConnType,numPol>::indFC(*iterCellS));
88         _split.splitTargetCell(*iterCellS,nbOfNodesS,_tetra);
89         for(typename std::vector<SplitterTetra<MyMeshType>*>::iterator iter = _tetra.begin(); iter != _tetra.end(); ++iter)
90           {
91             (*iter)->splitIntoDualCells(subTetras);
92             for(int i=0;i<24;i++)
93               {
94                 SplitterTetra<MyMeshType> *tmp=subTetras[i];
95                 double volume = tmp->intersectSourceCell(targetCell);
96                 ConnType sourceNode=tmp->getId(0);
97                 if(volume!=0.)
98                   {
99                     typename MyMatrix::value_type::const_iterator iterRes=resRow.find(OTT<ConnType,numPol>::indFC(sourceNode));
100                     if(iterRes==resRow.end())
101                       resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(sourceNode),volume));
102                     else
103                       {
104                         double val=(*iterRes).second+volume;
105                         resRow.erase(OTT<ConnType,numPol>::indFC(sourceNode));
106                         resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(sourceNode),val));
107                       }
108                   }
109                 delete tmp;
110               }
111           }
112       }
113   }
114 }
115
116 #endif