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  const bool valueRequired
86 )
87 :
88  parent_bctype(p, iF),
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 {
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  {
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 (
154  const exprFixedValueFvPatchField<Type>& rhs
155 )
156 :
157  parent_bctype(rhs),
158  expressions::patchExprFieldBase(rhs),
159  dict_(rhs.dict_), // Deep copy
160  driver_(this->patch(), rhs.driver_, dict_)
161 {
163  DebugInFunction << nl;
164 }
165 
166 
167 template<class Type>
169 (
172 )
173 :
174  parent_bctype(rhs, iF),
175  expressions::patchExprFieldBase(rhs),
176  dict_(rhs.dict_), // Deep copy
177  driver_(this->patch(), rhs.driver_, dict_)
178 {
179  setDebug();
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
InfoInFunction
#define InfoInFunction
Definition: messageStream.H:387
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::Zero
static constexpr const zero Zero
Definition: zero.H:131
Foam::dictionary::found
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryI.H:80
Foam::fvPatchField< Type >::operator
friend Ostream & operator(Ostream &, const fvPatchField< Type > &)
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Definition: Ostream.H:381
Foam::exprFixedValueFvPatchField::exprFixedValueFvPatchField
exprFixedValueFvPatchField(const fvPatch &p, const DimensionedField< Type, volMesh > &)
Definition: exprFixedValueFvPatchField.C:41
Foam::dictionaryContent
A wrapper for dictionary content, without operators that could affect inheritance patterns.
Definition: dictionaryContent.H:43
Foam::fixedValueFvPatchField
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
Definition: fixedValueFvPatchField.H:76
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:58
Foam::exprFixedValueFvPatchField::write
virtual void write(Ostream &os) const
Definition: exprFixedValueFvPatchField.C:219
Foam::expressions::patchExprFieldBase
Base class for managing patches with expressions. The expected input supports value,...
Definition: patchExprFieldBase.H:79
exprFixedValueFvPatchField.H
Foam::Info
messageStream Info
DebugInFunction
#define DebugInFunction
Definition: messageStream.H:445
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:61
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::exprFixedValueFvPatchField::updateCoeffs
virtual void updateCoeffs()
Definition: exprFixedValueFvPatchField.C:180
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:119
os
OBJstream os(runTime.globalPath()/outputName)
Foam::exprFixedValueFvPatchField::driver_
expressions::patchExpr::parseDriver driver_
Definition: exprFixedValueFvPatchField.H:92
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
dictionaryContent.H
Foam::expressions::patchExprFieldBase::write
void write(Ostream &os) const
Definition: patchExprFieldBase.C:163
Foam::exprFixedValueFvPatchField
A fixed value boundary condition with expressions.
Definition: exprFixedValueFvPatchField.H:75
Foam::nl
constexpr char nl
Definition: Ostream.H:424
Foam::foamVersion::patch
const std::string patch
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:58
Foam::exprFixedValueFvPatchField::dict_
dictionary dict_
Definition: exprFixedValueFvPatchField.H:89
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Definition: foamVtkOutputTemplates.C:29
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Definition: error.H:494
Foam::fvPatchFieldMapper
Foam::fvPatchFieldMapper.
Definition: fvPatchFieldMapper.H:41
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:52
Foam::exprFixedValueFvPatchField::setDebug
void setDebug()
Definition: exprFixedValueFvPatchField.C:28
WarningInFunction
#define WarningInFunction
Definition: messageStream.H:353
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:50
Foam::stringOps::evaluate
string evaluate(label fieldWidth, const std::string &s, size_t pos=0, size_t len=std::string::npos)
Definition: stringOpsEvaluate.C:30