isoSurfaceParams.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-2021 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 "isoSurfaceParams.H"
29 #include "dictionary.H"
30 #include "Switch.H"
31 #include "boundBox.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 const Foam::Enum
36 <
38 >
40 ({
41  { algorithmType::ALGO_DEFAULT, "default" },
42  { algorithmType::ALGO_CELL, "cell" },
43  { algorithmType::ALGO_POINT, "point" },
44  { algorithmType::ALGO_TOPO, "topo" },
45 });
46 
47 
48 const Foam::Enum
49 <
51 >
53 ({
54  { filterType::NONE, "none" },
55  { filterType::PARTIAL, "partial" },
56  { filterType::FULL, "full" },
57  { filterType::CLEAN, "clean" },
58 
59  { filterType::CELL, "cell" },
60  { filterType::DIAGCELL, "diagcell" },
61 });
62 
63 
64 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
65 
68 (
69  const dictionary& dict,
70  const algorithmType deflt
71 )
72 {
73  word enumName;
74  if
75  (
76  !dict.readIfPresentCompat
77  (
78  "isoMethod", {{"isoAlgorithm", 0}},
79  enumName, keyType::LITERAL
80  )
81  )
82  {
83  return deflt;
84  }
85 
86  if (!algorithmNames.found(enumName))
87  {
89  << enumName << " is not in enumeration: "
90  << (algorithmNames) << nl
91  << exit(FatalIOError);
92  }
93 
94  return algorithmNames[enumName];
95 }
96 
97 
100 (
101  const dictionary& dict,
102  const filterType deflt
103 )
104 {
105  word enumName;
106  if (!dict.readIfPresent("regularise", enumName, keyType::LITERAL))
107  {
108  return deflt;
109  }
110 
111  // Try as bool/switch
112  const Switch sw = Switch::find(enumName);
113 
114  if (sw.good())
115  {
116  return (sw ? deflt : filterType::NONE);
117  }
118 
119  // As enum
120  if (!filterNames.found(enumName))
121  {
123  << enumName << " is not in enumeration: "
124  << (filterNames) << nl
125  << exit(FatalIOError);
126  }
127 
128  return filterNames[enumName];
129 }
130 
131 
132 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
133 
135 (
136  const algorithmType algo,
137  const filterType filter
138 ) noexcept
139 :
140  algo_(algo),
141  filter_(filter),
142  snap_(true),
143  mergeTol_(1e-6),
144  clipBounds_()
145 {}
146 
147 
149 (
150  const dictionary& dict,
151  const isoSurfaceParams& params
152 )
153 :
154  isoSurfaceParams(params)
155 {
156  algo_ = getAlgorithmType(dict, algo_);
157  filter_ = getFilterType(dict, filter_);
158  snap_ = dict.getOrDefault("snap", true);
159  dict.readIfPresent("mergeTol", mergeTol_);
160  dict.readIfPresent("bounds", clipBounds_);
161 }
162 
163 
165 (
166  const dictionary& dict,
167  const algorithmType algo,
168  const filterType filter
169 )
170 :
171  isoSurfaceParams(dict, isoSurfaceParams(algo, filter))
172 {}
173 
174 
175 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
178 {
179  clipBounds_ = bb;
180 }
181 
182 
184 {
185  os << " isoMethod:" << algorithmNames[algo_]
186  << " regularise:" << filterNames[filter_]
187  << " snap:" << snap_;
188 }
189 
190 
191 // ************************************************************************* //
dictionary dict
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Preferences for controlling iso-surface algorithms.
static filterType getFilterType(const dictionary &dict, const filterType deflt)
Get &#39;regularise&#39; as bool or enumeration.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
void print(Ostream &os) const
Print information about the settings.
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
algorithmType
The algorithm types.
void setClipBounds(const boundBox &bb)
Set optional clipping bounding box.
isoSurfaceParams(const algorithmType algo=algorithmType::ALGO_DEFAULT, const filterType filter=filterType::DIAGCELL) noexcept
Default construct, or with specified algorithm.
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
A class for handling words, derived from Foam::string.
Definition: word.H:63
String literal.
Definition: keyType.H:82
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
OBJstream os(runTime.globalPath()/outputName)
filterType
The filtering (regularization) to apply.
static const Enum< algorithmType > algorithmNames
Names for the iso-surface algorithms.
static const Enum< filterType > filterNames
Names for the filtering types.
static algorithmType getAlgorithmType(const dictionary &dict, const algorithmType deflt)
Get &#39;isoMethod&#39; or &#39;isoAlgorithm&#39; as enumeration.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: error.H:64
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
static Switch find(const std::string &str)
Find switchType for the given string, returning as a Switch that can be tested for good() or bad()...
Definition: Switch.C:147
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...