Salome HOME
Update copyrights
[tools/medcoupling.git] / src / INTERP_KERNEL / IntegralUniformIntersector.txx
1 // Copyright (C) 2007-2019  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 __INTEGRALUNIFORMINTERSECTOR_TXX__
21 #define __INTEGRALUNIFORMINTERSECTOR_TXX__
22
23 #include "IntegralUniformIntersector.hxx"
24 #include "VolSurfUser.txx"
25
26 namespace INTERP_KERNEL
27 {
28   template<class MyMeshType, class MyMatrix>
29   IntegralUniformIntersector<MyMeshType,MyMatrix>::IntegralUniformIntersector(const MyMeshType& mesh, bool isAbs):_mesh(mesh),_from_to(false),_is_abs(isAbs)
30   {
31   }
32
33   template<class MyMeshType, class MyMatrix>
34   void IntegralUniformIntersector<MyMeshType,MyMatrix>::putValueIn(ConnType iInCMode, double val1, MyMatrix& res) const
35   {
36     static const NumberingPolicy numPol=MyMeshType::My_numPol;
37     double val=performNormalization(val1);
38     if(_from_to)
39       {
40         typename MyMatrix::value_type& resRow=res[0];
41         typename MyMatrix::value_type::const_iterator iterRes=resRow.find(OTT<ConnType,numPol>::indFC(iInCMode));
42         if(iterRes==resRow.end())
43           resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(iInCMode),val));
44         else
45           {
46             double val2=(*iterRes).second+val;
47             resRow.erase(OTT<ConnType,numPol>::indFC(iInCMode));
48             resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(iInCMode),val2));
49           }
50       }
51     else
52       {
53         typename MyMatrix::value_type& resRow=res[iInCMode];
54         typename MyMatrix::value_type::const_iterator iterRes=resRow.find(OTT<ConnType,numPol>::indFC(0));
55         if(iterRes==resRow.end())
56           resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(0),val));
57         else
58           {
59             double val2=(*iterRes).second+val;
60             resRow.erase(OTT<ConnType,numPol>::indFC(0));
61             resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(0),val2));
62           }
63       }
64   }
65
66   template<class MyMeshType, class MyMatrix>
67   IntegralUniformIntersectorP0<MyMeshType,MyMatrix>::IntegralUniformIntersectorP0(const MyMeshType& mesh, bool isAbs):IntegralUniformIntersector<MyMeshType,MyMatrix>(mesh,isAbs)
68   {
69   }
70
71   template<class MyMeshType, class MyMatrix>
72   int IntegralUniformIntersectorP0<MyMeshType,MyMatrix>::getNumberOfRowsOfResMatrix() const
73   {
74     if(IntegralUniformIntersector<MyMeshType,MyMatrix>::_from_to)
75       return 1;
76     else
77       return IntegralUniformIntersector<MyMeshType,MyMatrix>::_mesh.getNumberOfElements();
78   }
79   
80   template<class MyMeshType, class MyMatrix>
81   int IntegralUniformIntersectorP0<MyMeshType,MyMatrix>::getNumberOfColsOfResMatrix() const
82   {
83     if(IntegralUniformIntersector<MyMeshType,MyMatrix>::_from_to)
84       return IntegralUniformIntersector<MyMeshType,MyMatrix>::_mesh.getNumberOfElements();
85     else
86       return 1;
87   }
88   
89   template<class MyMeshType, class MyMatrix>
90   void IntegralUniformIntersectorP0<MyMeshType,MyMatrix>::intersectCells(ConnType targetCell, const std::vector<ConnType>& srcCells, MyMatrix& res)
91   {
92     static const NumberingPolicy numPol=MyMeshType::My_numPol;
93     res.resize(getNumberOfRowsOfResMatrix());
94     unsigned long nbelem=IntegralUniformIntersector<MyMeshType,MyMatrix>::_mesh.getNumberOfElements();
95     const ConnType *connIndx=IntegralUniformIntersector<MyMeshType,MyMatrix>::_mesh.getConnectivityIndexPtr();
96     const ConnType *conn=IntegralUniformIntersector<MyMeshType,MyMatrix>::_mesh.getConnectivityPtr();
97     const double *coords=IntegralUniformIntersector<MyMeshType,MyMatrix>::_mesh.getCoordinatesPtr();
98     for(unsigned long i=0;i<nbelem;i++)
99       {
100         INTERP_KERNEL::NormalizedCellType t=IntegralUniformIntersector<MyMeshType,MyMatrix>::_mesh.getTypeOfElement(OTT<ConnType,numPol>::indFC(i));
101         double val=computeVolSurfOfCell<ConnType,numPol,MyMeshType::MY_SPACEDIM>(t,conn+OTT<ConnType,numPol>::ind2C(connIndx[i]),connIndx[i+1]-connIndx[i],coords);
102         IntegralUniformIntersector<MyMeshType,MyMatrix>::putValueIn(i,val,res);
103       }
104   }
105
106   template<class MyMeshType, class MyMatrix>
107   IntegralUniformIntersectorP1<MyMeshType,MyMatrix>::IntegralUniformIntersectorP1(const MyMeshType& mesh, bool isAbs):IntegralUniformIntersector<MyMeshType,MyMatrix>(mesh,isAbs)
108   {
109   }
110
111   template<class MyMeshType, class MyMatrix>
112   int IntegralUniformIntersectorP1<MyMeshType,MyMatrix>::getNumberOfRowsOfResMatrix() const
113   {
114     if(IntegralUniformIntersector<MyMeshType,MyMatrix>::_from_to)
115       return 1;
116     else
117       return IntegralUniformIntersector<MyMeshType,MyMatrix>::_mesh.getNumberOfNodes();
118   }
119   
120   template<class MyMeshType, class MyMatrix>
121   int IntegralUniformIntersectorP1<MyMeshType,MyMatrix>::getNumberOfColsOfResMatrix() const
122   {
123     if(IntegralUniformIntersector<MyMeshType,MyMatrix>::_from_to)
124       return IntegralUniformIntersector<MyMeshType,MyMatrix>::_mesh.getNumberOfNodes();
125     else
126       return 1;
127   }
128   
129   template<class MyMeshType, class MyMatrix>
130   void IntegralUniformIntersectorP1<MyMeshType,MyMatrix>::intersectCells(ConnType targetCell, const std::vector<ConnType>& srcCells, MyMatrix& res)
131   {
132     static const NumberingPolicy numPol=MyMeshType::My_numPol;
133     res.resize(getNumberOfRowsOfResMatrix());
134     unsigned long nbelem=IntegralUniformIntersector<MyMeshType,MyMatrix>::_mesh.getNumberOfElements();
135     const ConnType *connIndx=IntegralUniformIntersector<MyMeshType,MyMatrix>::_mesh.getConnectivityIndexPtr();
136     const ConnType *conn=IntegralUniformIntersector<MyMeshType,MyMatrix>::_mesh.getConnectivityPtr();
137     const double *coords=IntegralUniformIntersector<MyMeshType,MyMatrix>::_mesh.getCoordinatesPtr();
138     for(unsigned long i=0;i<nbelem;i++)
139       {
140         INTERP_KERNEL::NormalizedCellType t=IntegralUniformIntersector<MyMeshType,MyMatrix>::_mesh.getTypeOfElement(OTT<ConnType,numPol>::indFC(i));
141         int lgth=connIndx[i+1]-connIndx[i];
142         const ConnType *locConn=conn+OTT<ConnType,numPol>::ind2C(connIndx[i]);
143         double val=computeVolSurfOfCell<ConnType,numPol,MyMeshType::MY_SPACEDIM>(t,locConn,lgth,coords);
144         if(t==NORM_TRI3)
145           val/=3.;
146         else if(t==NORM_TETRA4)
147           val/=4.;
148         else
149           throw INTERP_KERNEL::Exception("Invalid cell type detected : must be TRI3 or TETRA4 ! ");
150         for(int j=0;j<lgth;j++)
151           IntegralUniformIntersector<MyMeshType,MyMatrix>::putValueIn(OTT<ConnType,numPol>::coo2C(locConn[j]),val,res);
152       }
153   }
154 }
155
156 #endif