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-------------------------------------------------------------------------------
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 "isoSurfaceParams.H"
29#include "dictionary.H"
30#include "Switch.H"
31#include "boundBox.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35const 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
48const 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 (
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
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_(boundBox::invertedBox)
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:
172{}
173
174
175// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
176
178{
179 clipBounds_ = bb;
180}
181
182
184{
185 os << " isoMethod:" << algorithmNames[algo_]
186 << " regularise:" << filterNames[filter_]
187 << " snap:" << snap_;
188}
189
190
191// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:78
bool good() const noexcept
True if the Switch represents a valid enumeration.
Definition: Switch.C:300
static Switch find(const std::string &str)
Definition: Switch.C:151
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:64
static const boundBox invertedBox
A large inverted boundBox: min/max == +/- ROOTVGREAT.
Definition: boundBox.H:86
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
bool readIfPresentCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, T &val, enum keyType::option matchOpt=keyType::REGEX) const
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Preferences for controlling iso-surface algorithms.
static const Enum< filterType > filterNames
Names for the filtering types.
algorithmType
The algorithm types.
void setClipBounds(const boundBox &bb)
Set optional clipping bounding box.
static algorithmType getAlgorithmType(const dictionary &dict, const algorithmType deflt)
Get 'isoMethod' or 'isoAlgorithm' as enumeration.
static filterType getFilterType(const dictionary &dict, const filterType deflt)
Get 'regularise' as bool or enumeration.
static const Enum< algorithmType > algorithmNames
Names for the iso-surface algorithms.
filterType
The filtering (regularization) to apply.
@ LITERAL
String literal.
Definition: keyType.H:81
scalar print()
Print to screen.
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
OBJstream os(runTime.globalPath()/outputName)
IOerror FatalIOError
const direction noexcept
Definition: Scalar.H:223
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict
volScalarField & e
Definition: createFields.H:11