cellSetOption.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2017-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "cellSetOption.H"
30#include "cellSet.H"
31#include "cellBitSet.H"
32#include "volFields.H"
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
38 namespace fv
39 {
41 }
42}
43
44
45const Foam::Enum
46<
48>
50({
51 { selectionModeType::smGeometric, "geometric" },
52 { selectionModeType::smPoints, "points" },
53 { selectionModeType::smCellSet, "cellSet" },
54 { selectionModeType::smCellZone, "cellZone" },
55 { selectionModeType::smAll, "all" },
56});
57
58
59// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
60
62{
63 switch (selectionMode_)
64 {
65 case smGeometric:
66 {
67 geometricSelection_ = dict.subDict("selection");
68 break;
69 }
70 case smPoints:
71 {
72 dict.readEntry("points", points_);
73 break;
74 }
75 case smCellSet:
76 {
77 dict.readEntry("cellSet", zoneName_);
78 break;
79 }
80 case smCellZone:
81 {
82 dict.readEntry("cellZone", zoneName_);
83 break;
84 }
85 case smAll:
86 {
87 break;
88 }
89 default:
90 {
92 << "Unknown selectionMode "
94 << ". Valid selectionMode types : "
96 << exit(FatalError);
97 }
98 }
99}
100
101
103{
104 // Set volume information
105
106 scalar sumVol = 0;
107 for (const label celli : cells_)
108 {
109 sumVol += mesh_.V()[celli];
110 }
111 reduce(sumVol, sumOp<scalar>());
112
113 const scalar VOld = V_;
114 V_ = sumVol;
115
116 // Convert both volumes to representation using current writeprecision
119
120 if (VName != VOldName)
121 {
122 Info<< indent
123 << "- selected " << returnReduce(cells_.size(), sumOp<label>())
124 << " cell(s) with volume " << V_ << endl;
125 }
126}
127
128
130{
131 switch (selectionMode_)
132 {
133 case smGeometric:
134 {
135 Info<< indent << "- selecting cells geometrically" << endl;
136
137 bitSet selectedCells
138 (
139 // verbosity = true
140 cellBitSet::select(mesh_, geometricSelection_, true)
141 );
142
143 // From bitSet -> labels
144 cells_ = selectedCells.sortedToc();
145 break;
146 }
147 case smPoints:
148 {
149 Info<< indent << "- selecting cells using points" << endl;
150
151 labelHashSet selectedCells;
152
153 for (const point& p : points_)
154 {
155 const label celli = mesh_.findCell(p);
156
157 const bool found = (celli >= 0);
158
159 if (found)
160 {
161 selectedCells.insert(celli);
162 }
163
165 {
167 << "No owner cell found for point " << p << endl;
168 }
169 }
170
171 cells_ = selectedCells.sortedToc();
172 break;
173 }
174 case smCellSet:
175 {
176 Info<< indent
177 << "- selecting cells using cellSet " << zoneName_ << endl;
178
179 cells_ = cellSet(mesh_, zoneName_).sortedToc();
180 break;
181 }
182 case smCellZone:
183 {
184 Info<< indent
185 << "- selecting cells using cellZone " << zoneName_ << endl;
186
187 // Also handles groups, multiple zones (as wordRe match) ...
188 labelList zoneIDs = mesh_.cellZones().indices(zoneName_);
189
190 if (zoneIDs.empty())
191 {
193 << "No matching cellZones: " << zoneName_ << nl
194 << "Valid zones : "
195 << flatOutput(mesh_.cellZones().names()) << nl
196 << "Valid groups: "
197 << flatOutput(mesh_.cellZones().groupNames())
198 << nl
199 << exit(FatalError);
200 }
201
202 if (zoneIDs.size() == 1)
203 {
204 cells_ = mesh_.cellZones()[zoneIDs.first()];
205 }
206 else
207 {
208 cells_ = mesh_.cellZones().selection(zoneIDs).sortedToc();
209 }
210 break;
211 }
212 case smAll:
213 {
214 Info<< indent << "- selecting all cells" << endl;
215
216 cells_ = identity(mesh_.nCells());
217 break;
218 }
219 default:
220 {
222 << "Unknown selectionMode "
223 << selectionModeTypeNames_[selectionMode_]
224 << ". Valid selectionMode types are "
225 << selectionModeTypeNames_
226 << exit(FatalError);
227 }
228 }
229
230 if
231 (
232 smAll != selectionMode_
233 && returnReduce(cells_.empty(), andOp<bool>())
234 )
235 {
237 << "No cells selected!" << endl;
238 }
239}
240
241
242// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
243
245(
246 const word& name,
247 const word& modelType,
248 const dictionary& dict,
249 const fvMesh& mesh
250)
251:
252 fv::option(name, modelType, dict, mesh),
253 timeStart_(-1),
254 duration_(0),
255 selectionMode_(selectionModeTypeNames_.get("selectionMode", coeffs_)),
256 zoneName_(),
257 points_(),
258 geometricSelection_(),
259 V_(0)
260{
262 read(dict);
265 setVol();
267}
268
269
270// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
271
273{
274 if (fv::option::isActive() && inTimeLimits(mesh_.time().value()))
275 {
276 // Update the cell set if the mesh is changing
277 if (mesh_.changing())
278 {
279 if (mesh_.topoChanging())
280 {
281 setCellSelection();
282 // Force printing of new set volume
283 V_ = -GREAT;
284 }
285 else if
286 (
287 selectionMode_ == smGeometric
288 || selectionMode_ == smPoints
289 )
290 {
291 // Geometric selection mode(s)
292 setCellSelection();
293 }
294
295 // Report new volume (if changed)
296 setVol();
297 }
298
299 return true;
300 }
301
302 return false;
303}
304
305
307{
309 {
310 if (coeffs_.readIfPresent("timeStart", timeStart_))
311 {
312 coeffs_.readEntry("duration", duration_);
313 }
314
315 return true;
316 }
317
318 return false;
319}
320
321
322// ************************************************************************* //
bool found
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:191
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition: HashTable.C:137
static unsigned int defaultPrecision() noexcept
Return the default precision.
Definition: IOstream.H:342
virtual bool read()
Re-read model coefficients if they have changed.
virtual word timeName() const
Return current time name.
Definition: Time.C:790
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
labelList sortedToc() const
The indices of the on bits as a sorted labelList.
Definition: bitSetI.H:533
static bitSet select(const polyMesh &mesh, const dictionary &dict, const bool verbosity=false)
Definition: cellBitSet.C:97
A collection of cell labels.
Definition: cellSet.H:54
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:460
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
Intermediate abstract class for handling cell-set options for the derived fvOptions.
dictionary geometricSelection_
Dictionary entries for "geometric" (topoSetCellSource) selection.
List< point > points_
List of points for "points" selectionMode.
void setSelection(const dictionary &dict)
Set cell selection name or points selection from dictionary input.
Definition: cellSetOption.C:61
selectionModeType
Enumeration for selection mode types.
virtual bool read(const dictionary &dict)
Read source dictionary.
virtual bool isActive()
Is the source active?
wordRe zoneName_
Name of set/zone for "cellSet" and "cellZone" selectionMode.
selectionModeType selectionMode_
Cell selection mode.
static const Enum< selectionModeType > selectionModeTypeNames_
List of selection mode type names.
void setCellSelection()
Set the cell selection based on user input selection mode.
void setVol()
Recalculate the volume.
Base abstract class for handling finite volume options (i.e. fvOption).
Definition: fvOption.H:127
dictionary coeffs_
Dictionary containing source coefficients.
Definition: fvOption.H:145
virtual bool isActive()
Is the source active?
Definition: fvOption.C:119
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
volScalarField & p
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
const labelIOList & zoneIDs
Definition: correctPhi.H:59
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
Definition: labelList.C:38
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:349
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:342
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:215
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:356
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
labelList fv(nPoints)
dictionary dict