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 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),
45  valueExpr_(),
46  driver_(fvPatch::lookupPatch(this->patch()), dict_)
47 {
48  if (dict.getOrDefault("debug", false))
49  {
50  debug |= 1;
51  }
52 
53  string expr;
54  dict.readEntry("expression", expr);
55  valueExpr_ = expressions::exprString(expr, dict);
56 
57  // Basic sanity
58  if (valueExpr_.empty())
59  {
61  << "The expression was not defined!" << nl
62  << exit(FatalIOError);
63  }
64 
65  driver_.readDict(dict_);
66 }
67 
68 
69 template<class Type>
71 (
72  const PatchExprField<Type>& rhs
73 )
74 :
75  PatchExprField<Type>(rhs, rhs.patch())
76 {}
77 
78 
79 template<class Type>
81 (
82  const PatchExprField<Type>& rhs,
83  const polyPatch& pp
84 )
85 :
86  PatchFunction1<Type>(rhs, pp),
87  dict_(rhs.dict_),
88  valueExpr_(rhs.valueExpr_),
89  driver_(fvPatch::lookupPatch(this->patch()), rhs.driver_)
90 {}
91 
92 
93 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
94 
95 template<class Type>
98 (
99  const scalar x
100 ) const
101 {
102  // Expression evaluation
103  driver_.clearVariables();
104 
105  driver_.setArgument(x);
106 
107  tmp<Field<Type>> tresult(driver_.evaluate<Type>(this->valueExpr_));
108 
109  DebugInfo
110  << "Evaluated: " << tresult() << nl;
111 
112  return tresult;
113 }
114 
115 
116 template<class Type>
119 (
120  const scalar x1,
121  const scalar x2
122 ) const
123 {
125  return nullptr;
126 }
127 
128 
129 template<class Type>
131 (
132  const FieldMapper& mapper
133 )
134 {
136 }
137 
138 
139 template<class Type>
141 (
142  const PatchFunction1<Type>& pf1,
143  const labelList& addr
144 )
145 {
146  PatchFunction1<Type>::rmap(pf1, addr);
147 }
148 
149 
150 template<class Type>
152 (
153  Ostream& os
154 ) const
155 {
156  // PatchFunction1-from-subdict so output dictionary contains
157  // only the relevant entries.
158  dict_.writeEntry(this->name(), os);
159 }
160 
161 
162 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::PatchFunction1Types::PatchExprField::integrate
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: PatchFunction1Expression.C:119
Foam::PatchFunction1Types::PatchExprField::value
virtual tmp< Field< Type > > value(const scalar x) const
Return value.
Definition: PatchFunction1Expression.C:98
Foam::FieldMapper
Abstract base class to hold the Field mapping addressing and weights.
Definition: FieldMapper.H:49
Foam::FatalIOError
IOerror FatalIOError
PatchFunction1Expression.H
Foam::PatchFunction1Types::PatchExprField::rmap
virtual void rmap(const PatchFunction1< Type > &pf1, const labelList &addr)
Reverse map the given PatchFunction1 onto this PatchFunction1.
Definition: PatchFunction1Expression.C:141
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:445
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::PatchFunction1Types::PatchExprField::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: PatchFunction1Expression.C:152
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::PatchFunction1Types::PatchExprField::PatchExprField
PatchExprField(const polyPatch &pp, const word &redirectType, const word &entryName, const dictionary &dict, const bool faceValues=true)
Construct from patch, entry name and dictionary.
Definition: PatchFunction1Expression.C:35
Foam::PatchFunction1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: PatchFunction1.H:59
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::PatchFunction1Types::PatchExprField::autoMap
virtual void autoMap(const FieldMapper &mapper)
Map (and resize as needed) from self given a mapping object.
Definition: PatchFunction1Expression.C:131
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:359
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::PatchFunction1Types::PatchExprField
PatchFunction1 with values supplied by a parsed expression.
Definition: PatchFunction1Expression.H:83
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::List< label >
Foam::expressions::exprString
Definition: exprString.H:60
x
x
Definition: LISASMDCalcMethod2.H:52
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401
fvPatch.H
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56