exprMixedFvPatchField.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  Original code Copyright (C) 2009-2018 Bernhard Gschaider
9  Copyright (C) 2019 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 #include "exprMixedFvPatchField.H"
29 
30 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
31 
32 template<class Type>
34 {
35  if (expressions::patchExprFieldBase::debug_ && !debug)
36  {
37  debug = 1;
38  }
39 }
40 
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
44 template<class Type>
46 (
47  const fvPatch& p,
49 )
50 :
52  expressions::patchExprFieldBase(true), // allowGradient
53  driver_(this->patch())
54 {
55  this->refValue() = Zero;
56  this->refGrad() = Zero;
57  this->valueFraction() = scalar(1);
58 }
59 
60 
61 template<class Type>
63 (
64  const exprMixedFvPatchField<Type>& ptf,
65  const fvPatch& p,
67  const fvPatchFieldMapper& mapper
68 )
69 :
70  mixedFvPatchField<Type>(ptf, p, iF, mapper),
72  driver_(this->patch(), ptf.driver_)
73 {
74  setDebug();
76 }
77 
78 
79 template<class Type>
81 (
82  const fvPatch& p,
84  const dictionary& dict
85 )
86 :
89  driver_(this->patch(), dict)
90 {
91  setDebug();
93 
94  // Basic sanity checks
95  if (this->valueExpr_.empty() && this->gradExpr_.empty())
96  {
97  if (this->valueExpr_.empty())
98  {
100  << "The valueExpr was not defined!" << nl
101  << exit(FatalIOError);
102  }
103  if (this->gradExpr_.empty())
104  {
106  << "The gradientExpr was not defined!" << nl
107  << exit(FatalIOError);
108  }
109  }
110 
111 
112  driver_.readDict(dict);
113 
114  // Similar to fvPatchField constructor, which we have bypassed
115  dict.readIfPresent("patchType", this->patchType());
116 
117  if (dict.found("refValue"))
118  {
119  this->refValue() = Field<Type>("refValue", dict, p.size());
120  }
121  else
122  {
123  this->refValue() = this->patchInternalField();
124  }
125 
126  if (dict.found("value"))
127  {
129  (
130  Field<Type>("value", dict, p.size())
131  );
132 
133  if (!dict.found("refValue"))
134  {
135  // Ensure refValue has a sensible value for the "update" below
136  this->refValue() = Field<Type>("value", dict, p.size());
137  }
138  }
139  else
140  {
141  fvPatchField<Type>::operator=(this->refValue());
142 
144  << "No value defined for "
145  << this->internalField().name()
146  << " on " << this->patch().name() << " therefore using "
147  << "the internal field next to the patch"
148  << endl;
149  }
150 
151 
152  if (dict.found("refGradient"))
153  {
154  this->refGrad() = Field<Type>("refGradient", dict, p.size());
155  }
156  else
157  {
158  this->refGrad() = Zero;
159  }
160 
161  if (dict.found("valueFraction"))
162  {
163  this->valueFraction() = Field<scalar>("valueFraction", dict, p.size());
164  }
165  else
166  {
167  this->valueFraction() = 1;
168  }
169 
170 
171  if (this->evalOnConstruct_)
172  {
173  // For potentialFoam or other solvers that don't evaluate
174  this->evaluate();
175  }
176  else
177  {
178  // Emulate mixedFvPatchField<Type>::evaluate,
179  // but avoid our own updateCoeffs
180  if (!this->updated())
181  {
183  }
184 
186  (
187  this->valueFraction()*this->refValue()
188  +
189  (1.0 - this->valueFraction())*
190  (
191  this->patchInternalField()
192  + this->refGrad()/this->patch().deltaCoeffs()
193  )
194  );
195 
197  }
198 }
199 
200 
201 template<class Type>
203 (
204  const exprMixedFvPatchField<Type>& ptf
205 )
206 :
209  driver_(this->patch(), ptf.driver_)
210 {
211  setDebug();
212  DebugInFunction << nl;
213 }
214 
215 
216 template<class Type>
218 (
219  const exprMixedFvPatchField<Type>& ptf,
221 )
222 :
223  mixedFvPatchField<Type>(ptf, iF),
225  driver_(this->patch(), ptf.driver_)
226 {
227  setDebug();
228  DebugInFunction << nl;
229 }
230 
231 
232 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
233 
234 template<class Type>
236 {
237  if (debug)
238  {
240  << "Value: " << this->valueExpr_ << nl
241  << "Gradient: " << this->gradExpr_ << nl
242  << "Fraction: " << this->fracExpr_ << nl
243  << "Variables: ";
244 
245  driver_.writeVariableStrings(Info) << endl;
246  }
247 
248  if (this->updated())
249  {
250  return;
251  }
252 
253  DebugInFunction << " - updating" << nl;
254 
255 
256  // Expression evaluation
257  {
258  driver_.clearVariables();
259 
260  if (this->valueExpr_.empty())
261  {
262  this->refValue() = Zero;
263  }
264  else
265  {
266  this->refValue() = driver_.evaluate<Type>(this->valueExpr_);
267  }
268 
269  bool evalGrad = !this->gradExpr_.empty();
270 
271  if (this->fracExpr_.empty() || this->fracExpr_ == "1")
272  {
273  evalGrad = false;
274  this->valueFraction() = scalar(1);
275  }
276  else if (this->fracExpr_ == "0")
277  {
278  this->valueFraction() = Zero;
279  }
280  else
281  {
282  this->valueFraction() = driver_.evaluate<scalar>(this->fracExpr_);
283  }
284 
285  if (evalGrad)
286  {
287  this->refGrad() = driver_.evaluate<Type>(this->gradExpr_);
288  }
289  else
290  {
291  this->refGrad() = Zero;
292  }
293  }
294 
296 }
297 
298 
299 template<class Type>
301 {
304 
305  driver_.writeCommon(os, this->debug_ || debug);
306 }
307 
308 
309 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:50
InfoInFunction
#define InfoInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:316
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::exprMixedFvPatchField::write
virtual void write(Ostream &os) const
Write.
Definition: exprMixedFvPatchField.C:300
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::dictionary::found
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionary.C:359
Foam::exprMixedFvPatchField::exprMixedFvPatchField
exprMixedFvPatchField(const fvPatch &p, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
Definition: exprMixedFvPatchField.C:46
exprMixedFvPatchField.H
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::exprMixedFvPatchField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: exprMixedFvPatchField.C:235
Foam::exprMixedFvPatchField::driver_
expressions::patchExpr::parseDriver driver_
The expression driver.
Definition: exprMixedFvPatchField.H:92
Foam::expressions::patchExprFieldBase
Base class for managing patches with expressions. The expected input supports values,...
Definition: patchExprFieldBase.H:88
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:356
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:63
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::mixedFvPatchField
This boundary condition provides a base class for 'mixed' type boundary conditions,...
Definition: mixedFvPatchField.H:123
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::exprMixedFvPatchField::setDebug
void setDebug()
Set debug ON if "debug" is enabled.
Definition: exprMixedFvPatchField.C:33
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:35
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:375
Foam::fvPatchFieldMapper
Foam::fvPatchFieldMapper.
Definition: fvPatchFieldMapper.H:47
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::exprMixedFvPatchField
A mixed boundary condition with expressions.
Definition: exprMixedFvPatchField.H:82
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294
Foam::stringOps::evaluate
string evaluate(const std::string &s, size_t pos=0, size_t len=std::string::npos)
Definition: stringOpsEvaluate.C:37
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54