Salome HOME
Doc: indicating how to pass MPI_Comm from mpi4py
[tools/medcoupling.git] / src / INTERP_KERNEL / InterpolationHelper.txx
1 // Copyright (C) 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 // Author : Anthony Geay (EDF R&D)
20
21 #pragma once
22
23 #include "BBTreeStandAlone.txx"
24 #include "MeshElement.txx"
25 #include "Log.hxx"
26
27 #include <memory>
28 #include <functional>
29
30 namespace INTERP_KERNEL
31 {
32   template<class MyMeshType>
33   BBTreeStandAlone<3,typename MyMeshType::MyConnType> BuildBBTreeWithAdjustment(const MyMeshType& srcMesh, std::function<void(double *,typename MyMeshType::MyConnType)> bboxAdjuster)
34   {
35     using ConnType = typename MyMeshType::MyConnType;
36     const ConnType numSrcElems = srcMesh.getNumberOfElements();
37     LOG(2, "Source mesh has " << numSrcElems << " elements");
38     // create BBTree structure
39     // - get bounding boxes
40     const ConnType nbElts = 6 * numSrcElems;
41     std::unique_ptr<double[]> bboxes( new double[nbElts] );
42     for(ConnType i = 0; i < numSrcElems ; ++i)
43       {
44         MeshElement<ConnType> srcElem(i,srcMesh);
45         // get source bboxes in right order
46         const BoundingBox *box( srcElem.getBoundingBox() );
47         box->fillInXMinXmaxYminYmaxZminZmaxFormat(bboxes.get()+6*i);
48       }
49     bboxAdjuster(bboxes.get(),nbElts);
50     return BBTreeStandAlone<3,ConnType>(std::move(bboxes),numSrcElems);
51   }
52
53   template<class MyMeshType>
54   BBTreeStandAlone<3,typename MyMeshType::MyConnType> BuildBBTree(const MyMeshType& srcMesh)
55   {
56     return BuildBBTreeWithAdjustment(srcMesh,[](double *,typename MyMeshType::MyConnType){});
57   }
58 }