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 -------------------------------------------------------------------------------
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 "exprResultStack.H"
30 #include "vector.H"
31 #include "tensor.H"
32 #include "symmTensor.H"
33 #include "sphericalTensor.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 namespace expressions
41 {
42 
43  defineTypeNameAndDebug(exprResultStack, 0);
45  (
46  exprResult,
47  exprResultStack,
48  dictionary
49  );
51  (
52  exprResult,
53  exprResultStack,
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 :
77 {
78  needsReset(true); // Requires reset every timestep to work
79 }
80 
81 
83 (
84  const dictionary &dict
85 )
86 :
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 
171 void Foam::expressions::exprResultStack::operator=
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 
185 void Foam::expressions::exprResultStack::operator=
186 (
187  const exprResult& rhs
188 )
189 {
190  if (this == &rhs)
191  {
192  return; // Self-assignment is a no-op
193  }
194 
195  DebugInFunction << nl;
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 // ************************************************************************* //
exprResultStack.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::expressions::exprResultStack::pop
exprResult pop()
Pop the last value as an expression result.
Definition: exprResultStack.C:96
tensor.H
Foam::expressions::exprResult::operator=
virtual void operator=(const exprResult &rhs)
Copy assignment.
Definition: exprResult.C:498
Foam::expressions::exprResultStack::push
void push(const exprResult &result)
Push an expression result value.
Definition: exprResultStack.C:129
sphericalTensor.H
Foam::expressions::exprResult
A polymorphic field/result from evaluating an expression.
Definition: exprResult.H:124
Foam::expressions::exprResult::valueType
const word & valueType() const noexcept
Basic type for the field or single value.
Definition: exprResultI.H:235
symmTensor.H
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:388
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::expressions::exprResult::needsReset
void needsReset(bool val)
Adjusts the internal needsReset value.
Definition: exprResult.H:312
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::expressions::exprResult::getUniform
exprResult getUniform(const label size, const bool noWarn, const bool parRun=Pstream::parRun()) const
Construct a uniform field from the current results.
Definition: exprResult.C:436
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::expressions::exprResultStack
A stack of polymorphic fields. Can be used to build a list of results one at a time.
Definition: exprResultStack.H:55
vector.H
Foam::expressions::exprResultStack::exprResultStack
exprResultStack()
Default construct.
Definition: exprResultStack.C:63
Foam::expressions::addToRunTimeSelectionTable
addToRunTimeSelectionTable(exprResult, exprResult, dictionary)
Foam::expressions::defineTypeNameAndDebug
defineTypeNameAndDebug(fvExprDriver, 0)