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\*---------------------------------------------------------------------------*/
28
30#include "dictionaryContent.H"
31
32// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
33
34template<class Type>
36{
37 if (expressions::patchExprFieldBase::debug_ && !debug)
38 {
39 debug = 1;
40 }
41}
42
43
44// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45
46template<class Type>
48(
49 const fvPatch& p,
51)
52:
53 parent_bctype(p, iF),
54 expressions::patchExprFieldBase(),
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_)
73{
74 setDebug();
76}
77
78
79template<class Type>
81(
82 const fvPatch& p,
84 const dictionary& dict,
85 const bool valueRequired
86)
87:
88 parent_bctype(p, iF),
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{
110 setDebug();
112
113 // Require valueExpr
114 if (this->valueExpr_.empty())
115 {
117 << "The valueExpr was not defined!" << nl
118 << exit(FatalIOError);
119 }
120
121
122 driver_.readDict(dict_);
123
124 if (dict.found("value"))
125 {
127 (
128 Field<Type>("value", dict, p.size())
129 );
130 }
131 else
132 {
133 (*this) == this->patchInternalField();
134
135 #ifdef FULLDEBUG
137 << "No value defined for "
138 << this->internalField().name() << " on "
139 << this->patch().name() << " - using patch internal field" << endl;
140 #endif
141 }
142
143 if (this->evalOnConstruct_)
144 {
145 // For potentialFoam or other solvers that don't evaluate
146 this->evaluate();
147 }
148}
149
150
151template<class Type>
153(
155)
156:
157 parent_bctype(rhs),
158 expressions::patchExprFieldBase(rhs),
159 dict_(rhs.dict_), // Deep copy
160 driver_(this->patch(), rhs.driver_, dict_)
161{
162 setDebug();
164}
165
166
167template<class Type>
169(
172)
173:
174 parent_bctype(rhs, iF),
175 expressions::patchExprFieldBase(rhs),
176 dict_(rhs.dict_), // Deep copy
177 driver_(this->patch(), rhs.driver_, dict_)
178{
179 setDebug();
181}
182
183
184// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
185
186template<class Type>
188{
189 if (this->updated())
190 {
191 return;
192 }
193
194 if (debug)
195 {
197 << "Value: " << this->valueExpr_ << nl
198 << "Variables: ";
199 driver_.writeVariableStrings(Info) << nl;
200 Info<< "... updating" << endl;
201 }
202
203
204 // Expression evaluation
205 {
206 bool evalValue = (!this->valueExpr_.empty() && this->valueExpr_ != "0");
207
208
209 driver_.clearVariables();
210
211 if (evalValue)
212 {
213 (*this) == driver_.evaluate<Type>(this->valueExpr_);
214 }
215 else
216 {
217 (*this) == Zero;
218 }
219 }
220
221 this->parent_bctype::updateCoeffs();
222}
223
224
225template<class Type>
227{
228 this->parent_bctype::write(os);
230
231 driver_.writeCommon(os, this->debug_ || debug);
232}
233
234
235// ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
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:126
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionaryI.H:87
A fixed value boundary condition with expressions.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
void setDebug()
Set debug ON if "debug" is enabled.
expectedTypes
Enumeration of expected expressions.
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
virtual bool write()
Write the output fields.
A FieldMapper for finite-volume patch fields.
friend Ostream & operator(Ostream &, const fvPatchField< Type > &)
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:473
OBJstream os(runTime.globalPath()/outputName)
#define WarningInFunction
Report a warning using Foam::Warning.
#define DebugInFunction
Report an information message using Foam::Info.
#define InfoInFunction
Report an information message using Foam::Info.
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.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
IOerror FatalIOError
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict