nonConformalMappedFvPatchBaseTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2023-2024 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
28 
29 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  const fvsPatchLabelField& srcPolyFacesPf,
35  const Field<Type>& srcFld,
36  const fvsPatchLabelField& tgtPolyFacesPf
37 )
38 {
39  if (!Pstream::parRun())
40  {
41  // Non-conformal mapped patches are ordered. So just return the field.
42  return srcFld;
43  }
44  else
45  {
46  // Otherwise this is a little more involved. Use the proc offsets and
47  // sizes stored in the polyFacesPf fields to send and receive in blocks.
48 
49  typedef
51  ncmpfFvsPatchLabelField;
52  const ncmpfFvsPatchLabelField& srcNcmPolyFacesPf =
53  refCast<const ncmpfFvsPatchLabelField>(srcPolyFacesPf);
54  const ncmpfFvsPatchLabelField& tgtNcmPolyFacesPf =
55  refCast<const ncmpfFvsPatchLabelField>(tgtPolyFacesPf);
56  const labelList& srcProcOffsets = srcNcmPolyFacesPf.procOffsets();
57  const labelList srcProcSizes(srcNcmPolyFacesPf.procSizes());
58  const labelList& tgtProcOffsets = tgtNcmPolyFacesPf.procOffsets();
59  const labelList tgtProcSizes(tgtNcmPolyFacesPf.procSizes());
60 
61  tmp<Field<Type>> tTgtFld
62  (
63  new Field<Type>(tgtProcOffsets.last() + tgtProcSizes.last())
64  );
65  Field<Type>& tgtFld = tTgtFld.ref();
66 
67  // Do local copy
68  {
69  SubList<Type> srcProcFld
70  (
71  srcFld,
72  srcProcSizes[Pstream::myProcNo()],
73  srcProcOffsets[Pstream::myProcNo()]
74  );
75 
76  SubList<Type> tgtProcFld
77  (
78  tgtFld,
79  tgtProcSizes[Pstream::myProcNo()],
80  tgtProcOffsets[Pstream::myProcNo()]
81  );
82 
83  tgtProcFld = srcProcFld;
84  }
85 
86  // Do remote transfers
87  {
89 
90  forAll(srcProcOffsets, proci)
91  {
92  if (proci != Pstream::myProcNo())
93  {
94  SubList<Type> srcProcFld
95  (
96  srcFld,
97  srcProcSizes[proci],
98  srcProcOffsets[proci]
99  );
100 
101  UOPstream(proci, pBufs)() << srcProcFld;
102  }
103  }
104 
105  pBufs.finishedSends();
106 
107  forAll(tgtProcOffsets, proci)
108  {
109  if (proci != Pstream::myProcNo())
110  {
111  SubList<Type> tgtProcFld
112  (
113  tgtFld,
114  tgtProcSizes[proci],
115  tgtProcOffsets[proci]
116  );
117 
118  UIPstream(proci, pBufs)() >> tgtProcFld;
119  }
120  }
121  }
122 
123  return tTgtFld;
124  }
125 }
126 
127 
128 template<class Type>
130 (
131  const fvsPatchLabelField& srcPolyFacesPf,
132  Field<Type>&& srcFld,
133  const fvsPatchLabelField& tgtPolyFacesPf
134 )
135 {
136  if (!Pstream::parRun())
137  {
138  // Non-conformal mapped patches are ordered. So just return the field.
139  return tmp<Field<Type>>(new Field<Type>(std::move(srcFld)));
140  }
141  else
142  {
143  // Defer to the above to communicate and construct the result
144  tmp<Field<Type>> tResult =
145  map(srcPolyFacesPf, srcFld, tgtPolyFacesPf);
146  return tResult;
147  }
148 }
149 
150 
151 template<class Type>
153 (
154  const fvsPatchLabelField& srcPolyFacesPf,
155  const tmp<Field<Type>>& srcFld,
156  const fvsPatchLabelField& tgtPolyFacesPf
157 )
158 {
159  if (!Pstream::parRun())
160  {
161  // Non-conformal mapped patches are ordered. So just return the field.
162  return srcFld;
163  }
164  else
165  {
166  // Defer to the above to communicate and construct the result
167  tmp<Field<Type>> tResult =
168  map(srcPolyFacesPf, srcFld(), tgtPolyFacesPf);
169  srcFld.clear();
170  return tResult;
171  }
172 }
173 
174 
175 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Pre-declare SubField and related Field type.
Definition: Field.H:83
Buffers for inter-processor communications streams (UOPstream, UIPstream).
void finishedSends(const bool block=true)
Mark all sends as having been done. This will start receives.
Input inter-processor communications stream operating on external buffer.
Definition: UIPstream.H:57
T & last()
Return the last element of the list.
Definition: UListI.H:128
Output inter-processor communications stream operating on external buffer.
Definition: UOPstream.H:58
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:399
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:429
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:83
static tmp< Field< Type > > map(const fvsPatchLabelField &srcPolyFacesPf, const Field< Type > &srcFld, const fvsPatchLabelField &tgtPolyFacesPf)
Map/interpolate from one patch to another.
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181