Salome HOME
de1a4cd48b25a4869f7707897199ed12a757638f
[tools/medcoupling.git] / src / INTERP_KERNEL / IntersectorCU.txx
1 // Copyright (C) 2009-2019  OPEN CASCADE
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 // File      : IntersectorCU.txx
20 // Created   : Thu Dec 17 12:30:17 2009
21 // Author    : Edward AGAPOV (eap)
22 //
23 #ifndef __IntersectorCU_TXX__
24 #define __IntersectorCU_TXX__
25
26 #include "IntersectorCU.hxx"
27
28 // convert index "From Mesh Index"
29 #define _FMIU(i) OTT<typename MyUMeshType::MyConnType,MyUMeshType::My_numPol>::ind2C((i))
30 #define _FMIC(i) OTT<typename MyCMeshType::MyConnType,MyCMeshType::My_numPol>::ind2C((i))
31 // convert index "To Mesh Index"
32 #define _TMIU(i) OTT<typename MyUMeshType::MyConnType,MyUMeshType::My_numPol>::indFC((i))
33 #define _TMIC(i) OTT<typename MyCMeshType::MyConnType,MyCMeshType::My_numPol>::indFC((i))
34 // convert coord "From Mesh Coord"
35 #define _FMCOO(i) OTT<typename MyUMeshType::MyConnType,MyUMeshType::My_numPol>::coo2C((i))
36 // convert connectivity "From Mesh Connectivity"
37 #define _FMCON(i) OTT<typename MyUMeshType::MyConnType,MyUMeshType::My_numPol>::conn2C((i))
38
39
40 #define _CU_TEMPLATE \
41 template<class MyCMeshType, class MyUMeshType, class MyMatrix, class ConcreteIntersector>
42 #define _INTERSECTOR_CU_ \
43 IntersectorCU<MyCMeshType, MyUMeshType, MyMatrix, ConcreteIntersector>
44
45 namespace INTERP_KERNEL
46 {
47   //================================================================================
48   /*!
49    * \brief Constructor
50    */
51   //================================================================================
52
53   _CU_TEMPLATE
54   _INTERSECTOR_CU_::IntersectorCU(const MyCMeshType& meshS, const MyUMeshType& meshT):
55     _meshU(meshT), _meshC(meshS)
56   {
57     _connectU  =meshT.getConnectivityPtr();
58     _connIndexU=meshT.getConnectivityIndexPtr();
59     _coordsU   =meshT.getCoordinatesPtr();
60
61     for ( int j = 0; j < SPACEDIM; ++j )
62       {
63         int axis = static_cast<int>( _TMIC( j ));
64         _coordsC [ j ] = _meshC.getCoordsAlongAxis( axis );
65         _nbCellsC[ j ] = static_cast<CConnType>(_meshC.nbCellsAlongAxis( axis ));
66       }
67   }
68
69   //================================================================================
70   /*!
71    * \brief Destructor
72    */
73   //================================================================================
74
75   _CU_TEMPLATE
76   _INTERSECTOR_CU_::~IntersectorCU()
77   {
78   }
79
80   //================================================================================
81   /*!
82    * \brief Return bounding box of an unstructured element
83    */
84   //================================================================================
85
86   _CU_TEMPLATE
87   void _INTERSECTOR_CU_::getUElemBB(double* bb, UConnType icell)
88   {
89     //initializing bounding box limits
90     for(int idim=0; idim<SPACEDIM; idim++)
91       {
92         bb[2*idim  ] =  std::numeric_limits<double>::max();
93         bb[2*idim+1] = -std::numeric_limits<double>::max();
94       }
95
96     UConnType nb_nodes = _connIndexU[icell+1] - _connIndexU[icell];
97     for (UConnType i=0; i<nb_nodes; i++)
98       {
99         //const double* coord_node=_coordsU+SPACEDIM*(OTT<ConnType,numPol>::coo2C(conn[OTT<ConnType,numPol>::conn2C(conn_index[OTT<ConnType,numPol>::ind2C(iP)]+i)]));
100         const double* coord_node=_coordsU+SPACEDIM*(_FMCOO( _connectU[_FMCON (_connIndexU[_FMIU(icell)]+i)]));
101         for(int idim=0; idim<SPACEDIM; idim++)
102           {            
103             double x = *(coord_node+idim);
104             bb[2*idim  ] = (x<bb[2*idim  ])?x:bb[2*idim  ];
105             bb[2*idim+1] = (x>bb[2*idim+1])?x:bb[2*idim+1];
106           }
107       }
108   }
109
110   //================================================================================
111   /*!
112    * \brief Return coordinates of nodes of an unstructured element
113    */
114   //================================================================================
115
116   _CU_TEMPLATE
117   void _INTERSECTOR_CU_::getUCoordinates(UConnType icell, std::vector<double>& coords)
118   {
119     UConnType nb_nodes = _connIndexU[icell+1] - _connIndexU[icell];
120     coords.resize( SPACEDIM * nb_nodes );
121     for (UConnType i=0; i<nb_nodes; i++)
122       for(int j=0; j<SPACEDIM; j++)
123         coords[SPACEDIM*i+j]=_coordsU[SPACEDIM*_FMCOO( _connectU[_FMCON (_connIndexU[_FMIU(icell)]+i)])+j];
124   }
125
126   _CU_TEMPLATE
127   typename MyCMeshType::MyConnType _INTERSECTOR_CU_::getNumberOfRowsOfResMatrix() const
128   {
129     return _meshU.getNumberOfElements();
130   }
131   _CU_TEMPLATE
132   typename MyCMeshType::MyConnType _INTERSECTOR_CU_::getNumberOfColsOfResMatrix() const
133   {
134     return static_cast<CConnType>(_meshC.getNumberOfElements());
135   }
136
137   //================================================================================
138   /*!
139    * \brief Intersects unstructured target cell with structured source cell given by
140    *        its indices
141    *  \param icellU - index of an unstructured element
142    *  \param icellC - i,j,k of a structured element
143    *  \param res - matrix to fill in
144    */
145   //================================================================================
146
147   _CU_TEMPLATE
148   void _INTERSECTOR_CU_::intersectCells(CConnType                     icellU,
149                                         const std::vector<CConnType>& icellC,
150                                         MyMatrix&                     res)
151   {
152     double v = intersectGeometry(icellU, icellC);
153
154     CConnType iC = icellC[0], area = _nbCellsC[0];
155     for ( int j = 1; j < SPACEDIM; ++j )
156       {
157         iC += icellC[j] * area;
158         area *= _nbCellsC[j];
159       }
160     res[ icellU ][ iC ] = v;
161   }
162 }
163
164 #endif