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-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 "volFields.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  namespace fv
37  {
38  defineTypeNameAndDebug(cellSetOption, 0);
39  }
40 }
41 
42 
43 const Foam::Enum
44 <
46 >
48 ({
49  { selectionModeType::smPoints, "points" },
50  { selectionModeType::smCellSet, "cellSet" },
51  { selectionModeType::smCellZone, "cellZone" },
52  { selectionModeType::smAll, "all" },
53 });
54 
55 
56 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
57 
59 {
60  switch (selectionMode_)
61  {
62  case smPoints:
63  {
64  dict.readEntry("points", points_);
65  break;
66  }
67  case smCellSet:
68  {
69  dict.readEntry("cellSet", cellSetName_);
70  break;
71  }
72  case smCellZone:
73  {
74  dict.readEntry("cellZone", cellSetName_);
75  break;
76  }
77  case smAll:
78  {
79  break;
80  }
81  default:
82  {
84  << "Unknown selectionMode "
86  << ". Valid selectionMode types : "
88  << exit(FatalError);
89  }
90  }
91 }
92 
93 
95 {
96  // Set volume information
97 
98  scalar sumVol = 0.0;
99  for (const label celli : cells_)
100  {
101  sumVol += mesh_.V()[celli];
102  }
103  reduce(sumVol, sumOp<scalar>());
104 
105  const scalar VOld = V_;
106  V_ = sumVol;
107 
108  // Convert both volumes to representation using current writeprecision
111 
112  if (VName != VOldName)
113  {
114  Info<< indent
115  << "- selected " << returnReduce(cells_.size(), sumOp<label>())
116  << " cell(s) with volume " << V_ << endl;
117  }
118 }
119 
120 
122 {
123  switch (selectionMode_)
124  {
125  case smPoints:
126  {
127  Info<< indent << "- selecting cells using points" << endl;
128 
129  labelHashSet selectedCells;
130 
131  forAll(points_, i)
132  {
133  label celli = mesh_.findCell(points_[i]);
134  if (celli >= 0)
135  {
136  selectedCells.insert(celli);
137  }
138 
139  label globalCelli = returnReduce(celli, maxOp<label>());
140  if (globalCelli < 0)
141  {
143  << "Unable to find owner cell for point " << points_[i]
144  << endl;
145  }
146 
147  }
148 
149  cells_ = selectedCells.sortedToc();
150  break;
151  }
152  case smCellSet:
153  {
154  Info<< indent
155  << "- selecting cells using cellSet " << cellSetName_ << endl;
156 
157  cells_ = cellSet(mesh_, cellSetName_).sortedToc();
158  break;
159  }
160  case smCellZone:
161  {
162  Info<< indent
163  << "- selecting cells using cellZone " << cellSetName_ << endl;
164 
165  label zoneID = mesh_.cellZones().findZoneID(cellSetName_);
166  if (zoneID == -1)
167  {
169  << "Cannot find cellZone " << cellSetName_ << endl
170  << "Valid cellZones are " << mesh_.cellZones().names()
171  << exit(FatalError);
172  }
173 
174  cells_ = mesh_.cellZones()[zoneID];
175  break;
176  }
177  case smAll:
178  {
179  Info<< indent << "- selecting all cells" << endl;
180 
181  cells_ = identity(mesh_.nCells());
182  break;
183  }
184  default:
185  {
187  << "Unknown selectionMode "
188  << selectionModeTypeNames_[selectionMode_]
189  << ". Valid selectionMode types are "
190  << selectionModeTypeNames_
191  << exit(FatalError);
192  }
193  }
194 }
195 
196 
197 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
198 
200 (
201  const word& name,
202  const word& modelType,
203  const dictionary& dict,
204  const fvMesh& mesh
205 )
206 :
207  fv::option(name, modelType, dict, mesh),
208  timeStart_(-1),
209  duration_(0),
210  selectionMode_(selectionModeTypeNames_.get("selectionMode", coeffs_)),
211  cellSetName_("none"),
212  V_(0)
213 {
214  Info<< incrIndent;
215  read(dict);
216  setSelection(coeffs_);
217  setCellSelection();
218  setVol();
219  Info<< decrIndent;
220 }
221 
222 
223 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
224 
226 {
227  if (fv::option::isActive() && inTimeLimits(mesh_.time().value()))
228  {
229  // Update the cell set if the mesh is changing
230  if (mesh_.changing())
231  {
232  if (mesh_.topoChanging())
233  {
234  setCellSelection();
235  // Force printing of new set volume
236  V_ = -GREAT;
237  }
238  else if (selectionMode_ == smPoints)
239  {
240  // This is the only geometric selection mode
241  setCellSelection();
242  }
243 
244  // Report new volume (if changed)
245  setVol();
246  }
247 
248  return true;
249  }
250 
251  return false;
252 }
253 
254 
256 {
257  if (fv::option::read(dict))
258  {
259  if (coeffs_.readIfPresent("timeStart", timeStart_))
260  {
261  coeffs_.readEntry("duration", duration_);
262  }
263 
264  return true;
265  }
266 
267  return false;
268 }
269 
270 
271 // ************************************************************************* //
Foam::fv::cellSetOption::setVol
void setVol()
Recalculate the volume.
Definition: cellSetOption.C:94
volFields.H
Foam::maxOp
Definition: ops.H:223
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
Foam::fv::cellSetOption::cellSetOption
cellSetOption(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: cellSetOption.C:200
Foam::fv::cellSetOption::selectionMode_
selectionModeType selectionMode_
Cell selection mode.
Definition: cellSetOption.H:195
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::fv::cellSetOption::setCellSelection
void setCellSelection()
Set the cell selection based on user input selection mode.
Definition: cellSetOption.C:121
Foam::fv::cellSetOption::smPoints
Definition: cellSetOption.H:177
Foam::HashSet< label, Hash< label > >
Foam::incrIndent
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:346
cellSetOption.H
Foam::sumOp
Definition: ops.H:213
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::fv::cellSetOption::setSelection
void setSelection(const dictionary &dict)
Set cell selection name or points selection from dictionary input.
Definition: cellSetOption.C:58
Foam::Time::timeName
virtual word timeName() const
Return current time name.
Definition: Time.C:790
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:51
Foam::fv::option
Base abstract class for handling finite volume options (i.e. fvOption).
Definition: fvOption.H:126
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::fv::cellSetOption::isActive
virtual bool isActive()
Is the source active?
Definition: cellSetOption.C:225
Foam::fv::cellSetOption::read
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: cellSetOption.C:255
Foam::fv::cellSetOption::selectionModeType
selectionModeType
Enumeration for selection mode types.
Definition: cellSetOption.H:172
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
zoneID
const labelIOList & zoneID
Definition: interpolatedFaces.H:22
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::decrIndent
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:353
Foam::cellSet
A collection of cell labels.
Definition: cellSet.H:51
Foam::indent
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:339
Foam::fv::option::read
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvOptionIO.C:55
Foam::fv::cellSetOption::smCellZone
Definition: cellSetOption.H:176
Foam::fv::option::isActive
virtual bool isActive()
Is the source active?
Definition: fvOption.C:119
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
fv
labelList fv(nPoints)
Foam::IOstream::defaultPrecision
static unsigned int defaultPrecision() noexcept
Return the default precision.
Definition: IOstream.H:342
Foam::fv::cellSetOption::selectionModeTypeNames_
static const Enum< selectionModeType > selectionModeTypeNames_
List of selection mode type names.
Definition: cellSetOption.H:181
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::identity
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
Definition: labelList.C:38
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:191
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(atmAmbientTurbSource, 0)
Foam::fv::cellSetOption::cellSetName_
word cellSetName_
Name of set/zone for "cellSet" and "cellZone" selectionMode.
Definition: cellSetOption.H:198
Foam::fv::cellSetOption::points_
List< point > points_
List of points for "points" selectionMode.
Definition: cellSetOption.H:201
Foam::fv::cellSetOption::smCellSet
Definition: cellSetOption.H:175
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::fv::cellSetOption::smAll
Definition: cellSetOption.H:174