Loading...
Searching...
No Matches
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-2022 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
29#include "patchExprFieldBase.H"
30#include "facePointPatch.H"
31#include "fvMesh.H"
32#include "fvPatch.H"
33#include "pointMesh.H"
34#include "stringOps.H"
35
36// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37
38void Foam::expressions::patchExprFieldBase::readExpressions
39(
40 const dictionary& dict,
41 enum expectedTypes expectedType,
42 bool wantPointData
43)
44{
45 if (debug_)
46 {
47 Info<< "Expression BC with " << dict << nl;
48 }
49
50 valueExpr_.clear();
51 gradExpr_.clear();
52 fracExpr_.clear();
53
54 if (expectedTypes::VALUE_TYPE == expectedType)
55 {
56 // Mandatory
57 valueExpr_.readEntry("valueExpr", dict);
58 }
59 else if (expectedTypes::GRADIENT_TYPE == expectedType)
60 {
61 // Mandatory
62 gradExpr_.readEntry("gradientExpr", dict);
63 }
64 else
65 {
66 // MIXED_TYPE
67 const bool evalValue = valueExpr_.readIfPresent("valueExpr", dict);
68 const bool evalGrad = gradExpr_.readIfPresent("gradientExpr", dict);
69
70 // Expect a fraction as well
71 // - but allow it to be optional and defer treatment to inherited BC
72
73 if (evalValue && evalGrad)
74 {
75 if
76 (
77 fracExpr_.readIfPresent("fractionExpr", dict)
78 && !fracExpr_.empty()
79 )
80 {
81 // Add function call wrapping for point data,
82 // but not for 0/1 (handled as shortcuts later)
83 if (wantPointData && fracExpr_ != "0" && fracExpr_ != "1")
84 {
85 fracExpr_ = "point(" + fracExpr_ + ")";
86 }
87 }
88 }
89 else
90 {
92 << "Entries 'valueExpr' and 'gradientExpr' "
93 "(mixed-conditon) not found in dictionary "
94 << dict.name() << nl
96 }
97
98 if (debug_)
99 {
100 if (!evalValue)
101 {
102 Info<< "Mixed with no valueExpr" << nl;
103 }
104 if (!evalGrad)
105 {
106 Info<< "Mixed with no gradientExpr" << nl;
107 }
109 }
110}
111
112
113// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
114
116:
117 debug_(false),
119 valueExpr_(),
120 gradExpr_(),
121 fracExpr_()
122{}
123
124
126(
127 const dictionary& dict,
128 enum expectedTypes expectedType,
129 bool wantPointData
130)
131:
132 debug_(dict.getOrDefault("debug", false)),
133 evalOnConstruct_(dict.getOrDefault("evalOnConstruct", false)),
134 valueExpr_(),
135 gradExpr_(),
136 fracExpr_()
138 readExpressions(dict, expectedType, wantPointData);
139}
140
141
142// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
143
145{
146 os.writeEntryIfDifferent<bool>("evalOnConstruct", false, evalOnConstruct_);
147
148 // Do not emit debug_ value
149
150 // Write expression, but not empty ones
151 valueExpr_.writeEntry("valueExpr", os, false);
152 gradExpr_.writeEntry("gradientExpr", os, false);
153 fracExpr_.writeEntry("fractionExpr", os, false);
154}
155
156
157// ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
bool evalOnConstruct_
Slightly dodgy concept here.
void write(Ostream &os) const
Write.
expectedTypes
Enumeration of expected expressions.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
OBJstream os(runTime.globalPath()/outputName)
messageStream Info
Information stream (stdout output on master, null elsewhere).
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict