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  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 
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  driver_(this->patch(), dict)
88 {
89  setDebug();
91 
92  // Basic sanity
93  if (this->valueExpr_.empty())
94  {
96  << "The valueExpr was not defined!" << nl
97  << exit(FatalIOError);
98  }
99 
100  driver_.readDict(dict);
101 
102  if (dict.found("value"))
103  {
105  (
106  Field<Type>("value", dict, p.size())
107  );
108  }
109  else
110  {
111  (*this) == this->patchInternalField();
112 
114  << "No value defined for "
115  << this->internalField().name() << " on "
116  << this->patch().name() << " - setting to internalField value "
117  << nl;
118  }
119 
120  if (this->evalOnConstruct_)
121  {
122  // For potentialFoam or other solvers that don't evaluate
123  this->evaluate();
124  }
125 }
126 
127 
128 template<class Type>
130 (
132 )
133 :
136  driver_(this->patch(), ptf.driver_)
137 {
138  setDebug();
139  DebugInFunction << nl;
140 }
141 
142 
143 template<class Type>
145 (
148 )
149 :
152  driver_(this->patch(), ptf.driver_)
153 {
154  setDebug();
155  DebugInFunction << nl;
156 }
157 
158 
159 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
160 
161 template<class Type>
163 {
164  if (debug)
165  {
167  << "Value: " << this->valueExpr_ << nl
168  << "Variables: ";
169  driver_.writeVariableStrings(Info) << endl;
170  }
171 
172  if (this->updated())
173  {
174  return;
175  }
176 
178  << "updating" << nl;
179 
180  // Expression evaluation
181  {
182  driver_.clearVariables();
183 
184  if (this->valueExpr_.empty())
185  {
186  (*this) == Zero;
187  }
188  else
189  {
190  tmp<Field<Type>> tresult(driver_.evaluate<Type>(this->valueExpr_));
191 
192  if (debug)
193  {
194  Info<< "Evaluated: " << tresult();
195  }
196 
197  (*this) == tresult;
198  }
199  }
200 
202 }
203 
204 
205 template<class Type>
207 {
210 
211  driver_.writeCommon(os, this->debug_ || debug);
212 }
213 
214 
215 // ************************************************************************* //
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::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
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:206
Foam::expressions::patchExprFieldBase
Base class for managing patches with expressions. The expected input supports values,...
Definition: patchExprFieldBase.H:88
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:356
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:63
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::exprFixedValueFvPatchField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: exprFixedValueFvPatchField.C:162
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:86
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:76
Foam::nl
constexpr char nl
Definition: Ostream.H:372
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: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::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: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