Loading...
Searching...
No Matches
PDRblockOuter.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-------------------------------------------------------------------------------
10License
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
28#include "PDRblock.H"
29#include "dictionary.H"
30#include "Switch.H"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34const Foam::Enum
35<
36 Foam::PDRblock::outerControl::controlType
37>
38Foam::PDRblock::outerControl::controlNames_
39({
40 { controlType::OUTER_NONE, "none" },
41 { controlType::OUTER_EXTEND, "extend" },
42 { controlType::OUTER_BOX, "box" },
43 { controlType::OUTER_SPHERE, "sphere" },
44});
45
46
47// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
48
49namespace Foam
50{
51
52// Get a single or a pair of values
53template<class T>
54static Vector2D<T> getLazyPair(const word& name, const dictionary& dict)
55{
56 if (token(dict.lookup(name)).isNumber())
57 {
58 return Vector2D<T>::uniform(dict.get<T>(name));
59 }
60
61 return dict.get<Vector2D<T>>(name);
62}
63
64} // End namespace Foam
65
66
67// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
68
69Foam::PDRblock::outerControl::outerControl()
70:
71 type_(controlType::OUTER_NONE),
72 expandType_(expansionType::EXPAND_RATIO),
73 onGround_(false),
74 relSize_(0,0),
75 nCells_(0,0),
76 expansion_(1,1)
77{}
78
79
80// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
81
82void Foam::PDRblock::outerControl::clear()
83{
84 type_ = controlType::OUTER_NONE;
85 expandType_ = expansionType::EXPAND_RATIO;
86 onGround_ = false;
87 relSize_ = Zero;
88 nCells_ = Zero;
89 expansion_ = vector2D::uniform(1);
90}
91
92
93void Foam::PDRblock::outerControl::report(Ostream& os) const
94{
95 if (active())
96 {
97 os << "Has outer region: " << controlNames_[type_] << nl
98 << " onGround : " << Switch::name(onGround_) << nl
99 << " sizes : " << relSize_ << nl
100 << " nCells : " << nCells_ << nl;
101 }
102 else
103 {
104 os << "No outer region" << nl;
105 }
106}
107
108
109bool Foam::PDRblock::outerControl::active() const
110{
111 return (controlType::OUTER_NONE != type_);
112}
113
114
115bool Foam::PDRblock::outerControl::isSphere() const
116{
117 return (controlType::OUTER_SPHERE == type_);
118}
119
120
121bool Foam::PDRblock::outerControl::onGround() const
122{
123 return onGround_;
124}
125
126
127bool Foam::PDRblock::outerControl::onGround(const bool on)
128{
129 bool old(onGround_);
130 onGround_ = on;
131 return old;
132}
133
134
135void Foam::PDRblock::outerControl::read(const dictionary& dict)
136{
137 clear();
138
139 type_ = controlNames_.getOrDefault("type", dict, controlType::OUTER_NONE);
140 onGround_ = dict.getOrDefault("onGround", false);
141
142 if (controlType::OUTER_NONE == type_)
143 {
144 return;
145 }
146
147 // Everything else
148
149 nCells_ = getLazyPair<label>("nCells", dict);
150 relSize_ = getLazyPair<scalar>("size", dict);
151
152 expandType_ =
153 expansionNames_.getOrDefault
154 (
155 "expansion",
156 dict,
158 );
159
160
161 if (dict.found("ratios"))
162 {
163 expansion_ = getLazyPair<scalar>("ratios", dict);
164 }
165 else
166 {
167 if (expandType_ != expansionType::EXPAND_UNIFORM)
168 {
169 expandType_ = expansionType::EXPAND_UNIFORM;
170 // Info << "Warning: no 'ratios', use uniform spacing" << nl;
171 }
172 }
173
174 if (expandType_ == expansionType::EXPAND_UNIFORM)
175 {
176 expansion_ = vector2D::uniform(1);
177 }
178
179
180 // Errors
181 int die = 0;
182
183 if (nCells_.x() <= 1 || nCells_.y() <= 1)
184 {
185 if (!die++)
186 {
188 }
190 << "Too few outer cells: " << nCells_ << nl;
191 }
192
193 if (relSize_.x() <= 1 || relSize_.y() <= 1)
194 {
195 if (!die++)
196 {
198 }
200 << "Outer dimensions must be > 1. Had " << relSize_ << nl;
201 }
202
203 if (die)
204 {
206 }
207
208
209 // Warnings
210
211 if
212 (
213 controlType::OUTER_BOX == type_
214 || controlType::OUTER_SPHERE == type_
215 )
216 {
217 if (relSize_.x() < 2 || relSize_.y() < 2)
218 {
220 << "Outer dimensions "
221 << relSize_ << " too small for "
222 << controlNames_[type_] << " - switching to "
223 << controlNames_[controlType::OUTER_EXTEND] << nl;
224
225 type_ = controlType::OUTER_EXTEND;
226 }
227 }
228
229 if (controlType::OUTER_SPHERE == type_)
230 {
231 if (relSize_.x() < 3 || relSize_.y() < 3)
232 {
234 << "Outer dimensions "
235 << relSize_ << " too small for "
236 << controlNames_[type_] << " - switching to "
237 << controlNames_[controlType::OUTER_BOX] << nl;
238
239 type_ = controlType::OUTER_EXTEND;
240 }
241 }
242}
243
244
245// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition Enum.H:57
static const Enum< expansionType > expansionNames_
Named enumerations for the expansion type.
Definition PDRblock.H:170
@ EXPAND_UNIFORM
Uniform expansion (ie, no expansion).
Definition PDRblock.H:162
@ EXPAND_RATIO
End/start ratio.
Definition PDRblock.H:163
static const char * name(bool b) noexcept
A string representation of bool as "false" / "true".
Templated 2D Vector derived from VectorSpace adding construction from 2 components,...
Definition Vector2D.H:54
static Vector2D< Cmpt > uniform(const Cmpt &s)
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
void clear()
Reset to (0,0,0) sizing.
A token holds an item read from Istream.
Definition token.H:70
bool isNumber() const noexcept
Token is (signed/unsigned) integer type, FLOAT or DOUBLE.
Definition tokenI.H:992
A class for handling words, derived from Foam::string.
Definition word.H:66
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
OBJstream os(runTime.globalPath()/outputName)
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
static Vector2D< T > getLazyPair(const word &name, const dictionary &dict)
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict