Salome HOME
Update copyrights 2014.
[modules/med.git] / src / INTERP_KERNEL / IntersectorCU.txx
1 // Copyright (C) 2009-2014  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         _coordsC [ j ] = _meshC.getCoordsAlongAxis( _TMIC( j ));
64         _nbCellsC[ j ] = _meshC.nbCellsAlongAxis  ( _TMIC( j ));
65       }
66   }
67
68   //================================================================================
69   /*!
70    * \brief Destructor
71    */
72   //================================================================================
73
74   _CU_TEMPLATE
75   _INTERSECTOR_CU_::~IntersectorCU()
76   {
77   }
78
79   //================================================================================
80   /*!
81    * \brief Return bounding box of an unstructured element
82    */
83   //================================================================================
84
85   _CU_TEMPLATE
86   void _INTERSECTOR_CU_::getUElemBB(double* bb, UConnType icell)
87   {
88     //initializing bounding box limits
89     for(int idim=0; idim<SPACEDIM; idim++)
90       {
91         bb[2*idim  ] =  std::numeric_limits<double>::max();
92         bb[2*idim+1] = -std::numeric_limits<double>::max();
93       }
94
95     UConnType nb_nodes = _connIndexU[icell+1] - _connIndexU[icell];
96     for (UConnType i=0; i<nb_nodes; i++)
97       {
98         //const double* coord_node=_coordsU+SPACEDIM*(OTT<ConnType,numPol>::coo2C(conn[OTT<ConnType,numPol>::conn2C(conn_index[OTT<ConnType,numPol>::ind2C(iP)]+i)]));
99         const double* coord_node=_coordsU+SPACEDIM*(_FMCOO( _connectU[_FMCON (_connIndexU[_FMIU(icell)]+i)]));
100         for(int idim=0; idim<SPACEDIM; idim++)
101           {            
102             double x = *(coord_node+idim);
103             bb[2*idim  ] = (x<bb[2*idim  ])?x:bb[2*idim  ];
104             bb[2*idim+1] = (x>bb[2*idim+1])?x:bb[2*idim+1];
105           }
106       }
107   }
108
109   //================================================================================
110   /*!
111    * \brief Return coordinates of nodes of an unstructured element
112    */
113   //================================================================================
114
115   _CU_TEMPLATE
116   void _INTERSECTOR_CU_::getUCoordinates(UConnType icell, std::vector<double>& coords)
117   {
118     UConnType nb_nodes = _connIndexU[icell+1] - _connIndexU[icell];
119     coords.resize( SPACEDIM * nb_nodes );
120     for (UConnType i=0; i<nb_nodes; i++)
121       for(int j=0; j<SPACEDIM; j++)
122         coords[SPACEDIM*i+j]=_coordsU[SPACEDIM*_FMCOO( _connectU[_FMCON (_connIndexU[_FMIU(icell)]+i)])+j];
123   }
124
125   _CU_TEMPLATE
126   int _INTERSECTOR_CU_::getNumberOfRowsOfResMatrix() const
127   {
128     return _meshU.getNumberOfElements();
129   }
130   _CU_TEMPLATE
131   int _INTERSECTOR_CU_::getNumberOfColsOfResMatrix() const
132   {
133     return _meshC.getNumberOfElements();
134   }
135
136   //================================================================================
137   /*!
138    * \brief Intersects unstructured target cell with structured source cell given by
139    *        its indices
140    *  \param icellU - index of an unstructured element
141    *  \param icellC - i,j,k of a structured element
142    *  \param res - matrix to fill in
143    */
144   //================================================================================
145
146   _CU_TEMPLATE
147   void _INTERSECTOR_CU_::intersectCells(CConnType                     icellU,
148                                         const std::vector<CConnType>& icellC,
149                                         MyMatrix&                     res)
150   {
151     double v = intersectGeometry(icellU, icellC);
152
153     CConnType iC = icellC[0], area = _nbCellsC[0];
154     for ( int j = 1; j < SPACEDIM; ++j )
155       {
156         iC += icellC[j] * area;
157         area *= _nbCellsC[j];
158       }
159     res[ icellU ][ iC ] = v;
160   }
161 }
162
163 #endif