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