Salome HOME
updated copyright message
[tools/medcoupling.git] / src / ParaMEDMEM / DisjointDEC.hxx
1 // Copyright (C) 2007-2023  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 MEDDoubleField;
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     virtual ~DisjointDEC();
83
84     void setNature(NatureOfField nature);
85     void attachLocalField( MEDCouplingFieldDouble *field);
86     void attachLocalField(const ParaFIELD *field, bool ownPt=false);
87     void attachLocalField(const ICoCo::MEDDoubleField *field);
88     
89     virtual void prepareSourceDE() = 0;
90     virtual void prepareTargetDE() = 0;
91     virtual void recvData() = 0;
92     virtual void sendData() = 0;
93     void sendRecvData(bool way=true);
94     virtual void synchronize() = 0;
95
96     virtual void computeProcGroup() { }
97     void renormalizeTargetField(bool isWAbs);
98     //
99     ProcessorGroup *getSourceGrp() const { return _source_group; }
100     ProcessorGroup *getTargetGrp() const { return _target_group; }
101     bool isInSourceSide() const;
102     bool isInTargetSide() const;
103     bool isInUnion() const;
104   protected:
105     void compareFieldAndMethod() const;
106     void cleanInstance();
107     void copyInstance(const DisjointDEC& other);
108     void checkPartitionGroup() const;
109   protected:
110     const ParaFIELD* _local_field;
111     //! Processor group representing the union of target and source processors
112     ProcessorGroup* _union_group;
113     ProcessorGroup* _source_group;
114     ProcessorGroup* _target_group;
115     
116     const CommInterface* _comm_interface;
117     bool _owns_field;
118     bool _owns_groups;
119     MPI_Comm _union_comm;
120   };
121 }
122
123 #endif