Salome HOME
9e8b00c9f81adaf48e11cae721d2a10d2530b029
[tools/medcoupling.git] / src / ParaMEDMEM / StructuredCoincidentDEC.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 __STRUCTUREDCOINCIDENTDEC_HXX__
21 #define __STRUCTUREDCOINCIDENTDEC_HXX__
22
23 #include "DisjointDEC.hxx"
24 #include "BlockTopology.hxx"
25
26
27 namespace MEDCoupling
28 {
29   class DEC;
30   class BlockTopology;
31
32   /*!
33     \anchor StructuredCoincidentDEC-det
34     \class StructuredCoincidentDEC
35
36     This class aims at \ref interpolation "remapping fields" that have identical
37     structured supports (=the same underlying mesh) but different parallel topologies
38     (=different sub-domains in the structured mesh). It can be used to couple
39     together multi-physics codes that operate on the same domain
40     with different partitioning. This can be useful for example if one of
41     the computation is much faster than the other. It can also be used
42     to couple together codes that share an interface that was generated
43     in the same manner (with identical global ids).
44     Also, this \ref para-dec "DEC" can be used for fields that have component topologies,
45     i.e., components that are scattered over several processors.
46
47     The remapping between the two supports is based on identity of global
48     ids, instead of geometrical considerations (as it is the case for
49     \ref InterpKernelDEC-det "InterpKernelDEC").
50     Therefore, beware that this \ref para-dec "DEC" can not be used
51     for coincident meshes if they do *not* have the exact same numbering.
52
53     With this %DEC no projection, and no interpolation of the field data is done, contrary
54     to what happens in \ref InterpKernelDEC-det "InterpKernelDEC". It is just
55     a matter of allocating the values from one side to the other, using directly the cell
56     identifiers.
57
58     As all the other DECs, its usage requires two phases :
59     - a setup phase during which the topologies are exchanged so that
60     the target side knows from which processors it should expect
61     the data.
62     - a send/recv phase during which the field data is actually transferred.
63
64     This example illustrates the sending of a field with
65     the \c StructuredCoincidentDEC :
66     \code
67     ...
68     StructuredCoincidentDEC dec(groupA, groupB);
69     dec.attachLocalField(field);
70     dec.synchronize();
71     if (groupA.containsMyRank())
72     dec.recvData();
73     else if (groupB.containsMyRank())
74     dec.sendData();
75     ...
76     \endcode
77
78     Creating a ParaFIELD to be attached to the %DEC is done in exactly the same way as for
79     the other DECs, if only the partitioning of the support mesh differs.
80     In the case where the
81     fields have also different *component* topologies, creating the ParaFIELD
82     requires some more effort. See the \ref para-over "parallelism" section for more details.
83   */
84   class StructuredCoincidentDEC : public DisjointDEC
85   {
86   public:
87     StructuredCoincidentDEC();
88     StructuredCoincidentDEC( ProcessorGroup& source, ProcessorGroup& target);
89     virtual ~StructuredCoincidentDEC();
90     void release();
91
92     void synchronize();
93     void recvData();
94     void sendData();
95     void prepareSourceDE();
96     void prepareTargetDE();
97
98   private :
99     void synchronizeTopology();
100     void broadcastTopology(BlockTopology*&, int tag);
101
102     BlockTopology* _topo_source;
103     BlockTopology* _topo_target;
104
105     bool _owns_topo_source;
106     bool _owns_topo_target;
107
108     int* _send_counts;
109     int* _recv_counts;
110     int* _send_displs;
111     int* _recv_displs;
112     double* _recv_buffer;
113     double* _send_buffer;
114   };
115 }
116
117 #endif