Loading...
Searching...
No Matches
lduCalculatedProcessorField.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) 2022-2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
29
30// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31
32template<class Type>
34(
36)
37:
38 LduInterfaceField<Type>(interface),
49)
50:
51 LduInterfaceField<Type>(refCast<const lduInterface>(ptf)),
52 procInterface_(ptf.procInterface_),
53 sendRequest_(-1),
55{}
56
57
58// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
59
60template<class Type>
62{
64}
65
66
67template<class Type>
69{
70 const bool ok = UPstream::finishedRequest(recvRequest_);
71 if (ok)
72 {
73 recvRequest_ = -1;
75 }
76 return ok;
77}
78
79
80template<class Type>
82(
83 solveScalarField& result,
84 const bool add,
85 const lduAddressing& lduAddr,
86 const label patchId,
87 const solveScalarField& psiInternal,
88 const scalarField& coeffs,
89 const direction cmpt,
90 const Pstream::commsTypes commsType
91) const
92{
93 if (!this->all_ready())
94 {
96 << "Outstanding request(s) on interface "
97 //<< procInterface_.name()
98 << abort(FatalError);
99 }
100
101 // Bypass patchInternalField since uses fvPatch addressing
102 const labelUList& fc = lduAddr.patchAddr(patchId);
103
104 {
105 scalarSendBuf_.resize_nocopy(fc.size());
106 scalarRecvBuf_.resize_nocopy(fc.size());
107
108 forAll(fc, i)
109 {
110 scalarSendBuf_[i] = psiInternal[fc[i]];
111 }
112 }
113
114 recvRequest_ = UPstream::nRequests();
115 UIPstream::read
116 (
117 UPstream::commsTypes::nonBlocking,
118 procInterface_.neighbProcNo(),
119 scalarRecvBuf_,
120 procInterface_.tag(),
121 procInterface_.comm()
122 );
123
124 sendRequest_ = UPstream::nRequests();
125 UOPstream::write
126 (
127 UPstream::commsTypes::nonBlocking,
128 procInterface_.neighbProcNo(),
129 scalarSendBuf_,
130 procInterface_.tag(),
131 procInterface_.comm()
132 );
133
134 this->updatedMatrix(false);
135}
136
137
138template<class Type>
140(
141 solveScalarField& result,
142 const bool add,
143 const scalarField& coeffs,
144 const solveScalarField& vals
145) const
146{
147 const labelUList& faceCells = this->procInterface_.faceCells();
148
149 if (add)
150 {
151 forAll(faceCells, elemI)
152 {
153 result[faceCells[elemI]] += coeffs[elemI]*vals[elemI];
154 }
155 }
156 else
157 {
158 forAll(faceCells, elemI)
159 {
160 result[faceCells[elemI]] -= coeffs[elemI]*vals[elemI];
161 }
162 }
163}
164
165
166template<class Type>
168(
169 solveScalarField& result,
170 const bool add,
171 const lduAddressing& lduAddr,
172 const label patchId,
173 const solveScalarField& psiInternal,
174 const scalarField& coeffs,
175 const direction cmpt,
176 const Pstream::commsTypes commsType
177) const
178{
179 if (this->updatedMatrix())
180 {
181 return;
182 }
183
184 {
185 // Require receive data.
186 // Only update the send request state.
187 UPstream::waitRequest(recvRequest_); recvRequest_ = -1;
188 if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
189 }
190
191 // Consume straight from receive buffer. Note use of our own
192 // helper to avoid using fvPatch addressing
193 addToInternalField(result, !add, coeffs, scalarRecvBuf_);
194
195 this->updatedMatrix(true);
196}
197
198
199// ************************************************************************* //
An abstract base class for implicitly-coupled interface fields e.g. processor and cyclic patch fields...
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.
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
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.
static label nRequests() noexcept
Number of outstanding requests (on the internal list of requests).
commsTypes
Communications types.
Definition UPstream.H:81
@ nonBlocking
"nonBlocking" (immediate) : (MPI_Isend, MPI_Irecv)
Definition UPstream.H:84
static bool finishedRequestPair(label &req0, label &req1)
Non-blocking comms: have both requests finished? Corresponds to pair of MPI_Test().
static bool finishedRequest(const label i)
Non-blocking comms: has request i finished? Corresponds to MPI_Test().
static void waitRequest(const label i)
Wait until request i has finished. Corresponds to MPI_Wait().
Smooth ATC in cells next to a set of patches supplied by type.
Definition faceCells.H:55
The class contains the addressing required by the lduMatrix: upper, lower and losort.
virtual const labelUList & patchAddr(const label patchNo) const =0
Return patch to internal addressing given patch number.
A lduProcessorField type bypassing coupledFvPatchField.
const lduPrimitiveProcessorInterface & procInterface_
Local reference cast into the interface.
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.
lduCalculatedProcessorField(const lduInterface &interface)
Construct from ldu interface.
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.
solveScalarField scalarSendBuf_
Scalar send buffer.
virtual bool all_ready() const
Receive and send requests have both completed.
label recvRequest_
Current (non-blocking) recv request.
solveScalarField scalarRecvBuf_
Scalar recv buffer.
label sendRequest_
Current (non-blocking) send request.
void addToInternalField(solveScalarField &result, const bool add, const scalarField &coeffs, const solveScalarField &vals) const
virtual bool ready() const
Are all (receive) data available?
bool updatedMatrix() const noexcept
Whether matrix has been updated.
const lduInterface & interface() const noexcept
Return the interface.
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches.
Concrete implementation of processor interface. Used to temporarily store settings.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
label patchId(-1)
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
Definition typeInfo.H:172
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
void add(DimensionedField< scalar, GeoMesh > &result, const dimensioned< scalar > &dt1, const DimensionedField< scalar, GeoMesh > &f2)
errorManip< error > abort(error &err)
Definition errorManip.H:139
Field< solveScalar > solveScalarField
uint8_t direction
Definition direction.H:49
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
UList< label > labelUList
A UList of labels.
Definition UList.H:75
dict add("bounds", meshBb)
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299