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 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  //lduInterfaceField(interface),
42  procInterface_(refCast<const lduPrimitiveProcessorInterface>(interface)),
43  sendBuf_(interface.faceCells().size()),
44  receiveBuf_(interface.faceCells().size()),
45  scalarSendBuf_(interface.faceCells().size()),
46  scalarReceiveBuf_(interface.faceCells().size()),
47  outstandingSendRequest_(-1),
48  outstandingRecvRequest_(-1)
49 {}
50 
51 
52 template<class Type>
54 (
56 )
57 :
58  //lduInterfaceField(ptf.procInterface_),
60  procInterface_(ptf.procInterface_),
61  sendBuf_(procInterface_.faceCells().size()),
62  receiveBuf_(procInterface_.faceCells().size()),
63  scalarSendBuf_(procInterface_.faceCells().size()),
64  scalarReceiveBuf_(procInterface_.faceCells().size()),
65  outstandingSendRequest_(-1),
66  outstandingRecvRequest_(-1)
67 
68 {}
69 
70 
71 template<class Type>
73 (
76 )
77 :
78  //lduInterfaceField(ptf.procInterface_),
80  procInterface_(ptf.procInterface_),
81  sendBuf_(procInterface_.faceCells().size()),
82  receiveBuf_(procInterface_.faceCells().size()),
83  scalarSendBuf_(procInterface_.faceCells().size()),
84  scalarReceiveBuf_(procInterface_.faceCells().size()),
85  outstandingSendRequest_(-1),
86  outstandingRecvRequest_(-1)
87 {}
88 
89 
90 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
91 
92 template<class Type>
94 {
95  if
96  (
97  this->outstandingSendRequest_ >= 0
98  && this->outstandingSendRequest_ < Pstream::nRequests()
99  )
100  {
101  bool finished =
102  UPstream::finishedRequest(this->outstandingSendRequest_);
103  if (!finished)
104  {
105  return false;
106  }
107  }
108  this->outstandingSendRequest_ = -1;
109 
110  if
111  (
112  this->outstandingRecvRequest_ >= 0
113  && this->outstandingRecvRequest_ < Pstream::nRequests()
114  )
115  {
116  bool finished =
117  UPstream::finishedRequest(this->outstandingRecvRequest_);
118  if (!finished)
119  {
120  return false;
121  }
122  }
123  this->outstandingRecvRequest_ = -1;
124 
125  return true;
126 }
127 
128 
129 template<class Type>
132 {
133  if (debug && !this->ready())
134  {
136  << "On patch of size " << procInterface_.faceCells().size()
137  << " between proc " << procInterface_.myProcNo()
138  << " and " << procInterface_.neighbProcNo()
139  << " outstanding request."
140  << abort(FatalError);
141  }
142  return *this;
143 }
144 
145 
146 template<class Type>
148 (
149  const Pstream::commsTypes commsType
150 )
151 {
152  if (Pstream::parRun())
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  reinterpret_cast<char*>(this->begin()),
174  this->byteSize(),
175  procInterface_.tag(),
176  procInterface_.comm()
177  );
178 
179  outstandingSendRequest_ = UPstream::nRequests();
181  (
182  Pstream::commsTypes::nonBlocking,
183  procInterface_.neighbProcNo(),
184  reinterpret_cast<const char*>(sendBuf_.begin()),
185  this->byteSize(),
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_ < Pstream::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 solveScalarField& psiInternal,
221  const scalarField& coeffs,
222  const direction cmpt,
223  const Pstream::commsTypes commsType
224 ) const
225 {
226  // Bypass patchInternalField since uses fvPatch addressing
227  const labelList& fc = procInterface_.faceCells();
228  scalarSendBuf_.setSize(fc.size());
229  forAll(fc, i)
230  {
231  scalarSendBuf_[i] = psiInternal[fc[i]];
232  }
233 
234  if (debug && !this->ready())
235  {
237  << "On patch " //<< interface_.name()
238  << " outstanding request."
239  << abort(FatalError);
240  }
241 
242 
243  scalarReceiveBuf_.setSize(scalarSendBuf_.size());
244  outstandingRecvRequest_ = UPstream::nRequests();
246  (
247  Pstream::commsTypes::nonBlocking,
248  procInterface_.neighbProcNo(),
249  reinterpret_cast<char*>(scalarReceiveBuf_.begin()),
250  scalarReceiveBuf_.byteSize(),
251  procInterface_.tag(),
252  procInterface_.comm()
253  );
254 
255  outstandingSendRequest_ = UPstream::nRequests();
257  (
258  Pstream::commsTypes::nonBlocking,
259  procInterface_.neighbProcNo(),
260  reinterpret_cast<const char*>(scalarSendBuf_.begin()),
261  scalarSendBuf_.byteSize(),
262  procInterface_.tag(),
263  procInterface_.comm()
264  );
265 
266  const_cast<lduInterfaceField&>
267  (
268  static_cast<const lduInterfaceField&>(*this)
269  ).updatedMatrix() = false;
270 }
271 
272 
273 template<class Type>
275 (
276  solveScalarField& result,
277  const bool add,
278  const scalarField& coeffs,
279  const solveScalarField& vals
280 ) const
281 {
282  const labelUList& faceCells = this->procInterface_.faceCells();
283 
284  if (add)
285  {
286  forAll(faceCells, elemI)
287  {
288  result[faceCells[elemI]] += coeffs[elemI]*vals[elemI];
289  }
290  }
291  else
292  {
293  forAll(faceCells, elemI)
294  {
295  result[faceCells[elemI]] -= coeffs[elemI]*vals[elemI];
296  }
297  }
298 }
299 
300 
301 template<class Type>
303 (
304  solveScalarField& result,
305  const bool add,
306  const solveScalarField& psiInternal,
307  const scalarField& coeffs,
308  const direction cmpt,
309  const Pstream::commsTypes commsType
310 ) const
311 {
312  if (this->updatedMatrix())
313  {
314  return;
315  }
316 
317  if
318  (
319  outstandingRecvRequest_ >= 0
320  && outstandingRecvRequest_ < Pstream::nRequests()
321  )
322  {
323  UPstream::waitRequest(outstandingRecvRequest_);
324  }
325  // Recv finished so assume sending finished as well.
326  outstandingSendRequest_ = -1;
327  outstandingRecvRequest_ = -1;
328 
329  // Consume straight from scalarReceiveBuf_. Note use of our own
330  // helper to avoid using fvPatch addressing
331  addToInternalField(result, !add, coeffs, scalarReceiveBuf_);
332 
333  const_cast<lduInterfaceField&>
334  (
335  static_cast<const lduInterfaceField&>(*this)
336  ).updatedMatrix() = true;
337 }
338 
339 
340 //template<class Type>
341 //void Foam::calculatedProcessorFvPatchField<Type>::write(Ostream& os) const
342 //{
343 // //zeroGradientFvPatchField<Type>::write(os);
344 // fvPatchField<Type>::write(os);
345 // this->writeEntry("value", os);
346 //}
347 
348 
349 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
setSize
points setSize(newPointi)
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::calculatedProcessorFvPatchField::addToInternalField
void addToInternalField(solveScalarField &result, const bool add, const scalarField &coeffs, const solveScalarField &vals) const
Definition: calculatedProcessorFvPatchField.C:275
stdFoam::begin
constexpr auto begin(C &c) -> decltype(c.begin())
Return iterator to the beginning of the container c.
Definition: stdFoam.H:97
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::calculatedProcessorFvPatchField::evaluate
virtual void evaluate(const Pstream::commsTypes commsType)
Evaluate the patch field.
Definition: calculatedProcessorFvPatchField.C:195
Foam::calculatedProcessorFvPatchField::initInterfaceMatrixUpdate
virtual void initInterfaceMatrixUpdate(solveScalarField &result, const bool add, const solveScalarField &psiInternal, const scalarField &coeffs, const direction cmpt, const Pstream::commsTypes commsType) const
Initialise neighbour matrix update.
Definition: calculatedProcessorFvPatchField.C:217
interface
interfaceProperties interface(alpha1, U, thermo->transportPropertiesDict())
Foam::lduInterface
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches.
Definition: lduInterface.H:54
Foam::calculatedProcessorFvPatchField::patchNeighbourField
virtual tmp< Field< Type > > patchNeighbourField() const
Return neighbour field of internal field.
Definition: calculatedProcessorFvPatchField.C:131
Foam::calculatedProcessorFvPatchField::initEvaluate
virtual void initEvaluate(const Pstream::commsTypes commsType)
Initialise the evaluation of the patch field.
Definition: calculatedProcessorFvPatchField.C:148
Foam::calculatedProcessorFvPatchField::ready
virtual bool ready() const
Is all data available.
Definition: calculatedProcessorFvPatchField.C:93
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
calculatedProcessorFvPatchField.H
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
Foam::calculatedProcessorFvPatchField::updateInterfaceMatrix
virtual void updateInterfaceMatrix(solveScalarField &result, const bool add, const solveScalarField &psiInternal, const scalarField &coeffs, const direction cmpt, const Pstream::commsTypes commsType) const
Update result field based on interface functionality.
Definition: calculatedProcessorFvPatchField.C:303
Foam::blockMeshTools::read
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:33
Foam::FatalError
error FatalError
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::lduInterfaceField
An abstract base class for implicitly-coupled interface fields e.g. processor and cyclic patch fields...
Definition: lduInterfaceField.H:58
Foam::calculatedProcessorFvPatchField::procInterface_
const lduPrimitiveProcessorInterface & procInterface_
Local reference cast into the interface.
Definition: calculatedProcessorFvPatchField.H:73
Foam::calculatedProcessorFvPatchField
processorFvPatchField type bypassing fvPatch
Definition: calculatedProcessorFvPatchField.H:63
Foam::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:69
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::coupledFvPatchField
Abstract base class for coupled patches.
Definition: coupledFvPatchField.H:57
Foam::List< label >
Foam::UList< label >
Foam::calculatedProcessorFvPatchField::calculatedProcessorFvPatchField
calculatedProcessorFvPatchField(const lduInterface &interface, const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
Definition: calculatedProcessorFvPatchField.C:34
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:35
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::faceCells
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:56
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54