1 // Copyright (C) 2007-2023 CEA, EDF
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef __INTERPKERNELDEC_HXX__
21 #define __INTERPKERNELDEC_HXX__
23 #include "DisjointDEC.hxx"
24 #include "MxN_Mapping.hxx"
25 #include "InterpolationOptions.hxx"
29 class InterpolationMatrix;
32 \anchor InterpKernelDEC-det
33 \class InterpKernelDEC
35 \section InterpKernelDEC-over Overview
37 The InterpKernelDEC enables the \ref InterpKerRemapGlobal "remapping" (or interpolation) of fields between
41 methodology is based on the algorithms of %INTERP_KERNEL, that is to say, they work in a similar fashion than
42 what the \ref remapper "sequential remapper" does. The following \ref discretization "projection methods"
43 are supported: P0->P0 (the most common case), P1->P0, P0->P1.
45 The computation is possible for 3D meshes, 2D meshes, and 3D-surface
46 meshes. Dimensions must be identical for code A and code B (for instance, though it could be
47 desirable, it is not yet possible to couple 3D surfaces with 2D surfaces).
49 The name "InterpKernelDEC" comes from the fact that this class uses exactly the same algorithms
50 as the sequential remapper. Both this class and the sequential
51 \ref MEDCoupling::MEDCouplingRemapper "MEDCouplingRemapper" are built on top of the %INTERP_KERNEL
52 algorithms (notably the computation of the intersection volumes).
54 Among the important properties inherited from the parent abstract class \ref DisjointDEC-det "DisjointDEC",
55 the two \ref MPIProcessorGroup-det "processor groups" (source and target) must have a void intersection.
57 \image html NonCoincident_small.png "Transfer of a field supported by a quadrangular mesh to a triangular mesh".
59 \image latex NonCoincident_small.eps "Transfer of a field supported by a quadrangular mesh to a triangular mesh"
61 In the figure above we see the transfer of a field based on a quadrangular mesh to a new field supported by
62 a triangular mesh. In a P0-P0 interpolation, to obtain the value on a triangle, the values on the
63 quadrangles are weighted by their intersection area and summed.
65 A typical use of InterpKernelDEC encompasses two distinct phases :
66 - A setup phase during which the intersection volumes are computed and the communication structures are
67 setup. This corresponds to calling the InterpKernelDEC::synchronize() method.
68 - A running phase during which the projections are actually performed. This corresponds to the calls to
69 sendData() and recvData() which actually trigger the data exchange. The data exchange are synchronous
70 in the current version of the library so that recvData() and sendData() calls must be synchronized
71 on code A and code B processor groups.
73 The following code excerpt illustrates a typical use of the InterpKernelDEC class.
77 InterpKernelDEC dec(groupA, groupB);
78 dec.attachLocalField(field);
80 if (groupA.containsMyRank())
82 else if (groupB.containsMyRank())
86 A \ref InterpKerRemapGlobal "remapping" of the field from the source mesh to the target mesh is performed by
87 the function synchronise(), which computes the interpolation matrix.
89 Computing the field on the receiving side can be expressed in terms of a matrix-vector product :
90 \f$ \phi_t=W.\phi_s\f$, with \f$ \phi_t \f$ the field on the target side and \f$ \phi_s \f$ the field
92 When remapping a 3D surface to another 3D surface, a projection phase is necessary to match elements
93 from both sides. Care must be taken when defining this projection to obtain a
94 \ref InterpKerRemapGlobal "conservative remapping".
96 In the P0-P0 case, this matrix is a plain rectangular matrix with coefficients equal to the
97 intersection areas between triangle and quadrangles. For instance, in the above figure, the matrix
101 \begin{tabular}{|cccc|}
102 0.72 & 0 & 0.2 & 0 \\
103 0.46 & 0 & 0.51 & 0.03\\
104 0.42 & 0.53 & 0 & 0.05\\
105 0 & 0 & 0.92 & 0.05 \\
109 \section InterpKernelDEC-options Options
110 On top of the usual \ref MEDCoupling::DECOptions "DEC options", the options supported by %InterpKernelDEC objects are
111 related to the underlying \ref InterpKerIntersectors "intersector class".
112 All the options available in the intersector objects are
113 available for the %InterpKernelDEC object. The various options available for intersectors can
114 be reviewed in \ref InterpKerIntersectors.
118 InterpKernelDEC dec(source_group, target_group);
119 dec.attachLocalField(field);
120 dec.setDoRotate(false);
121 dec.setPrecision(1e-12);
125 \warning{ Options must be set before calling the synchronize method. }
128 class InterpKernelDEC : public DisjointDEC, public INTERP_KERNEL::InterpolationOptions
132 InterpKernelDEC(ProcessorGroup& source_group, ProcessorGroup& target_group);
133 InterpKernelDEC(const std::set<int>& src_ids, const std::set<int>& trg_ids, const MPI_Comm& world_comm=MPI_COMM_WORLD);
134 virtual ~InterpKernelDEC();
138 void synchronizeWithDefaultValue(double val);
139 MCAuto<DataArrayIdType> retrieveNonFetchedIds() const;
141 void recvData(double time);
143 void sendData(double time , double deltatime);
144 void prepareSourceDE() { }
145 void prepareTargetDE() { }
147 MCAuto<DataArrayIdType> retrieveNonFetchedIdsSource() const;
148 MCAuto<DataArrayIdType> retrieveNonFetchedIdsTarget() const;
150 InterpolationMatrix* _interpolation_matrix;