Loading...
Searching...
No Matches
mixedFvPatchField.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 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 "mixedFvPatchField.H"
30
31// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
32
33template<class Type>
35(
36 const dictionary& dict,
38)
39{
40 if (!IOobjectOption::isAnyRead(readOpt)) return false;
41 const auto& p = fvPatchFieldBase::patch();
42
43
44 // If there is a 'refValue', also require all others
45 const auto* hasValue = dict.findEntry("refValue", keyType::LITERAL);
46
47 if (!hasValue && IOobjectOption::isReadOptional(readOpt))
48 {
49 return false;
50 }
51
52 const auto* hasGrad = dict.findEntry("refGradient", keyType::LITERAL);
53 const auto* hasFrac = dict.findEntry("valueFraction", keyType::LITERAL);
54
55 // Combined error message on failure
56 if (!hasValue || !hasGrad || !hasFrac)
57 {
59 << "Required entries:";
60
61 if (!hasValue) FatalIOError << " 'refValue'";
62 if (!hasGrad) FatalIOError << " 'refGradient'";
63 if (!hasFrac) FatalIOError << " 'valueFraction'";
64
66 << " : missing for patch " << p.name()
67 << " : in dictionary " << dict.relativeName() << nl
69 }
70
71 // Everything verified - can assign
72 refValue_.assign(*hasValue, p.size());
73 refGrad_.assign(*hasGrad, p.size());
74 valueFraction_.assign(*hasFrac, p.size());
75
76 return true;
77}
78
79
80// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
81
82template<class Type>
84(
85 const fvPatch& p,
87)
88:
89 fvPatchField<Type>(p, iF),
90 refValue_(p.size()),
91 refGrad_(p.size()),
92 valueFraction_(p.size()),
93 source_(p.size(), Zero)
94{}
95
96
97template<class Type>
99(
100 const fvPatch& p,
102 const Foam::zero
103)
104:
105 fvPatchField<Type>(p, iF),
106 refValue_(p.size(), Zero),
107 refGrad_(p.size(), Zero),
108 valueFraction_(p.size(), Zero),
109 source_(p.size(), Zero)
110{}
111
112
113template<class Type>
115(
116 const fvPatch& p,
118 const dictionary& dict,
119 IOobjectOption::readOption requireMixed
120)
121:
122 // The "value" entry is not required
123 fvPatchField<Type>(p, iF, dict, IOobjectOption::NO_READ),
124 refValue_(p.size()),
125 refGrad_(p.size()),
126 valueFraction_(p.size()),
127 source_(p.size(), Zero)
128{
129 if (!readMixedEntries(dict, requireMixed))
130 {
131 // Not read (eg, optional and missing): no evaluate possible/need
132 return;
133 }
135 // Could also check/clamp fraction to 0-1 range
136 evaluate();
137}
138
139
140template<class Type>
142(
143 const mixedFvPatchField<Type>& ptf,
144 const fvPatch& p,
146 const fvPatchFieldMapper& mapper
147)
148:
149 fvPatchField<Type>(ptf, p, iF, mapper),
150 refValue_(ptf.refValue_, mapper),
151 refGrad_(ptf.refGrad_, mapper),
152 valueFraction_(ptf.valueFraction_, mapper),
153 source_(ptf.source_, mapper)
154{
155 if (notNull(iF) && mapper.hasUnmapped())
156 {
157 WarningInFunction
158 << "On field " << iF.name() << " patch " << p.name()
159 << " patchField " << this->type()
160 << " : mapper does not map all values." << nl
161 << " To avoid this warning fully specify the mapping in derived"
162 << " patch fields." << endl;
163 }
164}
165
166
167template<class Type>
169(
170 const mixedFvPatchField<Type>& ptf
171)
172:
173 fvPatchField<Type>(ptf),
174 refValue_(ptf.refValue_),
175 refGrad_(ptf.refGrad_),
176 valueFraction_(ptf.valueFraction_),
177 source_(ptf.source_)
178{}
179
180
181template<class Type>
183(
184 const mixedFvPatchField<Type>& ptf,
186)
187:
188 fvPatchField<Type>(ptf, iF),
189 refValue_(ptf.refValue_),
190 refGrad_(ptf.refGrad_),
191 valueFraction_(ptf.valueFraction_),
192 source_(ptf.source_)
193{}
194
195
196// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
197
198template<class Type>
200(
201 const fvPatchFieldMapper& m
202)
203{
205 refValue_.autoMap(m);
206 refGrad_.autoMap(m);
207 valueFraction_.autoMap(m);
208 source_.autoMap(m);
209}
210
211
212template<class Type>
214(
215 const fvPatchField<Type>& ptf,
216 const labelList& addr
217)
218{
219 fvPatchField<Type>::rmap(ptf, addr);
220
221 const mixedFvPatchField<Type>& mptf =
223
224 refValue_.rmap(mptf.refValue_, addr);
225 refGrad_.rmap(mptf.refGrad_, addr);
226 valueFraction_.rmap(mptf.valueFraction_, addr);
227 source_.rmap(mptf.source_, addr);
228}
229
230
231template<class Type>
233{
234 if (!this->updated())
235 {
236 this->updateCoeffs();
237 }
238
239 Field<Type>::operator=
240 (
241 lerp
242 (
243 this->patchInternalField() + refGrad_/this->patch().deltaCoeffs(),
244 refValue_,
245 valueFraction_
246 )
247 );
250}
251
252
253template<class Type>
256{
257 return lerp
258 (
259 refGrad_,
260 (refValue_ - this->patchInternalField())*this->patch().deltaCoeffs(),
261 valueFraction_
262 );
263}
264
265
266template<class Type>
269(
270 const tmp<scalarField>&
271) const
273 return Type(pTraits<Type>::one)*(1.0 - valueFraction_);
274}
275
276
277template<class Type>
280(
281 const tmp<scalarField>&
282) const
283{
284 return lerp
285 (
286 refGrad_/this->patch().deltaCoeffs(),
287 refValue_,
288 valueFraction_
289 );
290}
291
292
293template<class Type>
297 return -Type(pTraits<Type>::one)*valueFraction_*this->patch().deltaCoeffs();
298}
299
300
301template<class Type>
304{
305 return lerp
306 (
307 refGrad_,
308 this->patch().deltaCoeffs()*refValue_,
309 valueFraction_
310 );
311}
312
313
314template<class Type>
316{
318 refValue_.writeEntry("refValue", os);
319 refGrad_.writeEntry("refGradient", os);
320 valueFraction_.writeEntry("valueFraction", os);
321 source_.writeEntry("source", os);
323}
324
325
326// ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
virtual bool hasUnmapped() const =0
Any unmapped values?
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
static bool isReadOptional(readOption opt) noexcept
True if (LAZY_READ) bits are set [same as READ_IF_PRESENT].
readOption
Enumeration defining read preferences.
static bool isAnyRead(readOption opt) noexcept
True if any reading may be required (ie, != NO_READ).
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
void size(const label n)
Definition UList.H:118
commsTypes
Communications types.
Definition UPstream.H:81
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.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
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.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
virtual void rmap(const fvPatchField< Type > &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
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
@ LITERAL
String literal.
Definition keyType.H:82
This boundary condition provides a base class for 'mixed' type boundary conditions,...
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
mixedFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
virtual void write(Ostream &) const
Write.
virtual tmp< Field< Type > > gradientInternalCoeffs() const
Return the matrix diagonal coefficients corresponding to the.
virtual tmp< Field< Type > > snGrad() const
Return gradient at boundary.
virtual tmp< Field< Type > > valueInternalCoeffs(const tmp< scalarField > &) const
Return the matrix diagonal coefficients corresponding to the.
virtual tmp< Field< Type > > gradientBoundaryCoeffs() const
Return the matrix source coefficients corresponding to the.
virtual tmp< Field< Type > > valueBoundaryCoeffs(const tmp< scalarField > &) const
Return the matrix source coefficients corresponding to the.
virtual void rmap(const fvPatchField< Type > &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
bool readMixedEntries(const dictionary &dict, IOobjectOption::readOption readOpt=IOobjectOption::LAZY_READ)
Read the 'refValue', 'refGradient' and 'valueFraction' entries into their respective places.
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Evaluate the patch field.
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
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
volScalarField & p
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
OBJstream os(runTime.globalPath()/outputName)
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
Definition typeInfo.H:172
List< label > labelList
A List of labels.
Definition List.H:62
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
bool notNull(const T *ptr) noexcept
True if ptr is not a pointer (of type T) to the nullObject.
Definition nullObject.H:267
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
dimensioned< Type > lerp(const dimensioned< Type > &a, const dimensioned< Type > &b, const scalar t)
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict