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 -------------------------------------------------------------------------------
10 License
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 
34 const Foam::Enum
35 <
36  Foam::PDRblock::outerControl::controlType
37 >
38 Foam::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 
49 namespace Foam
50 {
51 
52 // Get a single or a pair of values
53 template<class T>
55 {
56  if (token(dict.lookup(name)).isNumber())
57  {
59  }
60 
61  return dict.get<Vector2D<T>>(name);
62 }
63 
64 } // End namespace Foam
65 
66 
67 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
68 
69 Foam::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 
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 
93 void 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 
109 bool Foam::PDRblock::outerControl::active() const
110 {
111  return (controlType::OUTER_NONE != type_);
112 }
113 
114 
115 bool Foam::PDRblock::outerControl::isSphere() const
116 {
117  return (controlType::OUTER_SPHERE == type_);
118 }
119 
120 
121 bool Foam::PDRblock::outerControl::onGround() const
122 {
123  return onGround_;
124 }
125 
126 
127 bool Foam::PDRblock::outerControl::onGround(const bool on)
128 {
129  bool old(onGround_);
130  onGround_ = on;
131  return old;
132 }
133 
134 
135 void 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,
157  expansionType::EXPAND_RATIO
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 // ************************************************************************* //
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::VectorSpace< Vector2D< Cmpt >, Cmpt, 2 >::uniform
static Vector2D< Cmpt > uniform(const Cmpt &s)
Return a VectorSpace with all elements = s.
Definition: VectorSpaceI.H:164
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::FatalIOError
IOerror FatalIOError
Foam::token
A token holds an item read from Istream.
Definition: token.H:68
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
Foam::Vector2D
Templated 2D Vector derived from VectorSpace adding construction from 2 components,...
Definition: Vector2D.H:55
Foam::blockMeshTools::read
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:57
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Switch.H
Foam::getLazyPair
static Vector2D< T > getLazyPair(const word &name, const dictionary &dict)
Definition: PDRblockOuter.C:54
PDRblock.H
Foam::dictionary::lookup
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionary.C:386
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:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
clear
patchWriters clear()
Foam::nl
constexpr char nl
Definition: Ostream.H:404
dictionary.H
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328