Salome HOME
Update copyrights
[tools/medcoupling.git] / src / ParaMEDMEM / ElementLocator.hxx
1 // Copyright (C) 2007-2019  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
20 #ifndef __ELEMENTLOCATOR_HXX__
21 #define __ELEMENTLOCATOR_HXX__
22
23 #include "InterpolationOptions.hxx"
24 #include "MEDCouplingNatureOfField.hxx"
25 #include "MCType.hxx"
26
27 #include <mpi.h>
28 #include <vector>
29 #include <set>
30
31 namespace MEDCoupling
32 {
33   class ParaFIELD;
34   class ProcessorGroup;
35   class InterpolationMatrix;
36   class MEDCouplingPointSet;
37   class DataArrayInt;
38
39   /*! Internal class, not part of the public API. Used in InterpolationMatrix.
40    *
41    */
42   class ElementLocator : public INTERP_KERNEL::InterpolationOptions
43   {
44   public:
45     ElementLocator(const ParaFIELD& sourceField, const ProcessorGroup& distant_group, const ProcessorGroup& local_group);
46
47     virtual ~ElementLocator();
48     void exchangeMesh(int idistantrank,
49                       MEDCouplingPointSet*& target_mesh,
50                       int*& distant_ids);
51     void exchangeMethod(const std::string& sourceMeth, int idistantrank, std::string& targetMeth);
52     const std::vector<int>& getDistantProcIds() const { return _distant_proc_ids; }
53     const MPI_Comm *getCommunicator() const;
54     NatureOfField getLocalNature() const;
55     //! This method is used to informed if there is -1D mesh on distant_group side or on local_group side.
56     bool isM1DCorr() const { return _is_m1d_corr; }
57     //Working side methods
58     void recvPolicyFromLazySideW(std::vector<int>& policy);
59     void sendSumToLazySideW(const std::vector< std::vector<int> >& distantLocEltIds, const std::vector< std::vector<double> >& partialSumRelToDistantIds);
60     void recvSumFromLazySideW(std::vector< std::vector<double> >& globalSumRelToDistantIds);
61     void sendCandidatesForAddElementsW(const std::vector<int>& distantGlobIds);
62     void recvAddElementsFromLazyProcsW(std::vector<std::vector<int> >& elementsToAdd);
63     //
64     void sendLocalIdsToLazyProcsW(const std::vector< std::vector<int> >& distantLocEltIds);
65     void recvGlobalIdsFromLazyProcsW(const std::vector< std::vector<int> >& distantLocEltIds, std::vector< std::vector<int> >& globalIds);
66     void recvCandidatesGlobalIdsFromLazyProcsW(std::vector< std::vector<int> >& globalIds);
67     void sendPartialSumToLazyProcsW(const std::vector<int>& distantGlobIds, const std::vector<double>& sum);
68     //Lazy side methods
69     int sendPolicyToWorkingSideL();
70     void recvFromWorkingSideL();
71     void sendToWorkingSideL();
72     //
73     void recvLocalIdsFromWorkingSideL();
74     void sendGlobalIdsToWorkingSideL();
75     void sendCandidatesGlobalIdsToWorkingSideL();
76     //
77     void recvSumFromWorkingSideL();
78     void recvCandidatesForAddElementsL();
79     void sendAddElementsToWorkingSideL();
80   private:
81     void _computeBoundingBoxes();
82     bool _intersectsBoundingBox(int irank);
83     void _exchangeMesh(MEDCouplingPointSet* local_mesh, MEDCouplingPointSet*& distant_mesh,
84                        int iproc_distant, const DataArrayInt* distant_ids_send,
85                        int*& distant_ids_recv);
86   private:
87     const ParaFIELD&  _local_para_field ;
88     MEDCouplingPointSet* _local_cell_mesh;
89     int _local_cell_mesh_space_dim;
90     bool _is_m1d_corr;
91     MEDCouplingPointSet* _local_face_mesh;
92     std::vector<MEDCouplingPointSet*> _distant_cell_meshes;
93     std::vector<MEDCouplingPointSet*> _distant_face_meshes;
94     double* _domain_bounding_boxes;
95     const ProcessorGroup& _distant_group;
96     const ProcessorGroup& _local_group;
97     ProcessorGroup* _union_group;
98     std::vector<int> _distant_proc_ids;
99     const MPI_Comm *_comm;
100     //Attributes only used by lazy side
101     std::vector<double> _values_added;
102     std::vector< std::vector<int> > _ids_per_working_proc;
103     std::vector< std::vector<int> > _ids_per_working_proc3;
104     std::vector< std::vector<double> > _values_per_working_proc;
105   public:
106     static const int CUMULATIVE_POLICY=3;
107     static const int NO_POST_TREATMENT_POLICY=7;
108   };
109
110 }
111
112 #endif