cyclicACMIGAMGInterfaceField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2013 OpenFOAM Foundation
9  Copyright (C) 2019-2024 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
31 #include "lduMatrix.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(cyclicACMIGAMGInterfaceField, 0);
39  (
40  GAMGInterfaceField,
41  cyclicACMIGAMGInterfaceField,
42  lduInterface
43  );
45  (
46  GAMGInterfaceField,
47  cyclicACMIGAMGInterfaceField,
48  lduInterfaceField
49  );
51  (
52  GAMGInterfaceField,
53  cyclicACMIGAMGInterfaceField,
54  Istream
55  );
56 }
57 
58 
59 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
60 
61 Foam::cyclicACMIGAMGInterfaceField::cyclicACMIGAMGInterfaceField
62 (
63  const GAMGInterface& GAMGCp,
64  const lduInterfaceField& fineInterface
65 )
66 :
67  GAMGInterfaceField(GAMGCp, fineInterface),
68  cyclicACMIInterface_(refCast<const cyclicACMIGAMGInterface>(GAMGCp)),
69  doTransform_(false),
70  rank_(0),
71  sendRequests_(),
72  recvRequests_()
73 {
75  refCast<const cyclicAMILduInterfaceField>(fineInterface);
76 
77  doTransform_ = p.doTransform();
78  rank_ = p.rank();
79 }
80 
81 
82 Foam::cyclicACMIGAMGInterfaceField::cyclicACMIGAMGInterfaceField
83 (
84  const GAMGInterface& GAMGCp,
85  const bool doTransform,
86  const int rank
87 )
88 :
89  GAMGInterfaceField(GAMGCp, doTransform, rank),
90  cyclicACMIInterface_(refCast<const cyclicACMIGAMGInterface>(GAMGCp)),
91  doTransform_(doTransform),
92  rank_(rank),
93  sendRequests_(),
94  recvRequests_()
95 {}
96 
97 
98 Foam::cyclicACMIGAMGInterfaceField::cyclicACMIGAMGInterfaceField
99 (
100  const GAMGInterface& GAMGCp,
101  Istream& is
102 )
103 :
104  GAMGInterfaceField(GAMGCp, is),
105  cyclicACMIInterface_(refCast<const cyclicACMIGAMGInterface>(GAMGCp)),
106  doTransform_(readBool(is)),
107  rank_(readLabel(is)),
108  sendRequests_(),
109  recvRequests_()
110 {}
111 
112 
113 Foam::cyclicACMIGAMGInterfaceField::cyclicACMIGAMGInterfaceField
114 (
115  const GAMGInterface& GAMGCp,
116  const lduInterfaceField& local,
117  const UPtrList<lduInterfaceField>& other
118 )
119 :
120  GAMGInterfaceField(GAMGCp, local),
121  cyclicACMIInterface_(refCast<const cyclicACMIGAMGInterface>(GAMGCp)),
122  doTransform_(false),
123  rank_(0),
124  sendRequests_(),
125  recvRequests_()
126 {
127  const auto& p = refCast<const cyclicACMILduInterfaceField>(local);
128 
129  doTransform_ = p.doTransform();
130  rank_ = p.rank();
131 }
132 
133 
134 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
135 
137 {
138  if
139  (
141  (
142  recvRequests_.start(),
143  recvRequests_.size()
144  )
145  )
146  {
147  recvRequests_.clear();
148 
149  if
150  (
152  (
153  sendRequests_.start(),
154  sendRequests_.size()
155  )
156  )
157  {
158  sendRequests_.clear();
159  }
160 
161  return true;
162  }
163 
164  return false;
165 }
166 
167 
169 (
170  solveScalarField& result,
171  const bool add,
172  const lduAddressing& lduAddr,
173  const label patchId,
174  const solveScalarField& psiInternal,
175  const scalarField& coeffs,
176  const direction cmpt,
177  const Pstream::commsTypes commsType
178 ) const
179 {
180  const auto& AMI =
181  (
182  cyclicACMIInterface_.owner()
183  ? cyclicACMIInterface_.AMI()
184  : cyclicACMIInterface_.neighbPatch().AMI()
185  );
186 
187  if (AMI.distributed())
188  {
189  DebugPout<< "cyclicACMIFvPatchField::initInterfaceMatrixUpdate() :"
190  << " interface:" << cyclicACMIInterface_.index()
191  << " size:" << cyclicACMIInterface_.size()
192  << " owner:" << cyclicACMIInterface_.owner()
193  << " AMI distributed:" << AMI.distributed()
194  << endl;
195 
196  // Start sending
197  if (commsType != UPstream::commsTypes::nonBlocking)
198  {
200  << "Can only evaluate distributed AMI with nonBlocking"
201  << exit(FatalError);
202  }
203 
204  // Get neighbouring field
205  const labelList& nbrFaceCells =
206  lduAddr.patchAddr(cyclicACMIInterface_.neighbPatchID());
207 
208  solveScalarField pnf(psiInternal, nbrFaceCells);
209 
210  // Transform according to the transformation tensors
211  transformCoupleField(pnf, cmpt);
212 
213  const auto& map =
214  (
215  cyclicACMIInterface_.owner()
216  ? AMI.tgtMap()
217  : AMI.srcMap()
218  );
219 
220  // Assert that all receives are known to have finished
221  if (!recvRequests_.empty())
222  {
224  << "Outstanding recv request(s) on patch "
225  << cyclicACMIInterface_.index()
226  << abort(FatalError);
227  }
228 
229  // Assume that sends are also OK
230  sendRequests_.clear();
231 
232  // Insert send/receive requests (non-blocking). See e.g.
233  // cyclicAMIPolyPatchTemplates.C
234  const label oldWarnComm = UPstream::commWarn(AMI.comm());
235  map.send
236  (
237  pnf,
238  sendRequests_,
239  scalarSendBufs_,
240  recvRequests_,
241  scalarRecvBufs_
242  );
243  UPstream::commWarn(oldWarnComm);
244  }
245 }
246 
247 
249 (
250  solveScalarField& result,
251  const bool add,
252  const lduAddressing& lduAddr,
253  const label patchId,
254  const solveScalarField& psiInternal,
255  const scalarField& coeffs,
256  const direction cmpt,
257  const Pstream::commsTypes
258 ) const
259 {
260  const labelUList& faceCells = lduAddr.patchAddr(patchId);
261 
262  const auto& AMI =
263  (
264  cyclicACMIInterface_.owner()
265  ? cyclicACMIInterface_.AMI()
266  : cyclicACMIInterface_.neighbPatch().AMI()
267  );
268 
269  DebugPout<< "cyclicACMIGAMGInterfaceField::updateInterfaceMatrix() :"
270  << " interface:" << cyclicACMIInterface_.index()
271  << " size:" << cyclicACMIInterface_.size()
272  << " owner:" << cyclicACMIInterface_.owner()
273  << " AMI distributed:" << AMI.distributed()
274  << endl;
275 
276 
277  if (AMI.distributed())
278  {
279  const auto& map =
280  (
281  cyclicACMIInterface_.owner()
282  ? AMI.tgtMap()
283  : AMI.srcMap()
284  );
285 
286  // Receive (= copy) data from buffers into work. TBD: receive directly
287  // into slices of work.
288  solveScalarField work;
289  map.receive(recvRequests_, scalarRecvBufs_, work);
290 
291  // Receive requests all handled by last function call
292  recvRequests_.clear();
293 
294  solveScalarField pnf(faceCells.size(), Zero);
295  AMI.weightedSum
296  (
297  cyclicACMIInterface_.owner(),
298  work,
299  pnf, // result
301  );
302 
303  // Add result using coefficients
304  this->addToInternalField(result, !add, faceCells, coeffs, pnf);
305  }
306  else
307  {
308  // Get neighbouring field
309  const labelList& nbrFaceCells =
310  lduAddr.patchAddr(cyclicACMIInterface_.neighbPatchID());
311 
312  solveScalarField pnf(psiInternal, nbrFaceCells);
313 
314  // Transform according to the transformation tensors
315  transformCoupleField(pnf, cmpt);
316 
317  if (cyclicACMIInterface_.owner())
318  {
319  pnf = AMI.interpolateToSource(pnf);
320  }
321  else
322  {
323  pnf = AMI.interpolateToTarget(pnf);
324  }
325 
326  const labelUList& faceCells = lduAddr.patchAddr(patchId);
327 
328  this->addToInternalField(result, !add, faceCells, coeffs, pnf);
329  }
330 }
331 
332 
334 {
335  //GAMGInterfaceField::write(os);
336  os << token::SPACE << doTransform()
337  << token::SPACE << rank();
338 }
339 
340 
341 // ************************************************************************* //
label patchId(-1)
GAMG agglomerated cyclic ACMI interface.
uint8_t direction
Definition: direction.H:46
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
Field< solveScalar > solveScalarField
virtual void updateInterfaceMatrix(solveScalarField &result, const bool add, const lduAddressing &lduAddr, const label patchId, const solveScalarField &psiInternal, const scalarField &coeffs, const direction cmpt, const Pstream::commsTypes commsType) const
Update result field based on interface functionality.
commsTypes
Communications types.
Definition: UPstream.H:77
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:608
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
Definition: typeInfo.H:172
static const Field< solveScalar > & null() noexcept
Return a null Field (reference to a nullObject). Behaves like an empty Field.
Definition: Field.H:137
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
Definition: label.H:63
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:52
An abstract base class for implicitly-coupled interface fields e.g. processor and cyclic patch fields...
Macros for easy insertion into run-time selection tables.
UList< label > labelUList
A UList of labels.
Definition: UList.H:78
virtual bool ready() const
Are all (receive) data available?
static label commWarn(const label communicator) noexcept
Alter communicator debugging setting. Warns for use of any communicator differing from specified...
Definition: UPstream.H:461
Abstract base class for cyclic AMI coupled interfaces.
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:130
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Space [isspace].
Definition: token.H:131
bool local
Definition: EEqn.H:20
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: HashTable.H:106
errorManip< error > abort(error &err)
Definition: errorManip.H:139
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
OBJstream os(runTime.globalPath()/outputName)
defineTypeNameAndDebug(combustionModel, 0)
Abstract base class for GAMG agglomerated interfaces.
Definition: GAMGInterface.H:50
virtual void initInterfaceMatrixUpdate(solveScalarField &result, const bool add, const lduAddressing &lduAddr, const label patchId, const solveScalarField &psiInternal, const scalarField &coeffs, const direction cmpt, const Pstream::commsTypes commsType) const
Initialise neighbour matrix update.
#define DebugPout
Report an information message using Foam::Pout.
::Foam::direction rank(const expressions::valueTypeCode) noexcept
The vector-space rank associated with given valueTypeCode.
Definition: exprTraits.C:70
"nonBlocking" (immediate) : (MPI_Isend, MPI_Irecv)
Abstract base class for GAMG agglomerated interface fields.
List< label > labelList
A List of labels.
Definition: List.H:62
volScalarField & p
virtual void write(Ostream &) const
Write to stream.
bool readBool(Istream &is)
Read bool from stream using Foam::Switch(Istream&)
Definition: bool.C:62
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
static bool finishedRequests(const label pos, label len=-1)
Non-blocking comms: have all requests (from position onwards) finished? Corresponds to MPI_Testall() ...
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127