processorGAMGInterfaceField.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) 2011-2017 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(processorGAMGInterfaceField, 0);
39  (
40  GAMGInterfaceField,
41  processorGAMGInterfaceField,
42  lduInterface
43  );
45  (
46  GAMGInterfaceField,
47  processorGAMGInterfaceField,
48  lduInterfaceField
49  );
51  (
52  GAMGInterfaceField,
53  processorGAMGInterfaceField,
54  Istream
55  );
56 }
57 
58 
59 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
60 
61 Foam::processorGAMGInterfaceField::processorGAMGInterfaceField
62 (
63  const GAMGInterface& GAMGCp,
64  const lduInterfaceField& fineInterface
65 )
66 :
67  GAMGInterfaceField(GAMGCp, fineInterface),
68  procInterface_(refCast<const processorGAMGInterface>(GAMGCp)),
69  doTransform_(false),
70  rank_(0),
71  sendRequest_(-1),
72  recvRequest_(-1)
73 {
74  const auto& p = refCast<const processorLduInterfaceField>(fineInterface);
75 
76  doTransform_ = p.doTransform();
77  rank_ = p.rank();
78 }
79 
80 
81 Foam::processorGAMGInterfaceField::processorGAMGInterfaceField
82 (
83  const GAMGInterface& GAMGCp,
84  const bool doTransform,
85  const int rank
86 )
87 :
88  GAMGInterfaceField(GAMGCp, doTransform, rank),
89  procInterface_(refCast<const processorGAMGInterface>(GAMGCp)),
90  doTransform_(doTransform),
91  rank_(rank),
92  sendRequest_(-1),
93  recvRequest_(-1)
94 {}
95 
96 
97 Foam::processorGAMGInterfaceField::processorGAMGInterfaceField
98 (
99  const GAMGInterface& GAMGCp,
100  Istream& is
101 )
102 :
103  GAMGInterfaceField(GAMGCp, is),
104  procInterface_(refCast<const processorGAMGInterface>(GAMGCp)),
105  doTransform_(readBool(is)),
106  rank_(readLabel(is))
107 {}
108 
109 
110 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
111 
113 {
114  const bool ok = UPstream::finishedRequest(recvRequest_);
115  if (ok)
116  {
117  recvRequest_ = -1;
118  if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
119  }
120  return ok;
121 }
122 
123 
125 (
127  const bool,
128  const lduAddressing& lduAddr,
129  const label patchId,
130  const solveScalarField& psiInternal,
131  const scalarField&,
132  const direction,
133  const Pstream::commsTypes commsType
134 ) const
135 {
136  procInterface_.interfaceInternalField(psiInternal, scalarSendBuf_);
137 
138  if
139  (
142  )
143  {
144  // Fast path.
145  scalarRecvBuf_.resize_nocopy(scalarSendBuf_.size());
146 
147  recvRequest_ = UPstream::nRequests();
149  (
151  procInterface_.neighbProcNo(),
152  scalarRecvBuf_.data_bytes(),
153  scalarRecvBuf_.size_bytes(),
154  procInterface_.tag(),
155  comm()
156  );
157 
158  sendRequest_ = UPstream::nRequests();
160  (
162  procInterface_.neighbProcNo(),
163  scalarSendBuf_.cdata_bytes(),
164  scalarSendBuf_.size_bytes(),
165  procInterface_.tag(),
166  comm()
167  );
168  }
169  else
170  {
171  procInterface_.compressedSend(commsType, scalarSendBuf_);
172  }
173 
174  this->updatedMatrix(false);
175 }
176 
177 
179 (
180  solveScalarField& result,
181  const bool add,
182  const lduAddressing& lduAddr,
183  const label patchId,
184  const solveScalarField&,
185  const scalarField& coeffs,
186  const direction cmpt,
187  const Pstream::commsTypes commsType
188 ) const
189 {
190  if (this->updatedMatrix())
191  {
192  return;
193  }
194 
195  const labelUList& faceCells = lduAddr.patchAddr(patchId);
196 
197  if
198  (
201  )
202  {
203  // Fast path: consume straight from receive buffer
204 
205  // Require receive data.
206  // Only update the send request state.
207  UPstream::waitRequest(recvRequest_); recvRequest_ = -1;
208  if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
209  }
210  else
211  {
212  scalarRecvBuf_.resize_nocopy(coeffs.size());
213  procInterface_.compressedReceive(commsType, scalarRecvBuf_);
214  }
215 
216 
217  // Transform according to the transformation tensor
218  transformCoupleField(scalarRecvBuf_, cmpt);
219 
220  // Multiply the field by coefficients and add into the result
221  addToInternalField(result, !add, faceCells, coeffs, scalarRecvBuf_);
222 
223  this->updatedMatrix(true);
224 }
225 
226 
228 {
229  //GAMGInterfaceField::write(os);
230  os << token::SPACE << doTransform()
231  << token::SPACE << rank();
232 }
233 
234 
235 // ************************************************************************* //
static bool floatTransfer
Should compact transfer be used in which floats replace doubles reducing the bandwidth requirement at...
Definition: UPstream.H:364
label patchId(-1)
uint8_t direction
Definition: direction.H:46
static label read(const UPstream::commsTypes commsType, const int fromProcNo, char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, UPstream::Request *req=nullptr)
Read buffer contents from given processor.
Definition: UIPstreamRead.C:35
Field< solveScalar > solveScalarField
commsTypes
Communications types.
Definition: UPstream.H:72
static label nRequests() noexcept
Number of outstanding requests (on the internal list of requests)
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
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
Definition: label.H:63
static bool finishedRequest(const label i)
Non-blocking comms: has request i finished? Corresponds to MPI_Test()
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
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Space [isspace].
Definition: token.H:131
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
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)
GAMG agglomerated processor interface.
virtual void write(Ostream &) const
Write to stream.
Abstract base class for GAMG agglomerated interfaces.
Definition: GAMGInterface.H:50
static bool write(const UPstream::commsTypes commsType, const int toProcNo, const char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, UPstream::Request *req=nullptr, const UPstream::sendModes sendMode=UPstream::sendModes::normal)
Write buffer contents to given processor.
::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.
virtual bool ready() const
Are all (receive) data available?
volScalarField & p
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.
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.
static void waitRequest(const label i)
Wait until request i has finished. Corresponds to MPI_Wait()
bool readBool(Istream &is)
Read bool from stream using Foam::Switch(Istream&)
Definition: bool.C:62
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)