exprResultStack.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) 2012-2018 Bernhard Gschaider <bgschaid@hfd-research.com>
9 Copyright (C) 2019 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 "exprResultStack.H"
30#include "vector.H"
31#include "tensor.H"
32#include "symmTensor.H"
33#include "sphericalTensor.H"
35
36// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37
38namespace Foam
39{
40namespace expressions
41{
42
45 (
49 );
51 (
54 empty
55 );
56
57} // End namespace expressions
58} // End namespace Foam
59
60
61// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
62
64:
65 expressions::exprResult()
66{
67 needsReset(true); // Requires reset every timestep to work
68}
69
70
72(
73 const exprResultStack& rhs
74)
75:
76 expressions::exprResult(rhs)
77{
78 needsReset(true); // Requires reset every timestep to work
79}
80
81
83(
84 const dictionary &dict
85)
86:
87 expressions::exprResult(dict)
88{
89 needsReset(true); // Requires reset every timestep to work
90}
91
92
93// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
94
97{
98 exprResult result;
99
100 if (this->size() <= 0)
101 {
103 << "Trying to pop result from a empty queue" << endl
104 << abort(FatalError);
105
106 return result;
107 }
108
109 const bool ok =
110 (
111 popChecked<scalar>(result)
112 || popChecked<vector>(result)
113 || popChecked<tensor>(result)
114 || popChecked<symmTensor>(result)
115 || popChecked<sphericalTensor>(result)
116 );
117
118 if (!ok)
119 {
121 << "Unsupported value type " << valueType() << nl
122 << abort(FatalError);
123 }
124
125 return result;
126}
127
128
130{
131 DebugInFunction << nl << "Pushing: " << result << nl;
132
133 if (!hasValue())
134 {
135 // This is the first push
136 exprResult::operator=(result);
137 }
138 else
139 {
140 if (valueType() != result.valueType())
141 {
143 << "Type of pushed value " << result.valueType()
144 << " is not the expected type " << valueType() << nl
145 << abort(FatalError);
146 }
147
148 const bool ok =
149 (
150 pushChecked<scalar>(result)
151 || pushChecked<vector>(result)
152 || pushChecked<tensor>(result)
153 || pushChecked<symmTensor>(result)
154 || pushChecked<sphericalTensor>(result)
155 );
156
157 if (!ok)
158 {
160 << "Unsupported value type " << valueType() << nl
161 << abort(FatalError);
162 }
163 }
164
165 DebugInFunction << "After push: " << *this << nl;
166}
167
168
169// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
170
172(
173 const exprResultStack& rhs
174)
175{
176 if (this == &rhs)
177 {
178 return; // Self-assignment is a no-op
179 }
180
181 static_cast<exprResult&>(*this) = rhs;
182}
183
184
186(
187 const exprResult& rhs
188)
189{
190 if (this == &rhs)
191 {
192 return; // Self-assignment is a no-op
193 }
194
196
197 exprResult exprValue
198 (
199 // Issue warning if the other result is not really uniform
200 rhs.getUniform(1, false)
201 );
202
203 this->push(exprValue);
204}
205
206
207// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A stack of polymorphic fields. Can be used to build a list of results one at a time.
exprResult pop()
Pop the last value as an expression result.
void push(const exprResult &result)
Push an expression result value.
A polymorphic field/result from evaluating an expression.
Definition: exprResult.H:127
const word & valueType() const noexcept
Basic type for the field or single value.
Definition: exprResultI.H:235
virtual void operator=(const exprResult &rhs)
Copy assignment.
Definition: exprResult.C:498
void needsReset(bool val)
Adjusts the internal needsReset value.
Definition: exprResult.H:312
friend Ostream & operator(Ostream &, const faMatrix< Type > &)
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
#define DebugInFunction
Report an information message using Foam::Info.
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict