calculatedProcessorGAMGInterfaceField.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) 2019-2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
30 #include "lduMatrix.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(calculatedProcessorGAMGInterfaceField, 0);
38  (
39  GAMGInterfaceField,
40  calculatedProcessorGAMGInterfaceField,
41  lduInterface
42  );
44  (
45  GAMGInterfaceField,
46  calculatedProcessorGAMGInterfaceField,
47  lduInterfaceField
48  );
50  (
51  GAMGInterfaceField,
52  calculatedProcessorGAMGInterfaceField,
53  Istream
54  );
55 }
56 
57 
58 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
59 
60 Foam::calculatedProcessorGAMGInterfaceField::
61 calculatedProcessorGAMGInterfaceField
62 (
63  const GAMGInterface& GAMGCp,
64  const lduInterfaceField& fineInterface
65 )
66 :
67  GAMGInterfaceField(GAMGCp, fineInterface),
68  procInterface_(refCast<const calculatedProcessorGAMGInterface>(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::calculatedProcessorGAMGInterfaceField::
82 calculatedProcessorGAMGInterfaceField
83 (
84  const GAMGInterface& GAMGCp,
85  const bool doTransform,
86  const int rank
87 )
88 :
89  GAMGInterfaceField(GAMGCp, doTransform, rank),
90  procInterface_(refCast<const calculatedProcessorGAMGInterface>(GAMGCp)),
91  doTransform_(doTransform),
92  rank_(rank),
93  sendRequest_(-1),
94  recvRequest_(-1)
95 {}
96 
97 
98 Foam::calculatedProcessorGAMGInterfaceField::
99 calculatedProcessorGAMGInterfaceField
100 (
101  const GAMGInterface& GAMGCp,
102  Istream& is
103 )
104 :
105  GAMGInterfaceField(GAMGCp, is),
106  procInterface_(refCast<const calculatedProcessorGAMGInterface>(GAMGCp)),
107  doTransform_(readBool(is)),
108  rank_(readLabel(is))
109 {}
110 
111 
112 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
113 
115 (
117  const bool add,
118  const lduAddressing& lduAddr,
119  const label patchId,
120  const solveScalarField& psiInternal,
121  const scalarField&,
122  const direction,
123  const Pstream::commsTypes commsType
124 ) const
125 {
126  procInterface_.interfaceInternalField(psiInternal, scalarSendBuf_);
127 
128  if
129  (
132  )
133  {
134  // Fast path.
135  scalarRecvBuf_.resize_nocopy(scalarSendBuf_.size());
136 
137  recvRequest_ = UPstream::nRequests();
139  (
141  procInterface_.neighbProcNo(),
142  scalarRecvBuf_,
143  procInterface_.tag(),
144  comm()
145  );
146 
147  sendRequest_ = UPstream::nRequests();
149  (
151  procInterface_.neighbProcNo(),
152  scalarSendBuf_,
153  procInterface_.tag(),
154  comm()
155  );
156  }
157  else
158  {
159  procInterface_.compressedSend(commsType, scalarSendBuf_);
160  }
161 
162  this->updatedMatrix(false);
163 }
164 
165 
167 (
168  solveScalarField& result,
169  const bool add,
170  const lduAddressing& lduAddr,
171  const label patchId,
172  const solveScalarField&,
173  const scalarField& coeffs,
174  const direction cmpt,
175  const Pstream::commsTypes commsType
176 ) const
177 {
178  if (this->updatedMatrix())
179  {
180  return;
181  }
182 
183  const labelUList& faceCells = lduAddr.patchAddr(patchId);
184 
185  if
186  (
189  )
190  {
191  // Fast path: consume straight from receive buffer
192 
193  // Require receive data.
194  // Only update the send request state.
195  UPstream::waitRequest(recvRequest_); recvRequest_ = -1;
196  if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
197  }
198  else
199  {
200  scalarRecvBuf_.resize_nocopy(this->size());
201  procInterface_.compressedReceive(commsType, scalarRecvBuf_);
202  }
203 
204 
205  // Transform according to the transformation tensor
206  transformCoupleField(scalarRecvBuf_, cmpt);
207 
208  // Multiply the field by coefficients and add into the result
209  addToInternalField(result, !add, faceCells, coeffs, scalarRecvBuf_);
210 
211  this->updatedMatrix(true);
212 }
213 
214 
216 {
217  //GAMGInterfaceField::write(os);
218  os << token::SPACE << doTransform()
219  << token::SPACE << rank();
220 }
221 
222 
223 // ************************************************************************* //
static bool floatTransfer
Should compact transfer be used in which floats replace doubles reducing the bandwidth requirement at...
Definition: UPstream.H:942
label patchId(-1)
uint8_t direction
Definition: direction.H:46
Field< solveScalar > solveScalarField
commsTypes
Communications types.
Definition: UPstream.H:77
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) to Type reference.
Definition: typeInfo.H:172
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()
static std::streamsize read(const UPstream::commsTypes commsType, const int fromProcNo, Type *buffer, std::streamsize count, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm, UPstream::Request *req=nullptr)
Receive buffer contents (contiguous types) from given processor.
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:76
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Space [isspace].
Definition: token.H:131
static bool write(const UPstream::commsTypes commsType, const int toProcNo, const Type *buffer, std::streamsize count, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm, UPstream::Request *req=nullptr, const UPstream::sendModes sendMode=UPstream::sendModes::normal)
Write buffer contents (contiguous types only) to given processor.
GAMG agglomerated processor interface.
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)
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.
OBJstream os(runTime.globalPath()/outputName)
defineTypeNameAndDebug(combustionModel, 0)
Abstract base class for GAMG agglomerated interfaces.
Definition: GAMGInterface.H:50
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.
::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.
The class contains the addressing required by the lduMatrix: upper, lower and losort.
volScalarField & p
virtual void write(Ostream &) const
Write to stream.
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)