Salome HOME
289d618dded6d65c915ee59805baa6a7cd9866bb
[tools/medcoupling.git] / src / ParaMEDMEM / DisjointDEC.hxx
1 // Copyright (C) 2007-2020  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 __DISJOINTDEC_HXX__
21 #define __DISJOINTDEC_HXX__
22
23 #include "MEDCouplingFieldDouble.hxx"
24 #include "NormalizedUnstructuredMesh.hxx"
25 #include "DEC.hxx"
26
27 #include <mpi.h>
28 #include <set>
29
30 namespace ICoCo
31 {
32   class MEDField;
33 }
34
35 namespace MEDCoupling
36 {
37   class ProcessorGroup;
38   class ParaFIELD;
39
40   /*!
41    * \anchor DisjointDEC-det
42    * \class DisjointDEC
43    *
44    * \section DisjointDEC-over Overview
45    *
46    * Abstract interface class representing a link between two
47    * processor groups for exchanging mesh or field data. The two processor groups must
48    * have a void intersection (\ref MEDCoupling::OverlapDEC "OverlapDEC" is to be considered otherwise).
49    * The %DEC is initialized by attaching a field on the receiving or on the
50    * sending side.
51    *
52    * The data is sent or received through calls to the (abstract) methods recvData() and sendData().
53    *
54    * One can attach either a \c MEDCoupling::ParaFIELD, or a
55    * \c ICoCo::Field, or directly a \c MEDCoupling::MEDCouplingFieldDouble instance.
56    * See the various signatures of the method DisjointDEC::attachLocalField()
57    *
58    * The derivations of this class should be considered for practical instantiation:
59    * - \ref InterpKernelDEC-det "InterpKernelDEC"
60    * - \ref ExplicitCoincidentDEC-det "ExplicitCoincidentDEC"
61    * - \ref StructuredCoincidentDEC-det "StructuredCoincidentDEC"
62    *
63    * \section DisjointDEC-options DisjointDEC options
64    * The options supported by %DisjointDEC objects are the same that the ones supported for all
65    * DECs in general and are all inherited from the class \ref MEDCoupling::DECOptions "DECOptions"
66    *
67   */
68
69   class DisjointDEC : public DEC
70   {
71   public:
72     DisjointDEC():_local_field(0),_union_group(0),_source_group(0),_target_group(0),
73     _comm_interface(0),
74     _owns_field(false),_owns_groups(false),
75     _union_comm(MPI_COMM_NULL)
76     { }
77     DisjointDEC(ProcessorGroup& source_group, ProcessorGroup& target_group);
78     DisjointDEC(const DisjointDEC&);
79     DisjointDEC &operator=(const DisjointDEC& s);
80     DisjointDEC(const std::set<int>& src_ids, const std::set<int>& trg_ids,
81                 const MPI_Comm& world_comm=MPI_COMM_WORLD);
82     void setNature(NatureOfField nature);
83     void attachLocalField( MEDCouplingFieldDouble *field);
84     void attachLocalField(const ParaFIELD *field, bool ownPt=false);
85     void attachLocalField(const ICoCo::MEDField *field);
86     
87     virtual void prepareSourceDE() = 0;
88     virtual void prepareTargetDE() = 0;
89     virtual void recvData() = 0;
90     virtual void sendData() = 0;
91     void sendRecvData(bool way=true);
92     virtual void synchronize() = 0;
93     virtual ~DisjointDEC();
94     virtual void computeProcGroup() { }
95     void renormalizeTargetField(bool isWAbs);
96     //
97     ProcessorGroup *getSourceGrp() const { return _source_group; }
98     ProcessorGroup *getTargetGrp() const { return _target_group; }
99     bool isInSourceSide() const;
100     bool isInTargetSide() const;
101     bool isInUnion() const;
102   protected:
103     void compareFieldAndMethod() const;
104     void cleanInstance();
105     void copyInstance(const DisjointDEC& other);
106     void checkPartitionGroup() const;
107   protected:
108     const ParaFIELD* _local_field;
109     //! Processor group representing the union of target and source processors
110     ProcessorGroup* _union_group;
111     ProcessorGroup* _source_group;
112     ProcessorGroup* _target_group;
113     
114     const CommInterface* _comm_interface;
115     bool _owns_field;
116     bool _owns_groups;
117     MPI_Comm _union_comm;
118   };
119 }
120
121 #endif