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-2020 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 
31 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
32 
33 template<class Type>
35 {
36  if (expressions::patchExprFieldBase::debug_ && !debug)
37  {
38  debug = 1;
39  }
40 }
41 
42 
43 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44 
45 template<class Type>
47 (
48  const fvPatch& p,
50 )
51 :
54  driver_(this->patch())
55 {}
56 
57 
58 template<class Type>
60 (
62  const fvPatch& p,
64  const fvPatchFieldMapper& mapper
65 )
66 :
67  fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
69  driver_(this->patch(), ptf.driver_)
70 {
71  setDebug();
73 }
74 
75 
76 template<class Type>
78 (
79  const fvPatch& p,
81  const dictionary& dict,
82  const bool valueRequired
83 )
84 :
87  (
88  dict,
89  expressions::patchExprFieldBase::expectedTypes::VALUE_TYPE
90  ),
91  driver_(this->patch(), dict)
92 {
93  setDebug();
95 
96  // Require valueExpr
97  if (this->valueExpr_.empty())
98  {
100  << "The valueExpr was not defined!" << nl
101  << exit(FatalIOError);
102  }
103 
104 
105  driver_.readDict(dict);
106 
107  if (dict.found("value"))
108  {
110  (
111  Field<Type>("value", dict, p.size())
112  );
113  }
114  else
115  {
116  (*this) == this->patchInternalField();
117 
118  #ifdef FULLDEBUG
120  << "No value defined for "
121  << this->internalField().name() << " on "
122  << this->patch().name() << " - using patch internal field" << endl;
123  #endif
124  }
125 
126  if (this->evalOnConstruct_)
127  {
128  // For potentialFoam or other solvers that don't evaluate
129  this->evaluate();
130  }
131 }
132 
133 
134 template<class Type>
136 (
138 )
139 :
142  driver_(this->patch(), ptf.driver_)
143 {
144  setDebug();
145  DebugInFunction << nl;
146 }
147 
148 
149 template<class Type>
151 (
154 )
155 :
158  driver_(this->patch(), ptf.driver_)
159 {
160  setDebug();
161  DebugInFunction << nl;
162 }
163 
164 
165 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
166 
167 template<class Type>
169 {
170  if (this->updated())
171  {
172  return;
173  }
174 
175  if (debug)
176  {
178  << "Value: " << this->valueExpr_ << nl
179  << "Variables: ";
180  driver_.writeVariableStrings(Info) << nl;
181  Info<< "... updating" << endl;
182  }
183 
184 
185  // Expression evaluation
186  {
187  bool evalValue = (!this->valueExpr_.empty() && this->valueExpr_ != "0");
188 
189 
190  driver_.clearVariables();
191 
192  if (evalValue)
193  {
194  (*this) == driver_.evaluate<Type>(this->valueExpr_);
195  }
196  else
197  {
198  (*this) == Zero;
199  }
200  }
201 
203 }
204 
205 
206 template<class Type>
208 {
211 
212  driver_.writeCommon(os, this->debug_ || debug);
213 }
214 
215 
216 // ************************************************************************* //
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:325
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::exprFixedValueFvPatchField::exprFixedValueFvPatchField
exprFixedValueFvPatchField(const fvPatch &p, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
Definition: exprFixedValueFvPatchField.C:47
Foam::fixedValueFvPatchField
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
Definition: fixedValueFvPatchField.H:80
Foam::exprFixedValueFvPatchField::write
virtual void write(Ostream &os) const
Write.
Definition: exprFixedValueFvPatchField.C:207
Foam::expressions::patchExprFieldBase
Base class for managing patches with expressions. The expected input supports value,...
Definition: patchExprFieldBase.H:83
exprFixedValueFvPatchField.H
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:365
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::exprFixedValueFvPatchField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: exprFixedValueFvPatchField.C:168
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::exprFixedValueFvPatchField::driver_
expressions::patchExpr::parseDriver driver_
The expression driver.
Definition: exprFixedValueFvPatchField.H:89
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::exprFixedValueFvPatchField
A fixed value boundary condition with expressions.
Definition: exprFixedValueFvPatchField.H:79
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
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:401
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::exprFixedValueFvPatchField::setDebug
void setDebug()
Set debug ON if "debug" is enabled.
Definition: exprFixedValueFvPatchField.C:34
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:303
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