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_(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 :
171  isoSurfaceParams(dict, isoSurfaceParams(algo, filter))
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 // ************************************************************************* //
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:77
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::isoSurfaceParams::getFilterType
static filterType getFilterType(const dictionary &dict, const filterType deflt)
Get 'regularise' as bool or enumeration.
Definition: isoSurfaceParams.C:100
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::isoSurfaceParams::algorithmType
algorithmType
The algorithm types.
Definition: isoSurfaceParams.H:114
Foam::FatalIOError
IOerror FatalIOError
Foam::Switch::good
bool good() const noexcept
True if the Switch represents a valid enumeration.
Definition: Switch.C:300
isoSurfaceParams.H
Foam::isoSurfaceParams::algorithmNames
static const Enum< algorithmType > algorithmNames
Names for the iso-surface algorithms.
Definition: isoSurfaceParams.H:162
Foam::isoSurfaceParams::isoSurfaceParams
isoSurfaceParams(const algorithmType algo=algorithmType::ALGO_DEFAULT, const filterType filter=filterType::DIAGCELL) noexcept
Default construct, or with specified algorithm.
Definition: isoSurfaceParams.C:135
Foam::isoSurfaceParams::print
void print(Ostream &os) const
Print information about the settings.
Definition: isoSurfaceParams.C:183
Switch.H
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
Foam::isoSurfaceParams
Preferences for controlling iso-surface algorithms.
Definition: isoSurfaceParams.H:107
os
OBJstream os(runTime.globalPath()/outputName)
Foam::isoSurfaceParams::setClipBounds
void setClipBounds(const boundBox &bb)
Set optional clipping bounding box.
Definition: isoSurfaceParams.C:177
Foam::ListOps::find
label find(const ListType &input, const UnaryPredicate &pred, const label start=0)
Find index of the first occurrence that satisfies the predicate.
Foam::isoSurfaceParams::getAlgorithmType
static algorithmType getAlgorithmType(const dictionary &dict, const algorithmType deflt)
Get 'isoMethod' or 'isoAlgorithm' as enumeration.
Definition: isoSurfaceParams.C:68
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
boundBox.H
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
dictionary.H
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Foam::isoSurfaceParams::filterNames
static const Enum< filterType > filterNames
Names for the filtering types.
Definition: isoSurfaceParams.H:165
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::isoSurfaceParams::filterType
filterType
The filtering (regularization) to apply.
Definition: isoSurfaceParams.H:123