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 -------------------------------------------------------------------------------
11 License
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 
34 template<class Type>
36 {
37  if (expressions::patchExprFieldBase::debug_ && !debug)
38  {
39  debug = 1;
40  }
41 }
42 
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
46 template<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 
60 template<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 {
76 }
77 
78 
79 template<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();
115  DebugInFunction << nl;
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 
152 template<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_)
162 {
164  DebugInFunction << nl;
165 }
166 
167 
168 template<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 
187 template<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  }
220  }
221 
222  this->parent_bctype::updateCoeffs();
223 }
224 
225 
226 template<class Type>
228 {
229  this->parent_bctype::write(os);
231 
232  driver_.writeCommon(os, this->debug_ || debug);
233 }
234 
235 
236 // ************************************************************************* //
dictionary dict
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual void write(Ostream &os) const
Write.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
void setDebug()
Set debug ON if "debug" is enabled.
virtual void readDict(const dictionary &dict)
Read dictionary entries.
#define DeprecatedInFunction(afterVersion)
Report a warning using Foam::Warning.
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
#define DebugInFunction
Report an information message using Foam::Info.
A fixed value boundary condition with expressions.
A FieldMapper for finite-volume patch fields.
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.
A wrapper for dictionary content, without operators that could affect inheritance patterns...
int debug
Static debugging option.
OBJstream os(runTime.globalPath()/outputName)
exprFixedValueFvPatchField(const fvPatch &p, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
#define WarningInFunction
Report a warning using Foam::Warning.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
const std::string patch
OpenFOAM patch number as a std::string.
messageStream Info
Information stream (stdout output on master, null elsewhere)
volScalarField & p
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
void write(Ostream &os) const
Write.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...
#define InfoInFunction
Report an information message using Foam::Info.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127
readOption
Enumeration defining read preferences.