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-2023 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  sendRequest_(-1),
43  recvRequest_(-1)
44 {}
45 
46 
47 template<class Type>
49 (
51 )
52 :
53  coupledFvPatchField<Type>(ptf),
54  procInterface_(ptf.procInterface_),
55  sendRequest_(-1),
56  recvRequest_(-1)
57 {}
58 
59 
60 template<class Type>
62 (
65 )
66 :
67  coupledFvPatchField<Type>(ptf, iF),
68  procInterface_(ptf.procInterface_),
69  sendRequest_(-1),
70  recvRequest_(-1)
71 {}
72 
73 
74 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
75 
76 template<class Type>
78 {
79  return UPstream::finishedRequestPair(recvRequest_, sendRequest_);
80 }
81 
82 
83 template<class Type>
85 {
86  const bool ok = UPstream::finishedRequest(recvRequest_);
87  if (ok)
88  {
89  recvRequest_ = -1;
90  if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
91  }
92  return ok;
93 }
94 
95 
96 template<class Type>
99 {
100  if (!this->ready())
101  {
103  << "Outstanding request on patch of size "
104  << procInterface_.faceCells().size()
105  << " between proc " << procInterface_.myProcNo()
106  << " and " << procInterface_.neighbProcNo()
107  << abort(FatalError);
108  }
109  return *this;
110 }
111 
112 
113 template<class Type>
115 (
116  const Pstream::commsTypes commsType
117 )
118 {
119  if (UPstream::parRun())
120  {
121  if (!is_contiguous<Type>::value)
122  {
124  << "Invalid for non-contiguous data types"
125  << abort(FatalError);
126  }
127 
128  //this->patchInternalField(sendBuf_);
129  // Bypass patchInternalField since uses fvPatch addressing
130  {
131  const Field<Type>& iF = this->internalField();
132  const labelList& fc = procInterface_.faceCells();
133  sendBuf_.resize_nocopy(fc.size());
134  forAll(fc, i)
135  {
136  sendBuf_[i] = iF[fc[i]];
137  }
138  }
139 
140  // Receive straight into *this
141  this->resize_nocopy(sendBuf_.size());
142 
143  recvRequest_ = UPstream::nRequests();
145  (
146  UPstream::commsTypes::nonBlocking,
147  procInterface_.neighbProcNo(),
148  this->data_bytes(),
149  this->size_bytes(),
150  procInterface_.tag(),
151  procInterface_.comm()
152  );
153 
154  sendRequest_ = UPstream::nRequests();
156  (
157  UPstream::commsTypes::nonBlocking,
158  procInterface_.neighbProcNo(),
159  sendBuf_.cdata_bytes(),
160  sendBuf_.size_bytes(),
161  procInterface_.tag(),
162  procInterface_.comm()
163  );
164  }
165 }
166 
167 
168 template<class Type>
170 (
171  const Pstream::commsTypes commsType
172 )
173 {
174  if (UPstream::parRun())
175  {
176  // Require receive data.
177  // Only update the send request state.
178  UPstream::waitRequest(recvRequest_); recvRequest_ = -1;
179  if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
180  }
181 }
182 
183 
184 template<class Type>
186 (
187  solveScalarField& result,
188  const bool add,
189  const lduAddressing& lduAddr,
190  const label patchId,
191  const solveScalarField& psiInternal,
192  const scalarField& coeffs,
193  const direction cmpt,
194  const Pstream::commsTypes commsType
195 ) const
196 {
197  if (!this->all_ready())
198  {
200  << "Outstanding request(s) on interface "
201  //<< interface_.name()
202  << abort(FatalError);
203  }
204 
205  // Bypass patchInternalField since uses fvPatch addressing
206  const labelList& fc = lduAddr.patchAddr(patchId);
207 
208  scalarSendBuf_.resize_nocopy(fc.size());
209  forAll(fc, i)
210  {
211  scalarSendBuf_[i] = psiInternal[fc[i]];
212  }
213 
214  scalarRecvBuf_.resize_nocopy(scalarSendBuf_.size());
215 
216  recvRequest_ = UPstream::nRequests();
218  (
219  UPstream::commsTypes::nonBlocking,
220  procInterface_.neighbProcNo(),
221  scalarRecvBuf_.data_bytes(),
222  scalarRecvBuf_.size_bytes(),
223  procInterface_.tag(),
224  procInterface_.comm()
225  );
226 
227  sendRequest_ = UPstream::nRequests();
229  (
230  UPstream::commsTypes::nonBlocking,
231  procInterface_.neighbProcNo(),
232  scalarSendBuf_.cdata_bytes(),
233  scalarSendBuf_.size_bytes(),
234  procInterface_.tag(),
235  procInterface_.comm()
236  );
238  this->updatedMatrix(false);
239 }
240 
241 
242 template<class Type>
244 (
245  solveScalarField& result,
246  const bool add,
247  const scalarField& coeffs,
248  const solveScalarField& vals
249 ) const
250 {
251  const labelUList& faceCells = this->procInterface_.faceCells();
252 
253  if (add)
254  {
255  forAll(faceCells, elemI)
256  {
257  result[faceCells[elemI]] += coeffs[elemI]*vals[elemI];
258  }
259  }
260  else
261  {
262  forAll(faceCells, elemI)
263  {
264  result[faceCells[elemI]] -= coeffs[elemI]*vals[elemI];
265  }
266  }
267 }
268 
269 
270 template<class Type>
272 (
273  solveScalarField& result,
274  const bool add,
275  const lduAddressing& lduAddr,
276  const label patchId,
277  const solveScalarField& psiInternal,
278  const scalarField& coeffs,
279  const direction cmpt,
280  const Pstream::commsTypes commsType
281 ) const
282 {
283  if (this->updatedMatrix())
284  {
285  return;
286  }
287 
288  if (UPstream::parRun())
289  {
290  // Require receive data.
291  // Only update the send request state.
292  UPstream::waitRequest(recvRequest_); recvRequest_ = -1;
293  if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
294  }
295 
296 
297  // Consume straight from receive buffer. Note use of our own
298  // helper to avoid using fvPatch addressing
299  addToInternalField(result, !add, coeffs, scalarRecvBuf_);
300 
301  this->updatedMatrix(true);
302 }
303 
304 
305 // ************************************************************************* //
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:598
Type & refCast(U &obj)
A dynamic_cast (for references). Generates a FatalError on failed casts and uses the virtual type() m...
Definition: typeInfo.H:159
virtual void evaluate(const Pstream::commsTypes commsType)
Evaluate the patch field.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
Definition: ListI.H:175
interfaceProperties interface(alpha1, U, thermo->transportPropertiesDict())
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:52
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
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.
virtual bool all_ready() const
Receive and send requests have both completed.
errorManip< error > abort(error &err)
Definition: errorManip.H:139
Abstract base class for coupled patches.
virtual bool ready() const
Are all (receive) 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