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 -------------------------------------------------------------------------------
10 License
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 
32 template<class Type>
34 (
35  const lduInterface& interface,
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 
51 template<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 
69 template<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 
89 template<class Type>
91 {
92  if
93  (
94  this->outstandingSendRequest_ >= 0
95  && this->outstandingSendRequest_ < UPstream::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_ < UPstream::nRequests()
109  )
110  {
111  if (!UPstream::finishedRequest(this->outstandingRecvRequest_))
112  {
113  return false;
114  }
115  }
116  this->outstandingRecvRequest_ = -1;
118  return true;
119 }
120 
121 
122 template<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 
139 template<class Type>
141 (
142  const Pstream::commsTypes commsType
143 )
144 {
145  if (Pstream::parRun())
146  {
147  if (!is_contiguous<Type>::value)
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  (
171  Pstream::commsTypes::nonBlocking,
172  procInterface_.neighbProcNo(),
173  this->data_bytes(),
174  this->size_bytes(),
175  procInterface_.tag(),
176  procInterface_.comm()
177  );
178 
179  outstandingSendRequest_ = UPstream::nRequests();
181  (
182  Pstream::commsTypes::nonBlocking,
183  procInterface_.neighbProcNo(),
184  sendBuf_.cdata_bytes(),
185  sendBuf_.size_bytes(),
186  procInterface_.tag(),
187  procInterface_.comm()
188  );
189  }
190 }
191 
192 
193 template<class Type>
195 (
196  const Pstream::commsTypes commsType
197 )
198 {
199  if (Pstream::parRun())
200  {
201  if
202  (
203  outstandingRecvRequest_ >= 0
204  && outstandingRecvRequest_ < UPstream::nRequests()
205  )
206  {
207  UPstream::waitRequest(outstandingRecvRequest_);
208  }
209  outstandingSendRequest_ = -1;
210  outstandingRecvRequest_ = -1;
211  }
212 }
213 
214 
215 template<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  (
253  Pstream::commsTypes::nonBlocking,
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  (
265  Pstream::commsTypes::nonBlocking,
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 
280 template<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 
308 template<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_ < UPstream::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 // ************************************************************************* //
label patchId(-1)
uint8_t direction
Definition: direction.H:46
void addToInternalField(solveScalarField &result, const bool add, const scalarField &coeffs, const solveScalarField &vals) const
virtual tmp< Field< Type > > patchNeighbourField() const
Return neighbour field of internal field.
Field< solveScalar > solveScalarField
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
Type & refCast(U &obj)
A dynamic_cast (for references) that generates FatalError on failed casts, uses the virtual type() me...
Definition: typeInfo.H:151
virtual void evaluate(const Pstream::commsTypes commsType)
Evaluate the patch field.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:68
interfaceProperties interface(alpha1, U, thermo->transportPropertiesDict())
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:52
An abstract base class for implicitly-coupled interface fields e.g. processor and cyclic patch fields...
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:413
points setSize(newPointi)
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
void setSize(const label n)
Alias for resize()
Definition: List.H:289
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
virtual void initEvaluate(const Pstream::commsTypes commsType)
Initialise the evaluation of the patch field.
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.
errorManip< error > abort(error &err)
Definition: errorManip.H:139
Abstract base class for coupled patches.
virtual bool ready() const
Is all data available.
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.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Concrete implementation of processor interface. Used to temporarily store settings.
calculatedProcessorFvPatchField(const lduInterface &interface, const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches...
Definition: lduInterface.H:53
A processorFvPatchField type bypassing fvPatch.
List< label > labelList
A List of labels.
Definition: List.H:62
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50