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