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,2023 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  // Insert send/receive requests (non-blocking). See e.g.
221  // cyclicAMIPolyPatchTemplates.C
222  const label oldWarnComm = UPstream::commWarn(AMI.comm());
223  map.send
224  (
225  pnf,
226  sendRequests_,
227  scalarSendBufs_,
228  recvRequests_,
229  scalarRecvBufs_
230  );
231  UPstream::commWarn(oldWarnComm);
232  }
233 }
234 
235 
237 (
238  solveScalarField& result,
239  const bool add,
240  const lduAddressing& lduAddr,
241  const label patchId,
242  const solveScalarField& psiInternal,
243  const scalarField& coeffs,
244  const direction cmpt,
245  const Pstream::commsTypes
246 ) const
247 {
248  const labelUList& faceCells = lduAddr.patchAddr(patchId);
249 
250  const auto& AMI =
251  (
252  cyclicACMIInterface_.owner()
253  ? cyclicACMIInterface_.AMI()
254  : cyclicACMIInterface_.neighbPatch().AMI()
255  );
256 
257  DebugPout<< "cyclicACMIGAMGInterfaceField::updateInterfaceMatrix() :"
258  << " interface:" << cyclicACMIInterface_.index()
259  << " size:" << cyclicACMIInterface_.size()
260  << " owner:" << cyclicACMIInterface_.owner()
261  << " AMI distributed:" << AMI.distributed()
262  << endl;
263 
264 
265  if (AMI.distributed())
266  {
267  const auto& map =
268  (
269  cyclicACMIInterface_.owner()
270  ? AMI.tgtMap()
271  : AMI.srcMap()
272  );
273 
274  // Receive (= copy) data from buffers into work. TBD: receive directly
275  // into slices of work.
276  solveScalarField work;
277  map.receive(recvRequests_, scalarRecvBufs_, work);
278 
279  solveScalarField pnf(faceCells.size(), Zero);
280  AMI.weightedSum
281  (
282  cyclicACMIInterface_.owner(),
283  work,
284  pnf, // result
286  );
287 
288  // Add result using coefficients
289  this->addToInternalField(result, !add, faceCells, coeffs, pnf);
290  }
291  else
292  {
293  // Get neighbouring field
294  const labelList& nbrFaceCells =
295  lduAddr.patchAddr(cyclicACMIInterface_.neighbPatchID());
296 
297  solveScalarField pnf(psiInternal, nbrFaceCells);
298 
299  // Transform according to the transformation tensors
300  transformCoupleField(pnf, cmpt);
301 
302  if (cyclicACMIInterface_.owner())
303  {
304  pnf = AMI.interpolateToSource(pnf);
305  }
306  else
307  {
308  pnf = AMI.interpolateToTarget(pnf);
309  }
310 
311  const labelUList& faceCells = lduAddr.patchAddr(patchId);
312 
313  this->addToInternalField(result, !add, faceCells, coeffs, pnf);
314  }
315 }
316 
317 
319 {
320  //GAMGInterfaceField::write(os);
321  os << token::SPACE << doTransform()
322  << token::SPACE << rank();
323 }
324 
325 
326 // ************************************************************************* //
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:72
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:598
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). Generates a FatalError on failed casts and uses the virtual type() m...
Definition: typeInfo.H:159
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:449
Abstract base class for cyclic AMI coupled interfaces.
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
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.
static const Field< solveScalar > & null()
Return nullObject reference Field.
Definition: FieldI.H:24
#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" : (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