Loading...
Searching...
No Matches
coupledFvPatchField.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2023-2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "coupledFvPatchField.H"
30
31// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
32
33template<class Type>
35(
36 const fvPatch& p,
38)
40 LduInterfaceField<Type>(refCast<const lduInterface>(p)),
41 fvPatchField<Type>(p, iF)
42{}
43
44
45template<class Type>
47(
48 const fvPatch& p,
50 const Field<Type>& f
51)
53 LduInterfaceField<Type>(refCast<const lduInterface>(p)),
54 fvPatchField<Type>(p, iF, f)
55{}
56
57
58template<class Type>
60(
62 const fvPatch& p,
64 const fvPatchFieldMapper& mapper
65)
67 LduInterfaceField<Type>(refCast<const lduInterface>(p)),
68 fvPatchField<Type>(ptf, p, iF, mapper)
69{}
70
71
72template<class Type>
74(
75 const fvPatch& p,
77 const dictionary& dict,
79)
81 LduInterfaceField<Type>(refCast<const lduInterface>(p, dict)),
82 fvPatchField<Type>(p, iF, dict, requireValue)
83{}
84
85
86template<class Type>
88(
90)
92 LduInterfaceField<Type>(refCast<const lduInterface>(ptf.patch())),
93 fvPatchField<Type>(ptf)
94{}
95
96
97template<class Type>
99(
100 const coupledFvPatchField<Type>& ptf,
102)
103:
104 LduInterfaceField<Type>(refCast<const lduInterface>(ptf.patch())),
105 fvPatchField<Type>(ptf, iF)
106{}
107
108
109// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
110
111template<class Type>
113(
114 const scalarField& deltaCoeffs,
115 UList<Type>& result
116) const
117{
118 // Get patch neighbour field, store temporarily in result
119 this->patchNeighbourField(result);
120 const auto& pnf = result;
121
122 // Same as patchInternalField(...), assuming faceCells are an indirection
123 // into internal field, but without additional storage...
124 const auto& addr = this->patch().faceCells();
125 const auto& iF = this->primitiveField();
126
127 // snGrad = deltaCoeffs * (patchNeighbourField - patchInternalField)
128
129 const label len = result.size();
130
131 for (label i = 0; i < len; ++i)
133 result[i] = deltaCoeffs[i]*(pnf[i] - iF[addr[i]]);
134 }
135}
136
137
138template<class Type>
140(
141 const scalarField& deltaCoeffs
142) const
143{
144 auto tresult = tmp<Field<Type>>::New(this->size());
145 this->snGrad(deltaCoeffs, tresult.ref());
146 return tresult;
147}
148
149
150template<class Type>
152{
153 if (!this->updated())
155 this->updateCoeffs();
156 }
157}
158
159
160template<class Type>
161void Foam::coupledFvPatchField<Type>::evaluate(const Pstream::commsTypes)
162{
163 if (!this->updated())
164 {
165 this->updateCoeffs();
166 }
167
168 Field<Type>::operator=
169 (
170 lerp
171 (
172 this->patchNeighbourField(),
173 this->patchInternalField(),
174 this->patch().weights()
175 )
176 );
177
179}
180
181
182template<class Type>
184(
185 const tmp<scalarField>& tweights,
186 UList<Type>& result
187) const
189 const auto& w = tweights();
190
191 const label len = result.size();
192
193 for (label i = 0; i < len; ++i)
194 {
195 result[i] = Type(pTraits<Type>::one)*w[i];
196 }
197 tweights.clear();
198}
199
200
201template<class Type>
203(
204 const tmp<scalarField>& tweights,
206) const
207{
208 const auto& w = tweights();
209
210 const label len = result.size();
211
212 for (label i = 0; i < len; ++i)
214 result[i] = Type(pTraits<Type>::one)*(1.0 - w[i]);
216 tweights.clear();
217}
218
219
220template<class Type>
223(
224 const tmp<scalarField>& w
225) const
227 return Type(pTraits<Type>::one)*w;
228}
229
230
231template<class Type>
234(
235 const tmp<scalarField>& w
236) const
237{
238 return Type(pTraits<Type>::one)*(1.0 - w);
239}
240
241
242template<class Type>
244(
245 const scalarField& deltaCoeffs,
246 UList<Type>& result
247) const
249 const label len = result.size();
250
251 for (label i = 0; i < len; ++i)
253 result[i] = -Type(pTraits<Type>::one)*deltaCoeffs[i];
254 }
255}
256
258template<class Type>
260(
261 const scalarField& deltaCoeffs,
262 UList<Type>& result
263) const
264{
265 const label len = result.size();
267 for (label i = 0; i < len; ++i)
268 {
269 result[i] = Type(pTraits<Type>::one)*deltaCoeffs[i];
270 }
271}
272
273
274template<class Type>
277(
278 const scalarField& deltaCoeffs
279) const
280{
281 auto tresult = tmp<Field<Type>>::New(deltaCoeffs.size());
282 this->gradientInternalCoeffs(deltaCoeffs, tresult.ref());
283 return tresult;
284}
285
286
287template<class Type>
292 return -Type(pTraits<Type>::one)*this->patch().deltaCoeffs();
293}
294
295
296template<class Type>
298(
299 UList<Type>& result
300) const
301{
303 this->gradientInternalCoeffs(this->patch().deltaCoeffs(), result);
304}
305
306
307template<class Type>
310(
311 const scalarField& deltaCoeffs
312) const
314 return -this->gradientInternalCoeffs(deltaCoeffs);
315}
316
317
318template<class Type>
323 return -this->gradientInternalCoeffs();
324}
325
326
327template<class Type>
329(
330 UList<Type>& result
331) const
334 this->gradientBoundaryCoeffs(this->patch().deltaCoeffs(), result);
335}
336
337
338template<class Type>
340{
343}
344
345
346// ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
readOption
Enumeration defining read preferences.
An abstract base class for implicitly-coupled interface fields e.g. processor and cyclic patch fields...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
commsTypes
Communications types.
Definition UPstream.H:81
Abstract base class for coupled patches.
virtual tmp< Field< Type > > gradientBoundaryCoeffs(const scalarField &deltaCoeffs) const
Return the matrix source coefficients corresponding to the evaluation of the gradient of this patchFi...
virtual void write(Ostream &) const
Write includes "value" entry.
virtual tmp< Field< Type > > gradientInternalCoeffs() const
Return the matrix diagonal coefficients corresponding to the evaluation of the gradient of this patch...
virtual tmp< Field< Type > > valueInternalCoeffs(const tmp< scalarField > &) const
Return the matrix diagonal coefficients corresponding to the evaluation of the value of this patchFie...
virtual tmp< Field< Type > > snGrad(const scalarField &deltaCoeffs) const
Return patch-normal gradient.
virtual void initEvaluate(const Pstream::commsTypes commsType)
Initialise the evaluation of the patch field.
virtual tmp< Field< Type > > gradientBoundaryCoeffs() const
Return the matrix source coefficients corresponding to the.
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
coupledFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
virtual tmp< Field< Type > > valueBoundaryCoeffs(const tmp< scalarField > &) const
Return the matrix source coefficients corresponding to the evaluation of the value of this patchField...
virtual void evaluate(const Pstream::commsTypes commsType)
Evaluate the patch field.
virtual tmp< Field< Type > > patchNeighbourField() const =0
Return neighbour field of internal field.
virtual tmp< Field< Type > > gradientInternalCoeffs(const scalarField &deltaCoeffs) const
Return the matrix diagonal coefficients corresponding to the evaluation of the gradient of this patch...
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
const fvPatch & patch() const noexcept
Return the patch.
bool updated() const noexcept
True if the boundary condition has already been updated.
A FieldMapper for finite-volume patch fields.
static tmp< fvPatchField< Type > > New(const word &patchFieldType, const fvPatch &, const DimensionedField< Type, volMesh > &)
Return a pointer to a new patchField created on freestore given.
virtual void write(Ostream &) const
Write.
virtual tmp< Field< Type > > patchInternalField() const
Return internal field next to patch.
void writeValueEntry(Ostream &os) const
Write *this field as a "value" entry.
const Field< Type > & primitiveField() const noexcept
Return const-reference to the internal field values.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Evaluate the patch field, sets updated() to false.
fvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition fvPatch.H:71
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches.
A traits class, which is primarily used for primitives and vector-space.
Definition pTraits.H:64
A class for managing temporary objects.
Definition tmp.H:75
void clear() const noexcept
If object pointer points to valid object: delete object and set pointer to nullptr.
Definition tmpI.H:289
volScalarField & p
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition error.H:688
OBJstream os(runTime.globalPath()/outputName)
const std::string patch
OpenFOAM patch number as a std::string.
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
Definition typeInfo.H:172
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dimensioned< Type > lerp(const dimensioned< Type > &a, const dimensioned< Type > &b, const scalar t)
labelList f(nPoints)
dictionary dict