patchExprFieldBase.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) 2011-2018 Bernhard Gschaider
9  Copyright (C) 2019-2020 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 
29 #include "patchExprFieldBase.H"
30 #include "facePointPatch.H"
31 #include "fvMesh.H"
32 #include "fvPatch.H"
33 #include "pointMesh.H"
34 
35 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 
38 :
39  patchExprFieldBase(false)
40 {}
41 
42 
44 (
45  bool allowGradient
46 )
47 :
48  debug_(false),
49  allowGradient_(allowGradient),
50  evalOnConstruct_(false),
51  valueExpr_(),
52  gradExpr_(),
53  fracExpr_()
54 {}
55 
56 
58 (
59  const dictionary& dict,
60  bool allowGradient,
61  bool isPointVal
62 )
63 :
64  debug_(dict.getOrDefault("debug", false)),
65  allowGradient_(allowGradient),
66  evalOnConstruct_(dict.getOrDefault("evalOnConstruct", false)),
67  valueExpr_(),
68  gradExpr_(),
69  fracExpr_()
70 {
71  if (debug_)
72  {
73  Info<< "Expression BC with " << dict << nl;
74  }
75 
76  string expr;
77 
78  if (dict.readIfPresent("valueExpr", expr))
79  {
80  valueExpr_ = expressions::exprString(expr, dict);
81  }
82  else
83  {
84  // No value expression - same as Zero
85  if (debug_)
86  {
87  Info<< "No valueExpr" << nl;
88  }
89  }
90 
91  if (allowGradient)
92  {
93  if (dict.readIfPresent("gradientExpr", expr))
94  {
95  gradExpr_ = expressions::exprString(expr, dict);
96  }
97  else
98  {
99  // No gradient expression - same as Zero
100 
101  if (debug_)
102  {
103  Info<< "No gradientExpr" << nl;
104  }
105  }
106 
107  if (dict.readIfPresent("fractionExpr", expr))
108  {
109  if (!expr.empty() && expr != "0")
110  {
111  if (isPointVal)
112  {
113  expr = "toPoint(" + expr + ")";
114  }
115 
116  fracExpr_ = expressions::exprString(expr, dict);
117  }
118  }
119  else
120  {
121  // No fraction expression - same as 1 (one)
122  // Mixed BC may elect to simply ignore gradient expression
123  }
124  }
125 }
126 
127 
129 (
130  const patchExprFieldBase& rhs
131 )
132 :
133  debug_(rhs.debug_),
134  allowGradient_(rhs.allowGradient_),
135  evalOnConstruct_(rhs.evalOnConstruct_),
136  valueExpr_(rhs.valueExpr_),
137  gradExpr_(rhs.gradExpr_),
138  fracExpr_(rhs.fracExpr_)
139 {}
140 
141 
142 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
143 
145 {
146  os.writeEntryIfDifferent<bool>("evalOnConstruct", false, evalOnConstruct_);
147 
148  // Do not emit debug_ value
149 
150  if (!valueExpr_.empty())
151  {
152  os.writeEntry("valueExpr", valueExpr_);
153  }
154  if (!gradExpr_.empty())
155  {
156  os.writeEntry("gradientExpr", gradExpr_);
157  }
158  if (!fracExpr_.empty())
159  {
160  os.writeEntry("fractionExpr", fracExpr_);
161  }
162 }
163 
164 
165 // ************************************************************************* //
Foam::Ostream::writeEntryIfDifferent
Ostream & writeEntryIfDifferent(const word &key, const T &value1, const T &value2)
Write a keyword/value entry only when the two values differ.
Definition: Ostream.H:244
Foam::expressions::patchExprFieldBase::debug_
bool debug_
Definition: patchExprFieldBase.H:95
Foam::expressions::patchExprFieldBase::allowGradient_
bool allowGradient_
Definition: patchExprFieldBase.H:96
Foam::expressions::patchExprFieldBase::gradExpr_
expressions::exprString gradExpr_
Definition: patchExprFieldBase.H:103
patchExprFieldBase.H
Foam::expressions::patchExprFieldBase
Base class for managing patches with expressions. The expected input supports values,...
Definition: patchExprFieldBase.H:89
Foam::expressions::patchExprFieldBase::patchExprFieldBase
patchExprFieldBase()
Default construct.
Definition: patchExprFieldBase.C:37
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
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
fvMesh.H
Foam::expressions::patchExprFieldBase::fracExpr_
expressions::exprString fracExpr_
Definition: patchExprFieldBase.H:104
Foam::expressions::patchExprFieldBase::write
void write(Ostream &os) const
Write.
Definition: patchExprFieldBase.C:144
Foam::nl
constexpr char nl
Definition: Ostream.H:385
facePointPatch.H
Foam::expressions::exprString
Definition: exprString.H:60
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:232
fvPatch.H
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::expressions::patchExprFieldBase::valueExpr_
expressions::exprString valueExpr_
Definition: patchExprFieldBase.H:102
Foam::expressions::patchExprFieldBase::evalOnConstruct_
bool evalOnConstruct_
Slightly dodgy concept here.
Definition: patchExprFieldBase.H:99
pointMesh.H