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-------------------------------------------------------------------------------
11License
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
31#include "facePointPatch.H"
32#include "dictionaryContent.H"
33
34// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35
36template<class Type>
38(
39 const pointPatch& p,
41)
42:
43 parent_bctype(p, iF),
44 expressions::patchExprFieldBase(),
45 dict_(),
46 driver_
47 (
48 fvPatch::lookupPatch
49 (
50 dynamicCast<const facePointPatch>(this->patch()).patch()
51 )
52 )
53{}
54
55
56template<class Type>
58(
60 const pointPatch& p,
62 const pointPatchFieldMapper& mapper
63)
64:
65 parent_bctype(rhs, p, iF, mapper),
66 expressions::patchExprFieldBase(rhs),
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
80template<class Type>
82(
83 const pointPatch& p,
85 const dictionary& dict
86)
87:
88 parent_bctype(p, iF),
89 expressions::patchExprFieldBase
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 (
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 {
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
153template<class Type>
155(
158)
159:
160 parent_bctype(rhs, iF),
161 expressions::patchExprFieldBase(rhs),
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
175template<class Type>
177(
179)
180:
181 parent_bctype(rhs),
182 expressions::patchExprFieldBase(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
198template<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
240template<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// ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Generic templated field type.
Definition: Field.H:82
friend Ostream & operator(Ostream &, const Field< Type > &)
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A wrapper for dictionary content, without operators that could affect inheritance patterns.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionaryI.H:87
A fixed value point boundary condition with expressions.
virtual void updateCoeffs()
Update the patch field.
expectedTypes
Enumeration of expected expressions.
A pointPatch based on a polyPatch.
virtual bool write()
Write the output fields.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:71
static const fvPatch & lookupPatch(const polyPatch &p)
Lookup the polyPatch index on corresponding fvMesh.
Definition: fvPatch.C:49
Foam::pointPatchFieldMapper.
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:64
Foam::valuePointPatchField.
volScalarField & p
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
OBJstream os(runTime.globalPath()/outputName)
#define WarningInFunction
Report a warning using Foam::Warning.
#define InfoInFunction
Report an information message using Foam::Info.
const std::string patch
OpenFOAM patch number as a std::string.
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.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
IOerror FatalIOError
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
To & dynamicCast(From &r)
Definition: typeInfo.H:88
dictionary dict