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