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-2021 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 {
67  refCast<const processorLduInterfaceField>(fineInterface);
68 
69  doTransform_ = p.doTransform();
70  rank_ = p.rank();
71 }
72 
73 
74 Foam::processorGAMGInterfaceField::processorGAMGInterfaceField
75 (
76  const GAMGInterface& GAMGCp,
77  const bool doTransform,
78  const int rank
79 )
80 :
81  GAMGInterfaceField(GAMGCp, doTransform, rank),
82  procInterface_(refCast<const processorGAMGInterface>(GAMGCp)),
83  doTransform_(doTransform),
84  rank_(rank)
85 {}
86 
87 
88 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
89 
91 (
93  const bool,
94  const lduAddressing& lduAddr,
95  const label patchId,
96  const solveScalarField& psiInternal,
97  const scalarField&,
98  const direction,
99  const Pstream::commsTypes commsType
100 ) const
101 {
102  procInterface_.interfaceInternalField(psiInternal, scalarSendBuf_);
103 
104  if
105  (
108  )
109  {
110  // Fast path.
111  scalarReceiveBuf_.setSize(scalarSendBuf_.size());
112  outstandingRecvRequest_ = UPstream::nRequests();
114  (
116  procInterface_.neighbProcNo(),
117  scalarReceiveBuf_.data_bytes(),
118  scalarReceiveBuf_.size_bytes(),
119  procInterface_.tag(),
120  comm()
121  );
122 
123  outstandingSendRequest_ = UPstream::nRequests();
125  (
127  procInterface_.neighbProcNo(),
128  scalarSendBuf_.cdata_bytes(),
129  scalarSendBuf_.size_bytes(),
130  procInterface_.tag(),
131  comm()
132  );
133  }
134  else
135  {
136  procInterface_.compressedSend(commsType, scalarSendBuf_);
137  }
138 
139  const_cast<processorGAMGInterfaceField&>(*this).updatedMatrix() = false;
140 }
141 
142 
144 (
145  solveScalarField& result,
146  const bool add,
147  const lduAddressing& lduAddr,
148  const label patchId,
149  const solveScalarField&,
150  const scalarField& coeffs,
151  const direction cmpt,
152  const Pstream::commsTypes commsType
153 ) const
154 {
155  if (updatedMatrix())
156  {
157  return;
158  }
159 
160  const labelUList& faceCells = lduAddr.patchAddr(patchId);
161 
162  if
163  (
166  )
167  {
168  // Fast path.
169  if
170  (
171  outstandingRecvRequest_ >= 0
172  && outstandingRecvRequest_ < UPstream::nRequests()
173  )
174  {
175  UPstream::waitRequest(outstandingRecvRequest_);
176  }
177  // Recv finished so assume sending finished as well.
178  outstandingSendRequest_ = -1;
179  outstandingRecvRequest_ = -1;
180 
181  // Consume straight from scalarReceiveBuf_
182 
183  // Transform according to the transformation tensor
184  transformCoupleField(scalarReceiveBuf_, cmpt);
185 
186  // Multiply the field by coefficients and add into the result
187  addToInternalField(result, !add, faceCells, coeffs, scalarReceiveBuf_);
188  }
189  else
190  {
191  solveScalarField pnf
192  (
193  procInterface_.compressedReceive<solveScalar>
194  (
195  commsType,
196  coeffs.size()
197  )
198  );
199  transformCoupleField(pnf, cmpt);
200 
201  addToInternalField(result, !add, faceCells, coeffs, pnf);
202  }
203 
204  const_cast<processorGAMGInterfaceField&>(*this).updatedMatrix() = true;
205 }
206 
207 
208 // ************************************************************************* //
static bool floatTransfer
Should compact transfer be used in which floats replace doubles reducing the bandwidth requirement at...
Definition: UPstream.H:327
label patchId(-1)
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)
Write buffer contents to given processor.
bool updatedMatrix() const
Whether matrix has been updated.
uint8_t direction
Definition: direction.H:46
Field< solveScalar > solveScalarField
commsTypes
Types of communications.
Definition: UPstream.H:66
static label nRequests() noexcept
Number of outstanding requests.
Definition: UPstream.C:83
Type & refCast(U &obj)
A dynamic_cast (for references) that generates FatalError on failed casts, uses the virtual type() me...
Definition: typeInfo.H:151
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:80
Abstract base class for processor coupled interfaces.
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
"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.
GAMG agglomerated processor interface field.
volScalarField & p
static label read(const commsTypes commsType, const int fromProcNo, char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Read buffer contents from given processor.
Definition: UIPstreamRead.C:35
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.
Definition: UPstream.C:97
Namespace for OpenFOAM.