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 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::CELL, "cell" },
56  { filterType::DIAGCELL, "diagcell" },
57  { filterType::PARTIAL, "partial" },
58  { filterType::FULL, "full" },
59 });
60 
61 
62 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
63 
66 (
67  const dictionary& dict,
68  const algorithmType deflt
69 )
70 {
71  word enumName;
72  if
73  (
74  !dict.readIfPresentCompat
75  (
76  "isoMethod", {{"isoAlgorithm", 0}},
77  enumName, keyType::LITERAL
78  )
79  )
80  {
81  return deflt;
82  }
83 
84  if (!algorithmNames.found(enumName))
85  {
87  << enumName << " is not in enumeration: "
88  << (algorithmNames) << nl
89  << exit(FatalIOError);
90  }
91 
92  return algorithmNames[enumName];
93 }
94 
95 
98 (
99  const dictionary& dict,
100  const filterType deflt
101 )
102 {
103  word enumName;
104  if (!dict.readIfPresent("regularise", enumName, keyType::LITERAL))
105  {
106  return deflt;
107  }
108 
109  // Try as bool/switch
110  const Switch sw = Switch::find(enumName);
111 
112  if (sw.good())
113  {
114  return (sw ? deflt : filterType::NONE);
115  }
116 
117  // As enum
118  if (!filterNames.found(enumName))
119  {
121  << enumName << " is not in enumeration: "
122  << (filterNames) << nl
123  << exit(FatalIOError);
124  }
125 
126  return filterNames[enumName];
127 }
128 
129 
130 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
131 
133 (
134  const algorithmType algo,
135  const filterType filter
136 ) noexcept
137 :
138  algo_(algo),
139  filter_(filter),
140  mergeTol_(1e-6),
141  clipBounds_(boundBox::invertedBox)
142 {}
143 
144 
146 (
147  const dictionary& dict,
148  const isoSurfaceParams& params
149 )
150 :
151  isoSurfaceParams(params)
152 {
153  algo_ = getAlgorithmType(dict, algo_);
154  filter_ = getFilterType(dict, filter_);
155  dict.readIfPresent("mergeTol", mergeTol_);
156  dict.readIfPresent("bounds", clipBounds_);
157 }
158 
159 
161 (
162  const dictionary& dict,
163  const algorithmType algo,
164  const filterType filter
165 )
166 :
167  isoSurfaceParams(dict, isoSurfaceParams(algo, filter))
168 {}
169 
170 
171 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
172 
174 {
175  clipBounds_ = bb;
176 }
177 
178 
179 // ************************************************************************* //
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:98
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::isoSurfaceParams::algorithmType
algorithmType
The algorithm types.
Definition: isoSurfaceParams.H:98
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:139
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:133
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:121
Foam::isoSurfaceParams
Preferences for controlling iso-surface algorithms.
Definition: isoSurfaceParams.H:91
Foam::isoSurfaceParams::setClipBounds
void setClipBounds(const boundBox &bb)
Set optional clipping bounding box.
Definition: isoSurfaceParams.C:173
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:66
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:385
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:142
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401
Foam::isoSurfaceParams::filterType
filterType
The filtering (regularization) to apply.
Definition: isoSurfaceParams.H:107