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  );
50 }
51 
52 
53 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54 
55 Foam::processorGAMGInterfaceField::processorGAMGInterfaceField
56 (
57  const GAMGInterface& GAMGCp,
58  const lduInterfaceField& fineInterface
59 )
60 :
61  GAMGInterfaceField(GAMGCp, fineInterface),
62  procInterface_(refCast<const processorGAMGInterface>(GAMGCp)),
63  doTransform_(false),
64  rank_(0),
65  sendRequest_(-1),
66  recvRequest_(-1)
67 {
68  const auto& p = refCast<const processorLduInterfaceField>(fineInterface);
69 
70  doTransform_ = p.doTransform();
71  rank_ = p.rank();
72 }
73 
74 
75 Foam::processorGAMGInterfaceField::processorGAMGInterfaceField
76 (
77  const GAMGInterface& GAMGCp,
78  const bool doTransform,
79  const int rank
80 )
81 :
82  GAMGInterfaceField(GAMGCp, doTransform, rank),
83  procInterface_(refCast<const processorGAMGInterface>(GAMGCp)),
84  doTransform_(doTransform),
85  rank_(rank),
86  sendRequest_(-1),
87  recvRequest_(-1)
88 {}
89 
90 
91 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
92 
94 (
96  const bool,
97  const lduAddressing& lduAddr,
98  const label patchId,
99  const solveScalarField& psiInternal,
100  const scalarField&,
101  const direction,
102  const Pstream::commsTypes commsType
103 ) const
104 {
105  procInterface_.interfaceInternalField(psiInternal, scalarSendBuf_);
106 
107  if
108  (
111  )
112  {
113  // Fast path.
114  scalarRecvBuf_.resize_nocopy(scalarSendBuf_.size());
115 
116  recvRequest_ = UPstream::nRequests();
118  (
120  procInterface_.neighbProcNo(),
121  scalarRecvBuf_.data_bytes(),
122  scalarRecvBuf_.size_bytes(),
123  procInterface_.tag(),
124  comm()
125  );
126 
127  sendRequest_ = UPstream::nRequests();
129  (
131  procInterface_.neighbProcNo(),
132  scalarSendBuf_.cdata_bytes(),
133  scalarSendBuf_.size_bytes(),
134  procInterface_.tag(),
135  comm()
136  );
137  }
138  else
139  {
140  procInterface_.compressedSend(commsType, scalarSendBuf_);
141  }
142 
143  this->updatedMatrix(false);
144 }
145 
146 
148 (
149  solveScalarField& result,
150  const bool add,
151  const lduAddressing& lduAddr,
152  const label patchId,
153  const solveScalarField&,
154  const scalarField& coeffs,
155  const direction cmpt,
156  const Pstream::commsTypes commsType
157 ) const
158 {
159  if (this->updatedMatrix())
160  {
161  return;
162  }
163 
164  const labelUList& faceCells = lduAddr.patchAddr(patchId);
165 
166  if
167  (
170  )
171  {
172  // Fast path: consume straight from receive buffer
173 
174  // Require receive data.
175  // Only update the send request state.
176  UPstream::waitRequest(recvRequest_); recvRequest_ = -1;
177  if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
178  }
179  else
180  {
181  scalarRecvBuf_.resize_nocopy(coeffs.size());
182  procInterface_.compressedReceive(commsType, scalarRecvBuf_);
183  }
184 
185 
186  // Transform according to the transformation tensor
187  transformCoupleField(scalarRecvBuf_, cmpt);
188 
189  // Multiply the field by coefficients and add into the result
190  addToInternalField(result, !add, faceCells, coeffs, scalarRecvBuf_);
191 
192  this->updatedMatrix(true);
193 }
194 
195 
196 // ************************************************************************* //
static bool floatTransfer
Should compact transfer be used in which floats replace doubles reducing the bandwidth requirement at...
Definition: UPstream.H:366
label patchId(-1)
uint8_t direction
Definition: direction.H:48
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:74
static label nRequests() noexcept
Number of outstanding requests (on the internal list of requests)
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
static bool finishedRequest(const label i)
Non-blocking comms: has request i finished? Corresponds to MPI_Test()
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.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
defineTypeNameAndDebug(combustionModel, 0)
GAMG agglomerated processor interface.
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
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.
"nonBlocking" : (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 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()
Namespace for OpenFOAM.