calculatedProcessorFvPatchField.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-2021 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 fvPatch& p,
38)
39:
40 coupledFvPatchField<Type>(p, iF),
41 procInterface_(refCast<const lduPrimitiveProcessorInterface>(interface)),
42 sendBuf_(interface.faceCells().size()),
43 receiveBuf_(interface.faceCells().size()),
44 scalarSendBuf_(interface.faceCells().size()),
45 scalarReceiveBuf_(interface.faceCells().size()),
46 outstandingSendRequest_(-1),
47 outstandingRecvRequest_(-1)
48{}
49
50
51template<class Type>
53(
55)
56:
57 coupledFvPatchField<Type>(ptf),
58 procInterface_(ptf.procInterface_),
59 sendBuf_(procInterface_.faceCells().size()),
60 receiveBuf_(procInterface_.faceCells().size()),
61 scalarSendBuf_(procInterface_.faceCells().size()),
62 scalarReceiveBuf_(procInterface_.faceCells().size()),
63 outstandingSendRequest_(-1),
64 outstandingRecvRequest_(-1)
65
66{}
67
68
69template<class Type>
71(
74)
75:
76 coupledFvPatchField<Type>(ptf, iF),
77 procInterface_(ptf.procInterface_),
78 sendBuf_(procInterface_.faceCells().size()),
79 receiveBuf_(procInterface_.faceCells().size()),
80 scalarSendBuf_(procInterface_.faceCells().size()),
81 scalarReceiveBuf_(procInterface_.faceCells().size()),
82 outstandingSendRequest_(-1),
83 outstandingRecvRequest_(-1)
84{}
85
86
87// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
88
89template<class Type>
91{
92 if
93 (
94 this->outstandingSendRequest_ >= 0
95 && this->outstandingSendRequest_ < Pstream::nRequests()
96 )
97 {
98 if (!UPstream::finishedRequest(this->outstandingSendRequest_))
99 {
100 return false;
101 }
102 }
103 this->outstandingSendRequest_ = -1;
104
105 if
106 (
107 this->outstandingRecvRequest_ >= 0
108 && this->outstandingRecvRequest_ < Pstream::nRequests()
109 )
110 {
111 if (!UPstream::finishedRequest(this->outstandingRecvRequest_))
112 {
113 return false;
114 }
115 }
116 this->outstandingRecvRequest_ = -1;
117
118 return true;
119}
120
121
122template<class Type>
125{
126 if (!this->ready())
127 {
129 << "On patch of size " << procInterface_.faceCells().size()
130 << " between proc " << procInterface_.myProcNo()
131 << " and " << procInterface_.neighbProcNo()
132 << " outstanding request."
133 << abort(FatalError);
134 }
135 return *this;
136}
137
138
139template<class Type>
141(
142 const Pstream::commsTypes commsType
143)
144{
145 if (Pstream::parRun())
146 {
148 {
150 << "Invalid for non-contiguous data types"
151 << abort(FatalError);
152 }
153
154 //this->patchInternalField(sendBuf_);
155 // Bypass patchInternalField since uses fvPatch addressing
156 {
157 const Field<Type>& iF = this->internalField();
158 const labelList& fc = procInterface_.faceCells();
159 sendBuf_.setSize(fc.size());
160 forAll(fc, i)
161 {
162 sendBuf_[i] = iF[fc[i]];
163 }
164 }
165
166 // Receive straight into *this
167 this->setSize(sendBuf_.size());
168 outstandingRecvRequest_ = UPstream::nRequests();
170 (
172 procInterface_.neighbProcNo(),
173 this->data_bytes(),
174 this->size_bytes(),
175 procInterface_.tag(),
176 procInterface_.comm()
177 );
178
179 outstandingSendRequest_ = UPstream::nRequests();
181 (
183 procInterface_.neighbProcNo(),
184 sendBuf_.cdata_bytes(),
185 sendBuf_.size_bytes(),
186 procInterface_.tag(),
187 procInterface_.comm()
188 );
189 }
190}
191
192
193template<class Type>
195(
196 const Pstream::commsTypes commsType
197)
198{
199 if (Pstream::parRun())
200 {
201 if
202 (
203 outstandingRecvRequest_ >= 0
204 && outstandingRecvRequest_ < Pstream::nRequests()
205 )
206 {
207 UPstream::waitRequest(outstandingRecvRequest_);
208 }
209 outstandingSendRequest_ = -1;
210 outstandingRecvRequest_ = -1;
211 }
212}
213
214
215template<class Type>
217(
218 solveScalarField& result,
219 const bool add,
220 const lduAddressing& lduAddr,
221 const label patchId,
222 const solveScalarField& psiInternal,
223 const scalarField& coeffs,
224 const direction cmpt,
225 const Pstream::commsTypes commsType
226) const
227{
228 // Bypass patchInternalField since uses fvPatch addressing
229
230 const labelList& fc = lduAddr.patchAddr(patchId);
231
232 scalarSendBuf_.setSize(fc.size());
233 forAll(fc, i)
234 {
235 scalarSendBuf_[i] = psiInternal[fc[i]];
236 }
237
238 if (!this->ready())
239 {
241 << "On patch " //<< interface_.name()
242 << " outstanding request."
243 << abort(FatalError);
244 }
245
246
247
248 scalarReceiveBuf_.setSize(scalarSendBuf_.size());
249 outstandingRecvRequest_ = UPstream::nRequests();
250
252 (
254 procInterface_.neighbProcNo(),
255 scalarReceiveBuf_.data_bytes(),
256 scalarReceiveBuf_.size_bytes(),
257 procInterface_.tag(),
258 procInterface_.comm()
259 );
260
261 outstandingSendRequest_ = UPstream::nRequests();
262
264 (
266 procInterface_.neighbProcNo(),
267 scalarSendBuf_.cdata_bytes(),
268 scalarSendBuf_.size_bytes(),
269 procInterface_.tag(),
270 procInterface_.comm()
271 );
272
273 const_cast<lduInterfaceField&>
274 (
275 static_cast<const lduInterfaceField&>(*this)
276 ).updatedMatrix() = false;
277}
278
279
280template<class Type>
282(
283 solveScalarField& result,
284 const bool add,
285 const scalarField& coeffs,
286 const solveScalarField& vals
287) const
288{
289 const labelUList& faceCells = this->procInterface_.faceCells();
290
291 if (add)
292 {
293 forAll(faceCells, elemI)
294 {
295 result[faceCells[elemI]] += coeffs[elemI]*vals[elemI];
296 }
297 }
298 else
299 {
300 forAll(faceCells, elemI)
301 {
302 result[faceCells[elemI]] -= coeffs[elemI]*vals[elemI];
303 }
304 }
305}
306
307
308template<class Type>
310(
311 solveScalarField& result,
312 const bool add,
313 const lduAddressing& lduAddr,
314 const label patchId,
315 const solveScalarField& psiInternal,
316 const scalarField& coeffs,
317 const direction cmpt,
318 const Pstream::commsTypes commsType
319) const
320{
321 if (this->updatedMatrix())
322 {
323 return;
324 }
325
326
327 if
328 (
329 outstandingRecvRequest_ >= 0
330 && outstandingRecvRequest_ < Pstream::nRequests()
331 )
332 {
333 UPstream::waitRequest(outstandingRecvRequest_);
334 }
335 // Recv finished so assume sending finished as well.
336 outstandingSendRequest_ = -1;
337 outstandingRecvRequest_ = -1;
338
339 // Consume straight from scalarReceiveBuf_. Note use of our own
340 // helper to avoid using fvPatch addressing
341 addToInternalField(result, !add, coeffs, scalarReceiveBuf_);
342
343 const_cast<lduInterfaceField&>
344 (
345 static_cast<const lduInterfaceField&>(*this)
346 ).updatedMatrix() = true;
347}
348
349
350// ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Generic templated field type.
Definition: Field.H:82
void evaluate()
Evaluate boundary conditions.
void setSize(const label n)
Alias for resize()
Definition: List.H:218
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
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
A processorFvPatchField type bypassing fvPatch.
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.
virtual void initEvaluate(const Pstream::commsTypes commsType)
Initialise the evaluation of the patch field.
void addToInternalField(solveScalarField &result, const bool add, const scalarField &coeffs, const solveScalarField &vals) const
virtual bool ready() const
Is all data available.
virtual tmp< Field< Type > > patchNeighbourField() const
Return neighbour field of internal field.
Abstract base class for coupled patches.
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:59
virtual bool write()
Write the output fields.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:71
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.
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.
A class for managing temporary objects.
Definition: tmp.H:65
volScalarField & p
#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
points setSize(newPointi)
interfaceProperties interface(alpha1, U, thermo->transportPropertiesDict())
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
A template class to specify that a data type can be considered as being contiguous in memory.
Definition: contiguous.H:78