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-2022 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),
44  expressions::patchExprFieldBase(),
45  dict_(),
46  driver_
47  (
48  fvPatch::lookupPatch
49  (
50  refCast<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),
66  expressions::patchExprFieldBase(rhs),
67  dict_(rhs.dict_), // Deep copy
68  driver_
69  (
70  fvPatch::lookupPatch
71  (
72  refCast<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), // bypass dictionary constructor
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  refCast<const facePointPatch>(this->patch()).patch()
114  ),
115  dict_
116  )
117 {
118  //FUTURE?
119  //DeprecatedInFunction(2212)
120  // << "Use uniformFixedValue with an expression Function1 instead." << nl
121  // << " This boundary condition will be removed in the future" << endl;
122 
123  // Require valueExpr
124  if (this->valueExpr_.empty())
125  {
127  << "The valueExpr was not defined!" << nl
128  << exit(FatalIOError);
129  }
130 
131  driver_.readDict(dict_);
132 
133  if (!this->readValueEntry(dict))
134  {
135  // Ensure field has reasonable initial values
136  this->extrapolateInternal();
137  }
138 
139  if (this->evalOnConstruct_)
140  {
141  // For potentialFoam or other solvers that don't evaluate
142  this->evaluate();
143  }
144 }
145 
146 
147 template<class Type>
149 (
150  const exprValuePointPatchField<Type>& rhs,
151  const DimensionedField<Type, pointMesh>& iF
152 )
153 :
154  parent_bctype(rhs, iF),
155  expressions::patchExprFieldBase(rhs),
156  dict_(rhs.dict_), // Deep copy
157  driver_
158  (
159  fvPatch::lookupPatch
160  (
161  refCast<const facePointPatch>(this->patch()).patch()
162  ),
163  rhs.driver_,
164  dict_
165  )
166 {}
167 
168 
169 template<class Type>
171 (
173 )
174 :
175  parent_bctype(rhs),
176  expressions::patchExprFieldBase(rhs),
177  dict_(rhs.dict_), // Deep copy
178  driver_
179  (
180  fvPatch::lookupPatch
181  (
182  refCast<const facePointPatch>(this->patch()).patch()
183  ),
184  rhs.driver_,
185  dict_
186  )
187 {}
188 
189 
190 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
191 
192 template<class Type>
194 {
195  if (this->updated())
196  {
197  return;
198  }
199 
200  if (debug)
201  {
203  << "Value: " << this->valueExpr_ << nl
204  << "Variables: ";
205  driver_.writeVariableStrings(Info) << nl;
206  Info<< "... updating" << endl;
207  }
208 
209 
210  // Expression evaluation
211  {
212  bool evalValue = (!this->valueExpr_.empty() && this->valueExpr_ != "0");
213 
214 
215  driver_.clearVariables();
216 
217  if (evalValue)
218  {
220  (
221  driver_.evaluate<Type>(this->valueExpr_, true)
222  );
223  }
224  else
225  {
226  (*this) == Zero;
227  }
228  }
229 
230  this->parent_bctype::updateCoeffs();
231 }
232 
233 
234 template<class Type>
236 {
237  this->parent_bctype::write(os);
239 
240  this->writeValueEntry(os);
241 
242  driver_.writeCommon(os, this->debug_ || debug);
243 }
244 
245 
246 // ************************************************************************* //
virtual void updateCoeffs()
Update the patch field.
dictionary dict
Foam::valuePointPatchField.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
static const fvPatch & lookupPatch(const polyPatch &p)
Lookup the polyPatch index on corresponding fvMesh.
Definition: fvPatch.C:42
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Type & refCast(U &obj)
A dynamic_cast (for references). Generates a FatalError on failed casts and uses the virtual type() m...
Definition: typeInfo.H:159
Foam::pointPatchFieldMapper.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
A fixed value point boundary condition with expressions.
A pointPatch based on a polyPatch.
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
friend Ostream & operator(Ostream &, const Field< Type > &)
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.
exprValuePointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
A wrapper for dictionary content, without operators that could affect inheritance patterns...
virtual void write(Ostream &os) const
Write.
int debug
Static debugging option.
OBJstream os(runTime.globalPath()/outputName)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:61
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
const std::string patch
OpenFOAM patch number as a std::string.
messageStream Info
Information stream (stdout output on master, null elsewhere)
volScalarField & p
void write(Ostream &os) const
Write.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...
#define InfoInFunction
Report an information message using Foam::Info.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127