Salome HOME
[bos #38048] [EDF] (2023-T3) PARAMEDMEM Ergonomy.
[tools/medcoupling.git] / src / ParaMEDMEM / OverlapElementLocator.hxx
1 // Copyright (C) 2007-2024  CEA, EDF
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 (CEA/DEN)
20
21 #ifndef __OVERLAPELEMENTLOCATOR_HXX__
22 #define __OVERLAPELEMENTLOCATOR_HXX__
23
24 #include "InterpolationOptions.hxx"
25 #include "MEDCouplingNatureOfField.hxx"
26 #include "MEDCouplingPointSet.hxx"
27 #include "MEDCouplingMemArray.hxx"
28 #include "MCAuto.hxx"
29
30 #include <mpi.h>
31 #include <vector>
32 #include <map>
33 #include <set>
34
35 //#define DEC_DEBUG
36
37 namespace MEDCoupling
38 {
39   class ParaFIELD;
40   class ProcessorGroup;
41   class OverlapInterpolationMatrix;
42   
43   typedef std::pair<int,int>   ProcCouple;     // a couple of proc IDs, typically used to define a exchange betw 2 procs
44
45   class OverlapElementLocator : public INTERP_KERNEL::InterpolationOptions
46   {
47   public:
48     OverlapElementLocator(const ParaFIELD *sourceField, const ParaFIELD *targetField, const ProcessorGroup& group,
49                           double epsAbs, int workSharingAlgo);
50     virtual ~OverlapElementLocator();
51     const MPI_Comm *getCommunicator() const;
52     void exchangeMeshes(OverlapInterpolationMatrix& matrix);
53     std::vector< std::pair<int,int> > getToDoList() const { return _to_do_list; }
54     std::vector< int > getProcsToSendFieldData() const { return _procs_to_send_field; }  // same set as the set of procs we sent mesh data to
55     std::string getSourceMethod() const;
56     std::string getTargetMethod() const;
57     const MEDCouplingPointSet *getSourceMesh(int procId) const;
58     const DataArrayIdType *getSourceIds(int procId) const;
59     const MEDCouplingPointSet *getTargetMesh(int procId) const;
60     const DataArrayIdType *getTargetIds(int procId) const;
61     bool isInMyTodoList(int i, int j) const;
62     void debugPrintWorkSharing(std::ostream & ostr) const;
63   private:
64     void computeBoundingBoxesAndInteractionList();
65     void computeTodoList_original();
66     void computeTodoList_new(bool revertIter);
67     void fillProcToSend();
68     bool intersectsBoundingBox(int i, int j) const;
69     void sendLocalMeshTo(int procId, bool sourceOrTarget, OverlapInterpolationMatrix& matrix) const;
70     void receiveRemoteMeshFrom(int procId, bool sourceOrTarget);
71     void sendMesh(int procId, const MEDCouplingPointSet *mesh, const DataArrayIdType *idsToSend) const;
72     void receiveMesh(int procId, MEDCouplingPointSet* &mesh, DataArrayIdType *&ids) const;
73   private:
74     typedef MCAuto< MEDCouplingPointSet >  AutoMCPointSet;
75     typedef MCAuto< DataArrayIdType >      AutoDAInt;
76     typedef std::pair<int,bool>  Proc_SrcOrTgt;  ///< a key indicating a proc ID and whether the data is for source mesh/field or target mesh/field
77
78     static const int START_TAG_MESH_XCH;
79
80     const ParaFIELD *_local_source_field;
81     const ParaFIELD *_local_target_field;
82
83     int _local_space_dim;
84     MEDCouplingPointSet *_local_source_mesh;
85     MEDCouplingPointSet *_local_target_mesh;
86
87     /*! of size _group.size(). Contains for each source proc i, the ids of proc j the targets interact with.
88         This vector is common for all procs in _group. This is the full list of jobs to do the interp. */
89     std::vector< std::vector< int > > _proc_pairs;
90     //! todo lists per proc
91     std::vector< std::vector< ProcCouple > > _all_todo_lists;
92     //! list of interpolation couples to be done by this proc only. This is a simple extraction of the member above _all_todo_lists
93     std::vector< ProcCouple > _to_do_list;
94     //! list of procs the local proc will have to send mesh data to:
95     std::vector< Proc_SrcOrTgt > _procs_to_send_mesh;
96     /*! list of procs the local proc will have to send field data to for the final matrix-vector computation:
97      * This can be different from _procs_to_send_mesh (restricted to Source) because interpolation matrix bits are computed on a potentially
98      * different proc than the target one.   */
99     std::vector< int > _procs_to_send_field;
100     //! Set of distant meshes
101     std::map< Proc_SrcOrTgt,  AutoMCPointSet > _remote_meshes;
102     //! Set of cell ID mappings for the above distant meshes (because only part of the meshes are exchanged)
103     std::map< Proc_SrcOrTgt, AutoDAInt > _remote_elems;
104     //! Bounding boxes (for source and target) for **all** procs.
105     //! Format minmax : Xmin_src,Xmax_src,Ymin_src,Ymax_src,Zmin_src,Zmax_src,Xmin_trg,Xmax_trg,Ymin_trg,Ymax_trg,Zmin_trg,Zmax_trg
106     double* _domain_bounding_boxes;
107     //! bounding box absolute adjustment
108     double _epsAbs;
109
110     std::vector<int> _distant_proc_ids;
111
112     const ProcessorGroup& _group;
113     const MPI_Comm *_comm;
114   };
115
116 }
117
118 #endif