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-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 )
37 :
39  procInterface_(refCast<const lduPrimitiveProcessorInterface>(interface)),
40  sendRequest_(-1),
41  recvRequest_(-1)
42 {}
43 
44 
45 template<class Type>
47 (
49 )
50 :
51  LduInterfaceField<Type>(refCast<const lduInterface>(ptf)),
52  procInterface_(ptf.procInterface_),
53  sendRequest_(-1),
54  recvRequest_(-1)
55 {}
56 
57 
58 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
59 
60 template<class Type>
62 {
63  return UPstream::finishedRequestPair(recvRequest_, sendRequest_);
64 }
65 
66 
67 template<class Type>
69 {
70  const bool ok = UPstream::finishedRequest(recvRequest_);
71  if (ok)
72  {
73  recvRequest_ = -1;
74  if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
75  }
76  return ok;
77 }
78 
79 
80 template<class Type>
82 (
83  solveScalarField& result,
84  const bool add,
85  const lduAddressing& lduAddr,
86  const label patchId,
87  const solveScalarField& psiInternal,
88  const scalarField& coeffs,
89  const direction cmpt,
90  const Pstream::commsTypes commsType
91 ) const
92 {
93  if (!this->all_ready())
94  {
96  << "Outstanding request(s) on interface "
97  //<< procInterface_.name()
98  << abort(FatalError);
99  }
100 
101  // Bypass patchInternalField since uses fvPatch addressing
102  const labelList& fc = lduAddr.patchAddr(patchId);
103 
104  scalarSendBuf_.resize_nocopy(fc.size());
105  forAll(fc, i)
106  {
107  scalarSendBuf_[i] = psiInternal[fc[i]];
108  }
109 
110  scalarRecvBuf_.resize_nocopy(scalarSendBuf_.size());
111 
112  recvRequest_ = UPstream::nRequests();
114  (
115  UPstream::commsTypes::nonBlocking,
116  procInterface_.neighbProcNo(),
117  scalarRecvBuf_.data_bytes(),
118  scalarRecvBuf_.size_bytes(),
119  procInterface_.tag(),
120  procInterface_.comm()
121  );
122 
123  sendRequest_ = UPstream::nRequests();
125  (
126  UPstream::commsTypes::nonBlocking,
127  procInterface_.neighbProcNo(),
128  scalarSendBuf_.cdata_bytes(),
129  scalarSendBuf_.size_bytes(),
130  procInterface_.tag(),
131  procInterface_.comm()
132  );
134  this->updatedMatrix(false);
135 }
136 
137 
138 template<class Type>
140 (
141  solveScalarField& result,
142  const bool add,
143  const scalarField& coeffs,
144  const solveScalarField& vals
145 ) const
146 {
147  const labelUList& faceCells = this->procInterface_.faceCells();
148 
149  if (add)
150  {
151  forAll(faceCells, elemI)
152  {
153  result[faceCells[elemI]] += coeffs[elemI]*vals[elemI];
154  }
155  }
156  else
157  {
158  forAll(faceCells, elemI)
159  {
160  result[faceCells[elemI]] -= coeffs[elemI]*vals[elemI];
161  }
162  }
163 }
164 
165 
166 template<class Type>
168 (
169  solveScalarField& result,
170  const bool add,
171  const lduAddressing& lduAddr,
172  const label patchId,
173  const solveScalarField& psiInternal,
174  const scalarField& coeffs,
175  const direction cmpt,
176  const Pstream::commsTypes commsType
177 ) const
178 {
179  if (this->updatedMatrix())
180  {
181  return;
182  }
183 
184  {
185  // Require receive data.
186  // Only update the send request state.
187  UPstream::waitRequest(recvRequest_); recvRequest_ = -1;
188  if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
189  }
190 
191  // Consume straight from receive buffer. Note use of our own
192  // helper to avoid using fvPatch addressing
193  addToInternalField(result, !add, coeffs, scalarRecvBuf_);
194 
195  this->updatedMatrix(true);
196 }
197 
198 
199 // ************************************************************************* //
label patchId(-1)
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.
uint8_t direction
Definition: direction.H:46
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
An abstract base class for implicitly-coupled interface fields e.g. processor and cyclic patch fields...
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)
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 bool all_ready() const
Receive and send requests have both completed.
lduCalculatedProcessorField(const lduInterface &interface)
Construct from ldu interface.
void addToInternalField(solveScalarField &result, const bool add, const scalarField &coeffs, const solveScalarField &vals) const
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
errorManip< error > abort(error &err)
Definition: errorManip.H:139
virtual bool ready() const
Are all (receive) data available?
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.
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches...
Definition: lduInterface.H:53
A lduProcessorField type bypassing coupledFvPatchField.
List< label > labelList
A List of labels.
Definition: List.H:62