Loading...
Searching...
No Matches
exprFixedValueFvPatchField.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) 2009-2018 Bernhard Gschaider
9 Copyright (C) 2019-2021 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\*---------------------------------------------------------------------------*/
30#include "dictionaryContent.H"
31
32// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
33
34template<class Type>
36{
38 {
39 debug = 1;
40 }
41}
42
43
44// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45
46template<class Type>
48(
49 const fvPatch& p,
50 const DimensionedField<Type, volMesh>& iF
51)
52:
53 parent_bctype(p, iF),
55 dict_(),
56 driver_(this->patch())
57{}
58
59
60template<class Type>
62(
64 const fvPatch& p,
66 const fvPatchFieldMapper& mapper
67)
68:
69 parent_bctype(rhs, p, iF, mapper),
70 expressions::patchExprFieldBase(rhs),
71 dict_(rhs.dict_), // Deep copy
72 driver_(this->patch(), rhs.driver_, dict_)
74 setDebug();
76}
77
78
79template<class Type>
81(
82 const fvPatch& p,
84 const dictionary& dict,
85 IOobjectOption::readOption requireValue // (ignored)
86)
87:
88 parent_bctype(p, iF), // bypass dictionary constructor
89 expressions::patchExprFieldBase
90 (
91 dict,
92 expressions::patchExprFieldBase::expectedTypes::VALUE_TYPE
93 ),
94 dict_
95 (
96 // Copy dictionary without "heavy" data chunks
97 dictionaryContent::copyDict
98 (
99 dict,
100 wordList(), // allow
101 wordList // deny
102 ({
103 "type", // redundant
104 "value"
105 })
106 )
107 ),
108 driver_(this->patch(), dict_)
109{
111 << "Use uniformFixedValue with an expression Function1 instead." << nl
112 << " This boundary condition will be removed in the future" << endl;
113
114 setDebug();
116
117 // Require valueExpr
118 if (this->valueExpr_.empty())
119 {
121 << "The valueExpr was not defined!" << nl
122 << exit(FatalIOError);
123 }
124
125
126 driver_.readDict(dict_);
127
128 // Since we bypassed dictionary constructor
130
131 if (!this->readValueEntry(dict))
132 {
133 // Ensure field has reasonable initial values
134 this->extrapolateInternal();
135
136 #ifdef FULLDEBUG
138 << "No value defined for "
139 << this->internalField().name() << " on "
140 << this->patch().name() << " - using patch internal field" << endl;
141 #endif
142 }
143
144 if (this->evalOnConstruct_)
145 {
146 // For potentialFoam or other solvers that don't evaluate
147 this->evaluate();
148 }
149}
150
151
152template<class Type>
154(
155 const exprFixedValueFvPatchField<Type>& rhs
156)
157:
158 parent_bctype(rhs),
159 expressions::patchExprFieldBase(rhs),
160 dict_(rhs.dict_), // Deep copy
161 driver_(this->patch(), rhs.driver_, dict_)
163 setDebug();
165}
166
167
168template<class Type>
170(
173)
174:
175 parent_bctype(rhs, iF),
176 expressions::patchExprFieldBase(rhs),
177 dict_(rhs.dict_), // Deep copy
178 driver_(this->patch(), rhs.driver_, dict_)
179{
180 setDebug();
182}
183
184
185// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
186
187template<class Type>
189{
190 if (this->updated())
191 {
192 return;
193 }
194
195 if (debug)
196 {
198 << "Value: " << this->valueExpr_ << nl
199 << "Variables: ";
200 driver_.writeVariableStrings(Info) << nl;
201 Info<< "... updating" << endl;
202 }
203
204
205 // Expression evaluation
206 {
207 bool evalValue = (!this->valueExpr_.empty() && this->valueExpr_ != "0");
208
209
210 driver_.clearVariables();
211
212 if (evalValue)
213 {
214 (*this) == driver_.evaluate<Type>(this->valueExpr_);
215 }
216 else
217 {
218 (*this) == Zero;
219 }
221
222 this->parent_bctype::updateCoeffs();
223}
224
225
226template<class Type>
228{
229 this->parent_bctype::write(os);
231
232 driver_.writeCommon(os, this->debug_ || debug);
233}
234
235
236// ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
readOption
Enumeration defining read preferences.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A wrapper for dictionary content, without operators that could affect inheritance patterns.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A fixed value boundary condition with expressions.
exprFixedValueFvPatchField(const fvPatch &p, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
dictionary dict_
Dictionary contents for the boundary condition.
expressions::patchExpr::parseDriver driver_
The expression driver.
virtual void write(Ostream &os) const
Write.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
void setDebug()
Set debug ON if "debug" is enabled.
void write(Ostream &os) const
Write.
expectedTypes
Enumeration of expected expressions.
virtual void write(Ostream &) const
Write includes "value" entry.
virtual void readDict(const dictionary &dict)
Read dictionary entries.
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.
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.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition fvPatch.H:71
volScalarField & p
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
OBJstream os(runTime.globalPath()/outputName)
#define WarningInFunction
Report a warning using Foam::Warning.
#define DeprecatedInFunction(afterVersion)
Report a warning using Foam::Warning.
#define DebugInFunction
Report an information message using Foam::Info.
#define InfoInFunction
Report an information message using Foam::Info.
Namespace for handling debugging switches.
Definition debug.C:45
A namespace for expression-related classes/traits etc.
const std::string patch
OpenFOAM patch number as a std::string.
string evaluate(label fieldWidth, const std::string &s, size_t pos=0, size_t len=std::string::npos)
String evaluation with specified (positive, non-zero) field width.
List< word > wordList
List of word.
Definition fileName.H:60
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
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
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict