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),
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),
71  dict_(rhs.dict_), // Deep copy
72  driver_(this->patch(), rhs.driver_, dict_)
73 {
74  setDebug();
76 }
77 
78 
79 template<class Type>
81 (
82  const fvPatch& p,
84  const dictionary& dict,
85  const bool valueRequired
86 )
87 :
88  parent_bctype(p, iF),
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();
111  DebugInFunction << nl;
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  {
126  fvPatchField<Type>::operator=
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 
151 template<class Type>
153 (
155 )
156 :
157  parent_bctype(rhs),
159  dict_(rhs.dict_), // Deep copy
160  driver_(this->patch(), rhs.driver_, dict_)
161 {
162  setDebug();
163  DebugInFunction << nl;
164 }
165 
166 
167 template<class Type>
169 (
172 )
173 :
174  parent_bctype(rhs, iF),
176  dict_(rhs.dict_), // Deep copy
177  driver_(this->patch(), rhs.driver_, dict_)
178 {
179  setDebug();
180  DebugInFunction << nl;
181 }
182 
183 
184 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
185 
186 template<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 
225 template<class Type>
227 {
228  this->parent_bctype::write(os);
230 
231  driver_.writeCommon(os, this->debug_ || debug);
232 }
233 
234 
235 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
InfoInFunction
#define InfoInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:350
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:369
Foam::exprFixedValueFvPatchField::exprFixedValueFvPatchField
exprFixedValueFvPatchField(const fvPatch &p, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
Definition: exprFixedValueFvPatchField.C:48
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::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
Foam::exprFixedValueFvPatchField::write
virtual void write(Ostream &os) const
Write.
Definition: exprFixedValueFvPatchField.C:226
Foam::expressions::patchExprFieldBase
Base class for managing patches with expressions. The expected input supports value,...
Definition: patchExprFieldBase.H:83
exprFixedValueFvPatchField.H
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:388
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:187
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::exprFixedValueFvPatchField::driver_
expressions::patchExpr::parseDriver driver_
The expression driver.
Definition: exprFixedValueFvPatchField.H:96
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
dictionaryContent.H
Foam::exprFixedValueFvPatchField
A fixed value boundary condition with expressions.
Definition: exprFixedValueFvPatchField.H:79
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::List< word >
Foam::exprFixedValueFvPatchField::dict_
dictionary dict_
Dictionary contents for the boundary condition.
Definition: exprFixedValueFvPatchField.H:93
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:36
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
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:35
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54
Foam::stringOps::evaluate
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.
Definition: stringOpsEvaluate.C:37