PatchFunction1Expression.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) 2020-2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
29 #include "fvPatch.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class Type>
35 (
36  const polyPatch& pp,
37  const word& redirectType,
38  const word& entryName,
39  const dictionary& dict,
40  const bool faceValues
41 )
42 :
43  PatchFunction1<Type>(pp, entryName, dict, faceValues),
44  dict_(dict), // Deep copy
45  valueExpr_("expression", dict_),
46  driver_(fvPatch::lookupPatch(this->patch()), dict_)
47 {
48  if (dict.getOrDefault("debug", false))
49  {
50  debug |= 1;
51  }
52 
53  // Basic sanity
54  if (valueExpr_.empty())
55  {
57  << "The expression was not defined!" << nl
58  << exit(FatalIOError);
59  }
60 
61  driver_.readDict(dict_);
62 }
63 
64 
65 template<class Type>
67 (
68  const PatchExprField<Type>& rhs
69 )
70 :
71  PatchExprField<Type>(rhs, rhs.patch())
72 {}
73 
74 
75 template<class Type>
77 (
78  const PatchExprField<Type>& rhs,
79  const polyPatch& pp
80 )
81 :
82  PatchFunction1<Type>(rhs, pp),
83  dict_(rhs.dict_), // Deep copy
84  valueExpr_(rhs.valueExpr_),
85  driver_(fvPatch::lookupPatch(this->patch()), rhs.driver_, dict_)
86 {}
87 
88 
89 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
90 
91 template<class Type>
94 (
95  const scalar x
96 ) const
97 {
98  // Expression evaluation
99  driver_.clearVariables();
100 
101  driver_.setArgument(x);
102 
103  tmp<Field<Type>> tresult(driver_.evaluate<Type>(this->valueExpr_));
104 
105  DebugInfo
106  << "Evaluated: " << tresult() << nl;
107 
108  return tresult;
109 }
110 
111 
112 template<class Type>
115 (
116  const scalar x1,
117  const scalar x2
118 ) const
119 {
121  return nullptr;
122 }
123 
124 
125 template<class Type>
127 (
128  const FieldMapper& mapper
129 )
130 {
132 }
133 
134 
135 template<class Type>
137 (
138  const PatchFunction1<Type>& pf1,
139  const labelList& addr
140 )
141 {
142  PatchFunction1<Type>::rmap(pf1, addr);
143 }
144 
145 
146 template<class Type>
148 (
149  Ostream& os
150 ) const
151 {
152  // PatchFunction1-from-subdict so output dictionary contains
153  // only the relevant entries.
154  dict_.writeEntry(this->name(), os);
155 }
156 
157 
158 // ************************************************************************* //
PatchFunction1 with values supplied by a parsed expression.
dictionary dict
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
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two values.
const polyPatch const word const word const dictionary & dict
virtual void rmap(const PatchFunction1< Type > &pf1, const labelList &addr)
Reverse map the given PatchFunction1 onto this PatchFunction1.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
Abstract base class to hold the Field mapping addressing and weights.
Definition: FieldMapper.H:43
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual void writeData(Ostream &os) const
Write in dictionary format.
virtual tmp< Field< Type > > value(const scalar x) const
Return value.
virtual void autoMap(const FieldMapper &mapper)
Map (and resize as needed) from self given a mapping object.
#define DebugInfo
Report an information message using Foam::Info.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
int debug
Static debugging option.
OBJstream os(runTime.globalPath()/outputName)
virtual void autoMap(const FieldMapper &mapper)
Map (and resize as needed) from self given a mapping object.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
virtual bool readDict(const dictionary &dict)
Read variables, tables etc.
Definition: fvExprDriver.C:146
const std::string patch
OpenFOAM patch number as a std::string.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:686
virtual void rmap(const PatchFunction1< Type > &rhs, const labelList &addr)
Reverse map the given PatchFunction1 onto this PatchFunction1.
PatchExprField(const polyPatch &pp, const word &redirectType, const word &entryName, const dictionary &dict, const bool faceValues=true)
Construct from patch, entry name and dictionary.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...