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 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 const Field<Type>& iF
37)
38:
40 procInterface_(refCast<const lduPrimitiveProcessorInterface>(interface)),
41 field_(iF),
42 sendBuf_(procInterface_.faceCells().size()),
43 receiveBuf_(procInterface_.faceCells().size()),
44 scalarSendBuf_(procInterface_.faceCells().size()),
45 scalarReceiveBuf_(procInterface_.faceCells().size()),
46 outstandingSendRequest_(-1),
47 outstandingRecvRequest_(-1)
48{}
49
50
51template<class Type>
53(
55)
56:
57 LduInterfaceField<Type>(refCast<const lduInterface>(ptf)),
58 procInterface_(ptf.procInterface_),
59 field_(ptf.field_),
60 sendBuf_(procInterface_.faceCells().size()),
61 receiveBuf_(procInterface_.faceCells().size()),
62 scalarSendBuf_(procInterface_.faceCells().size()),
63 scalarReceiveBuf_(procInterface_.faceCells().size()),
64 outstandingSendRequest_(-1),
65 outstandingRecvRequest_(-1)
66{}
67
68
69// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
70
71template<class Type>
73{
74 if
75 (
76 this->outstandingSendRequest_ >= 0
77 && this->outstandingSendRequest_ < Pstream::nRequests()
78 )
79 {
80 if (!UPstream::finishedRequest(this->outstandingSendRequest_))
81 {
82 return false;
83 }
84 }
85 this->outstandingSendRequest_ = -1;
86
87 if
88 (
89 this->outstandingRecvRequest_ >= 0
90 && this->outstandingRecvRequest_ < Pstream::nRequests()
91 )
92 {
93 if (!UPstream::finishedRequest(this->outstandingRecvRequest_))
94 {
95 return false;
96 }
97 }
98 this->outstandingRecvRequest_ = -1;
99
100 return true;
101}
102
103
104template<class Type>
106(
107 solveScalarField& result,
108 const bool add,
109 const lduAddressing& lduAddr,
110 const label patchId,
111 const solveScalarField& psiInternal,
112 const scalarField& coeffs,
113 const direction cmpt,
114 const Pstream::commsTypes commsType
115) const
116{
117 // Bypass patchInternalField since uses fvPatch addressing
118 const labelList& fc = lduAddr.patchAddr(patchId);
119
120 scalarSendBuf_.setSize(fc.size());
121 forAll(fc, i)
122 {
123 scalarSendBuf_[i] = psiInternal[fc[i]];
124 }
125
126 if (!this->ready())
127 {
129 << "On patch "
130 << " outstanding request."
131 << abort(FatalError);
132 }
133
134
135 scalarReceiveBuf_.setSize(scalarSendBuf_.size());
136 outstandingRecvRequest_ = UPstream::nRequests();
137
139 (
141 procInterface_.neighbProcNo(),
142 scalarReceiveBuf_.data_bytes(),
143 scalarReceiveBuf_.size_bytes(),
144 procInterface_.tag(),
145 procInterface_.comm()
146 );
147
148 outstandingSendRequest_ = UPstream::nRequests();
149
151 (
153 procInterface_.neighbProcNo(),
154 scalarSendBuf_.cdata_bytes(),
155 scalarSendBuf_.size_bytes(),
156 procInterface_.tag(),
157 procInterface_.comm()
158 );
159
160 const_cast<lduInterfaceField&>
161 (
162 static_cast<const lduInterfaceField&>(*this)
163 ).updatedMatrix() = false;
164}
165
166
167template<class Type>
169(
170 solveScalarField& result,
171 const bool add,
172 const scalarField& coeffs,
173 const solveScalarField& vals
174) const
175{
176 const labelUList& faceCells = this->procInterface_.faceCells();
177
178 if (add)
179 {
180 forAll(faceCells, elemI)
181 {
182 result[faceCells[elemI]] += coeffs[elemI]*vals[elemI];
183 }
184 }
185 else
186 {
187 forAll(faceCells, elemI)
188 {
189 result[faceCells[elemI]] -= coeffs[elemI]*vals[elemI];
190 }
191 }
192}
193
194
195template<class Type>
197(
198 solveScalarField& result,
199 const bool add,
200 const lduAddressing& lduAddr,
201 const label patchId,
202 const solveScalarField& psiInternal,
203 const scalarField& coeffs,
204 const direction cmpt,
205 const Pstream::commsTypes commsType
206) const
207{
208 if (this->updatedMatrix())
209 {
210 return;
211 }
212
213 if
214 (
215 outstandingRecvRequest_ >= 0
216 && outstandingRecvRequest_ < Pstream::nRequests()
217 )
218 {
219 UPstream::waitRequest(outstandingRecvRequest_);
220 }
221 // Recv finished so assume sending finished as well.
222 outstandingSendRequest_ = -1;
223 outstandingRecvRequest_ = -1;
224
225 // Consume straight from scalarReceiveBuf_. Note use of our own
226 // helper to avoid using fvPatch addressing
227 addToInternalField(result, !add, coeffs, scalarReceiveBuf_);
228
229 const_cast<lduInterfaceField&>
230 (
231 static_cast<const lduInterfaceField&>(*this)
232 ).updatedMatrix() = true;
233}
234
235
236// ************************************************************************* //
Generic templated field type.
Definition: Field.H:82
An abstract base class for implicitly-coupled interface fields e.g. processor and cyclic patch fields...
virtual bool read()
Re-read model coefficients if they have changed.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
commsTypes
Types of communications.
Definition: UPstream.H:67
@ nonBlocking
"nonBlocking"
static label nRequests()
Get number of outstanding requests.
Definition: UPstream.C:90
static bool finishedRequest(const label i)
Non-blocking comms: has request i finished?
Definition: UPstream.C:108
static void waitRequest(const label i)
Wait until request i has finished.
Definition: UPstream.C:104
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:59
virtual bool write()
Write the output fields.
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 and holding a reference to the Field<Type>.
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.
void addToInternalField(solveScalarField &result, const bool add, const scalarField &coeffs, const solveScalarField &vals) const
virtual bool ready() const
Is all data available.
An abstract base class for implicitly-coupled interface fields e.g. processor and cyclic patch fields...
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches.
Definition: lduInterface.H:58
Concrete implementation of processor interface. Used to temporarily store settings.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
label patchId(-1)
To & refCast(From &r)
Reference type cast template function.
Definition: typeInfo.H:131
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
errorManip< error > abort(error &err)
Definition: errorManip.H:144
uint8_t direction
Definition: direction.H:56
error FatalError
interfaceProperties interface(alpha1, U, thermo->transportPropertiesDict())
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333