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-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 #include "pointPatchFieldMapper.H"
31 #include "typeInfo.H"
32 #include "facePointPatch.H"
33 
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 
36 template<class Type>
38 (
39  const pointPatch& p,
41 )
42 :
45  driver_
46  (
47  fvPatch::lookupPatch
48  (
49  dynamicCast<const facePointPatch>(this->patch()).patch()
50  )
51  )
52 {}
53 
54 
55 template<class Type>
57 (
59  const pointPatch& p,
61  const pointPatchFieldMapper& mapper
62 )
63 :
64  valuePointPatchField<Type>(ptf, p, iF, mapper),
66  driver_
67  (
68  fvPatch::lookupPatch
69  (
70  dynamicCast<const facePointPatch>(this->patch()).patch()
71  ),
72  ptf.driver_
73  )
74 {}
75 
76 
77 template<class Type>
79 (
80  const pointPatch& p,
82  const dictionary& dict
83 )
84 :
87  (
88  dict,
89  expressions::patchExprFieldBase::expectedTypes::VALUE_TYPE,
90  true // pointValue
91  ),
92  driver_
93  (
94  fvPatch::lookupPatch
95  (
96  dynamicCast<const facePointPatch>(this->patch()).patch()
97  ),
98  dict
99  )
100 {
101  // Require valueExpr
102  if (this->valueExpr_.empty())
103  {
105  << "The valueExpr was not defined!" << nl
106  << exit(FatalIOError);
107  }
108 
109 
110  driver_.readDict(dict);
111 
112  if (dict.found("value"))
113  {
115  (
116  Field<Type>("value", dict, p.size())
117  );
118  }
119  else
120  {
122  << "No value defined for "
123  << this->internalField().name()
124  << " on " << this->patch().name()
125  << endl;
126  }
127 
128  if (this->evalOnConstruct_)
129  {
130  // For potentialFoam or other solvers that don't evaluate
131  this->evaluate();
132  }
133 }
134 
135 
136 template<class Type>
138 (
141 )
142 :
145  driver_
146  (
147  fvPatch::lookupPatch
148  (
149  dynamicCast<const facePointPatch>(this->patch()).patch()
150  ),
151  ptf.driver_
152  )
153 {}
154 
155 
156 template<class Type>
158 (
160 )
161 :
164  driver_
165  (
166  fvPatch::lookupPatch
167  (
168  dynamicCast<const facePointPatch>(this->patch()).patch()
169  ),
170  ptf.driver_
171  )
172 {}
173 
174 
175 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
176 
177 template<class Type>
179 {
180  if (this->updated())
181  {
182  return;
183  }
184 
185  if (debug)
186  {
188  << "Value: " << this->valueExpr_ << nl
189  << "Variables: ";
190  driver_.writeVariableStrings(Info) << nl;
191  Info<< "... updating" << endl;
192  }
193 
194 
195  // Expression evaluation
196  {
197  bool evalValue = (!this->valueExpr_.empty() && this->valueExpr_ != "0");
198 
199 
200  driver_.clearVariables();
201 
202  if (evalValue)
203  {
205  (
206  driver_.evaluate<Type>(this->valueExpr_, true)
207  );
208  }
209  else
210  {
211  (*this) == Zero;
212  }
213  }
214 
216 }
217 
218 
219 template<class Type>
221 {
224 
225  this->writeEntry("value", os);
226 
227  driver_.writeCommon(os, this->debug_ || debug);
228 }
229 
230 
231 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
InfoInFunction
#define InfoInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:325
p
volScalarField & p
Definition: createFieldRefs.H:8
typeInfo.H
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:350
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::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 (uses stdout - output is on the master only)
Foam::exprValuePointPatchField::write
virtual void write(Ostream &os) const
Write.
Definition: exprValuePointPatchField.C:220
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:121
Foam::exprValuePointPatchField::driver_
expressions::patchExpr::parseDriver driver_
The expression driver.
Definition: exprValuePointPatchField.H:85
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
Foam::valuePointPatchField
Foam::valuePointPatchField.
Definition: valuePointPatchField.H:52
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
facePointPatch.H
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::exprValuePointPatchField::updateCoeffs
virtual void updateCoeffs()
Update the patch field.
Definition: exprValuePointPatchField.C:178
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:303
exprValuePointPatchField.H
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
Foam::exprValuePointPatchField
A fixed value point boundary condition with expressions.
Definition: exprValuePointPatchField.H:75