Loading...
Searching...
No Matches
mixedFaPatchField.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) 2016-2017 Wikki Ltd
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 "mixedFaPatchField.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 = faPatchFieldBase::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 faPatch& p,
87)
88:
89 faPatchField<Type>(p, iF),
90 refValue_(p.size()),
91 refGrad_(p.size()),
92 valueFraction_(p.size())
93{}
94
95
96template<class Type>
98(
99 const faPatch& p,
101 const Foam::zero
102)
103:
104 faPatchField<Type>(p, iF),
105 refValue_(p.size(), Zero),
106 refGrad_(p.size(), Zero),
107 valueFraction_(p.size(), Zero)
108{}
109
110
111template<class Type>
113(
114 const faPatch& p,
116 const dictionary& dict,
117 IOobjectOption::readOption requireMixed
118)
119:
120 // The "value" entry is not required
121 faPatchField<Type>(p, iF, dict, IOobjectOption::NO_READ),
122 refValue_(p.size()),
123 refGrad_(p.size()),
124 valueFraction_(p.size())
125{
126 if (!readMixedEntries(dict, requireMixed))
127 {
128 // Not read (eg, optional and missing): no evaluate possible/need
129 return;
130 }
132 // Could also check/clamp fraction to 0-1 range
133 evaluate();
134}
135
136
137template<class Type>
139(
140 const mixedFaPatchField<Type>& ptf,
141 const faPatch& p,
143 const faPatchFieldMapper& mapper
144)
145:
146 faPatchField<Type>(ptf, p, iF, mapper),
147 refValue_(ptf.refValue_, mapper),
148 refGrad_(ptf.refGrad_, mapper),
149 valueFraction_(ptf.valueFraction_, mapper)
150{}
151
152
153template<class Type>
155(
156 const mixedFaPatchField<Type>& ptf
157)
158:
159 faPatchField<Type>(ptf),
160 refValue_(ptf.refValue_),
161 refGrad_(ptf.refGrad_),
162 valueFraction_(ptf.valueFraction_)
163{}
164
165
166template<class Type>
168(
169 const mixedFaPatchField<Type>& ptf,
171)
172:
173 faPatchField<Type>(ptf, iF),
174 refValue_(ptf.refValue_),
175 refGrad_(ptf.refGrad_),
176 valueFraction_(ptf.valueFraction_)
177{}
178
179
180// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
181
182template<class Type>
184(
185 const faPatchFieldMapper& m
186)
187{
189 refValue_.autoMap(m);
190 refGrad_.autoMap(m);
191 valueFraction_.autoMap(m);
192}
193
194
195template<class Type>
197(
198 const faPatchField<Type>& ptf,
199 const labelList& addr
200)
201{
202 faPatchField<Type>::rmap(ptf, addr);
203
204 const auto& mptf = refCast<const mixedFaPatchField<Type>>(ptf);
205
206 refValue_.rmap(mptf.refValue_, addr);
207 refGrad_.rmap(mptf.refGrad_, addr);
208 valueFraction_.rmap(mptf.valueFraction_, addr);
209}
210
211
212template<class Type>
214{
215 if (!this->updated())
216 {
217 this->updateCoeffs();
218 }
219
220 Field<Type>::operator=
221 (
222 lerp
223 (
224 this->patchInternalField() + refGrad_/this->patch().deltaCoeffs(),
225 refValue_,
226 valueFraction_
227 )
228 );
229
231}
232
233
234template<class Type>
236{
237 return lerp
238 (
239 refGrad_,
240 (refValue_ - this->patchInternalField())*this->patch().deltaCoeffs(),
241 valueFraction_
242 );
243}
244
245
246template<class Type>
248(
249 const tmp<scalarField>&
250) const
251{
252 return Type(pTraits<Type>::one)*(1.0 - valueFraction_);
253}
254
255
256template<class Type>
258(
259 const tmp<scalarField>&
260) const
261{
262 return lerp
263 (
264 refGrad_/this->patch().deltaCoeffs(),
265 refValue_,
266 valueFraction_
267 );
268}
269
270
271template<class Type>
275 return -Type(pTraits<Type>::one)*valueFraction_*this->patch().deltaCoeffs();
276}
277
278
279template<class Type>
282{
283 return lerp
284 (
285 refGrad_,
286 this->patch().deltaCoeffs()*refValue_,
287 valueFraction_
288 );
289}
290
291
292template<class Type>
294{
296 refValue_.writeEntry("refValue", os);
297 refGrad_.writeEntry("refGradient", os);
298 valueFraction_.writeEntry("valueFraction", os);
300}
301
302
303// ************************************************************************* //
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
void autoMap(const FieldMapper &map, const bool applyFlip=true)
Map from self.
Definition Field.C:465
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
bool updated() const noexcept
True if the boundary condition has already been updated.
const faPatch & patch() const noexcept
Return the patch.
A FieldMapper for finite-area patch fields.
faPatchField<Type> abstract base class. This class gives a fat-interface to all derived classes cover...
faPatchField(const faPatch &, const DimensionedField< Type, areaMesh > &)
Construct from patch and internal field.
virtual tmp< Field< Type > > patchInternalField() const
Return internal field next to patch.
virtual void rmap(const faPatchField< Type > &, const labelList &)
Reverse map the given faPatchField onto this faPatchField.
void writeValueEntry(Ostream &os) const
Write *this field as a "value" entry.
virtual void write(Ostream &os) const
Write.
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.
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition faPatch.H:76
@ LITERAL
String literal.
Definition keyType.H:82
This boundary condition provides a base class for 'mixed' type boundary conditions,...
virtual void write(Ostream &) const
Write.
virtual tmp< Field< Type > > gradientInternalCoeffs() const
Return the matrix diagonal coefficients corresponding to the.
virtual void rmap(const faPatchField< Type > &, const labelList &)
Reverse map the given faPatchField onto this faPatchField.
mixedFaPatchField(const faPatch &, const DimensionedField< Type, areaMesh > &)
Construct from patch and internal field.
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 autoMap(const faPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
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
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