exprValuePointPatchField.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) 2010-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 "pointPatchFieldMapper.H"
31 #include "facePointPatch.H"
32 #include "dictionaryContent.H"
33 
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 
36 template<class Type>
38 (
39  const pointPatch& p,
41 )
42 :
43  parent_bctype(p, iF),
45  dict_(),
46  driver_
47  (
48  fvPatch::lookupPatch
49  (
50  dynamicCast<const facePointPatch>(this->patch()).patch()
51  )
52  )
53 {}
54 
55 
56 template<class Type>
58 (
60  const pointPatch& p,
62  const pointPatchFieldMapper& mapper
63 )
64 :
65  parent_bctype(rhs, p, iF, mapper),
67  dict_(rhs.dict_), // Deep copy
68  driver_
69  (
70  fvPatch::lookupPatch
71  (
72  dynamicCast<const facePointPatch>(this->patch()).patch()
73  ),
74  rhs.driver_,
75  dict_
76  )
77 {}
78 
79 
80 template<class Type>
82 (
83  const pointPatch& p,
85  const dictionary& dict
86 )
87 :
88  parent_bctype(p, iF),
90  (
91  dict,
92  expressions::patchExprFieldBase::expectedTypes::VALUE_TYPE,
93  true // pointValue
94  ),
95  dict_
96  (
97  // Copy dictionary without "heavy" data chunks
98  dictionaryContent::copyDict
99  (
100  dict,
101  wordList(), // allow
102  wordList // deny
103  ({
104  "type", // redundant
105  "value"
106  })
107  )
108  ),
109  driver_
110  (
111  fvPatch::lookupPatch
112  (
113  dynamicCast<const facePointPatch>(this->patch()).patch()
114  ),
115  dict_
116  )
117 {
118  // Require valueExpr
119  if (this->valueExpr_.empty())
120  {
122  << "The valueExpr was not defined!" << nl
123  << exit(FatalIOError);
124  }
125 
126 
127  driver_.readDict(dict_);
128 
129  if (dict.found("value"))
130  {
131  Field<Type>::operator=
132  (
133  Field<Type>("value", dict, p.size())
134  );
135  }
136  else
137  {
139  << "No value defined for "
140  << this->internalField().name()
141  << " on " << this->patch().name()
142  << endl;
143  }
144 
145  if (this->evalOnConstruct_)
146  {
147  // For potentialFoam or other solvers that don't evaluate
148  this->evaluate();
149  }
150 }
151 
152 
153 template<class Type>
155 (
158 )
159 :
160  parent_bctype(rhs, iF),
162  dict_(rhs.dict_), // Deep copy
163  driver_
164  (
165  fvPatch::lookupPatch
166  (
167  dynamicCast<const facePointPatch>(this->patch()).patch()
168  ),
169  rhs.driver_,
170  dict_
171  )
172 {}
173 
174 
175 template<class Type>
177 (
179 )
180 :
181  parent_bctype(rhs),
183  dict_(rhs.dict_), // Deep copy
184  driver_
185  (
186  fvPatch::lookupPatch
187  (
188  dynamicCast<const facePointPatch>(this->patch()).patch()
189  ),
190  rhs.driver_,
191  dict_
192  )
193 {}
194 
195 
196 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
197 
198 template<class Type>
200 {
201  if (this->updated())
202  {
203  return;
204  }
205 
206  if (debug)
207  {
209  << "Value: " << this->valueExpr_ << nl
210  << "Variables: ";
211  driver_.writeVariableStrings(Info) << nl;
212  Info<< "... updating" << endl;
213  }
214 
215 
216  // Expression evaluation
217  {
218  bool evalValue = (!this->valueExpr_.empty() && this->valueExpr_ != "0");
219 
220 
221  driver_.clearVariables();
222 
223  if (evalValue)
224  {
226  (
227  driver_.evaluate<Type>(this->valueExpr_, true)
228  );
229  }
230  else
231  {
232  (*this) == Zero;
233  }
234  }
235 
236  this->parent_bctype::updateCoeffs();
237 }
238 
239 
240 template<class Type>
242 {
243  this->parent_bctype::write(os);
245 
246  this->writeEntry("value", os);
247 
248  driver_.writeCommon(os, this->debug_ || debug);
249 }
250 
251 
252 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::exprValuePointPatchField::dict_
dictionary dict_
Dictionary contents for the boundary condition.
Definition: exprValuePointPatchField.H:89
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
pointPatchFieldMapper.H
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::pointPatch
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:58
Foam::pointPatchFieldMapper
Foam::pointPatchFieldMapper.
Definition: pointPatchFieldMapper.H:48
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
Foam::expressions::patchExprFieldBase
Base class for managing patches with expressions. The expected input supports value,...
Definition: patchExprFieldBase.H:83
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::exprValuePointPatchField::write
virtual void write(Ostream &os) const
Write.
Definition: exprValuePointPatchField.C:241
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:123
Foam::exprValuePointPatchField::driver_
expressions::patchExpr::parseDriver driver_
The expression driver.
Definition: exprValuePointPatchField.H:92
os
OBJstream os(runTime.globalPath()/outputName)
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::exprValuePointPatchField::exprValuePointPatchField
exprValuePointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
Definition: exprValuePointPatchField.C:38
dictionaryContent.H
Foam::valuePointPatchField
Foam::valuePointPatchField.
Definition: valuePointPatchField.H:52
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
facePointPatch.H
Foam::List< word >
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::exprValuePointPatchField::updateCoeffs
virtual void updateCoeffs()
Update the patch field.
Definition: exprValuePointPatchField.C:199
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
exprValuePointPatchField.H
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::exprValuePointPatchField
A fixed value point boundary condition with expressions.
Definition: exprValuePointPatchField.H:75
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