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  Original code Copyright (C) 2010-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 #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  expressions::patchExprFieldBase::getFvPatch
48  (
49  dynamicCast<const facePointPatch>(this->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  expressions::patchExprFieldBase::getFvPatch
69  (
70  dynamicCast<const facePointPatch>(this->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  driver_
88  (
89  expressions::patchExprFieldBase::getFvPatch
90  (
91  dynamicCast<const facePointPatch>(this->patch())
92  ),
93  dict
94  )
95 {
96  // Basic sanity
97  if (this->valueExpr_.empty())
98  {
100  << "The valueExpr was not defined!" << nl
101  << exit(FatalIOError);
102  }
103 
104  driver_.readDict(dict);
105 
106  if (dict.found("value"))
107  {
109  (
110  Field<Type>("value", dict, p.size())
111  );
112  }
113  else
114  {
116  << "No value defined for "
117  << this->internalField().name()
118  << " on " << this->patch().name()
119  << endl;
120  }
121 
122  if (this->evalOnConstruct_)
123  {
124  // For potentialFoam or other solvers that don't evaluate
125  this->evaluate();
126  }
127 }
128 
129 
130 template<class Type>
132 (
135 )
136 :
139  driver_
140  (
141  expressions::patchExprFieldBase::getFvPatch
142  (
143  dynamicCast<const facePointPatch>(this->patch())
144  ),
145  ptf.driver_
146  )
147 {}
148 
149 
150 template<class Type>
152 (
154 )
155 :
158  driver_
159  (
160  expressions::patchExprFieldBase::getFvPatch
161  (
162  dynamicCast<const facePointPatch>(this->patch())
163  ),
164  ptf.driver_
165  )
166 {}
167 
168 
169 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
170 
171 template<class Type>
173 {
174  if (debug)
175  {
177  << "Value: " << this->valueExpr_ << nl
178  << "Variables: ";
179  driver_.writeVariableStrings(Info) << endl;
180  }
181 
182  if (this->updated())
183  {
184  return;
185  }
186 
187  // Expression evaluation
188  {
189  driver_.clearVariables();
190 
191  if (this->valueExpr_.empty())
192  {
193  (*this) == Zero;
194  }
195  else
196  {
198  (
199  driver_.evaluate<Type>(this->valueExpr_, true)
200  );
201  }
202  }
203 
205 }
206 
207 
208 template<class Type>
210 {
213 
214  this->writeEntry("value",os);
215 
216  driver_.writeCommon(os,this->debug_ || debug);
217 }
218 
219 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
InfoInFunction
#define InfoInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:316
p
volScalarField & p
Definition: createFieldRefs.H:8
typeInfo.H
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
pointPatchFieldMapper.H
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
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 values,...
Definition: patchExprFieldBase.H:88
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:209
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:86
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:51
Foam::nl
constexpr char nl
Definition: Ostream.H:372
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:375
Foam::exprValuePointPatchField::updateCoeffs
virtual void updateCoeffs()
Update the patch field.
Definition: exprValuePointPatchField.C:172
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:294
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:76