Salome HOME
Doc: indicating how to pass MPI_Comm from mpi4py
[tools/medcoupling.git] / src / INTERP_KERNEL / MeshElement.txx
1 // Copyright (C) 2007-2022  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 #ifndef __MESHELEMENT_TXX__
20 #define __MESHELEMENT_TXX__
21
22 #include "MeshElement.hxx"
23
24 #include "TetraAffineTransform.hxx"
25 #include "TransformedTriangle.hxx"
26 #include "MeshUtils.hxx"
27 #include "BoundingBox.hxx"
28 #include <assert.h>
29 #include <type_traits>
30 #include <limits>
31 #include <memory>
32
33 namespace INTERP_KERNEL
34 {
35
36   /**
37    * Constructor
38    *
39    * @param index   global number of element in the mesh in C mode.
40    * @param mesh    mesh that the element belongs to
41    */
42   template<class ConnType>
43   template<class MyMeshType>
44   MeshElement<ConnType>::MeshElement(const ConnType index, const MyMeshType& mesh): _number( 0 )
45   {
46     this->assign(index,mesh);
47   }
48
49   template<class ConnType>
50   template<class MyMeshType>
51   void MeshElement<ConnType>::assign(const ConnType index, const MyMeshType& mesh)
52   {
53     auto numberCore = mesh.getNumberOfNodesOfElement(OTT<typename MyMeshType::MyConnType,MyMeshType::My_numPol>::indFC(index));
54     if(numberCore < std::numeric_limits<nbnodesincelltype>::max())
55     {
56       _number = static_cast< nbnodesincelltype >(numberCore);
57       std::unique_ptr<const double*[]> vertices( new const double*[_number] );
58       for( nbnodesincelltype i = 0 ; i < _number ; ++i)
59         vertices[i] = getCoordsOfNode(i , OTT<typename MyMeshType::MyConnType,MyMeshType::My_numPol>::indFC(index), mesh);
60       // create bounding box
61       _box.initializeWith(vertices.get(),_number);
62     }
63     else
64     {
65       THROW_IK_EXCEPTION("ERROR at index " << index << " : exceeding capacity !");
66     }
67   }
68
69   /////////////////////////////////////////////////////////////////////
70   /// ElementBBoxOrder                                    /////////////
71   /////////////////////////////////////////////////////////////////////
72
73   /**
74    * Comparison operator based on the bounding boxes of the elements
75    *
76    * @return true if the coordinate _coord of the bounding box of elem1 is 
77    *          strictly smaller than that of the bounding box of elem2
78    */
79   template<class ConnType>
80   bool ElementBBoxOrder::operator()( MeshElement<ConnType>* elem1, MeshElement<ConnType>* elem2)
81   {
82     const BoundingBox* box1 = elem1->getBoundingBox();
83     const BoundingBox* box2 = elem2->getBoundingBox();
84
85     assert(elem1 != 0);
86     assert(elem2 != 0);
87     assert(box1 != 0);
88     assert(box2 != 0);
89     
90     const double coord1 = box1->getCoordinate(_coord);
91     const double coord2 = box2->getCoordinate(_coord);
92     
93     return coord1 < coord2;
94   }
95
96 }
97
98 #endif