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 | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "cellSetOption.H"
27 #include "volFields.H"
28 
29 // Symbol to force loading at runtime
30 extern "C"
32 {}
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  namespace fv
39  {
40  defineTypeNameAndDebug(cellSetOption, 0);
41  }
42 
43  template<> const char* NamedEnum
44  <
46  4
47  >::names[] =
48  {
49  "points",
50  "cellSet",
51  "cellZone",
52  "all"
53  };
54 
57 }
58 
59 
60 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
61 
63 {
64  switch (selectionMode_)
65  {
66  case smPoints:
67  {
68  dict.lookup("points") >> points_;
69  break;
70  }
71  case smCellSet:
72  {
73  dict.lookup("cellSet") >> cellSetName_;
74  break;
75  }
76  case smCellZone:
77  {
78  dict.lookup("cellZone") >> cellSetName_;
79  break;
80  }
81  case smAll:
82  {
83  break;
84  }
85  default:
86  {
88  << "Unknown selectionMode "
90  << ". Valid selectionMode types are" << selectionModeTypeNames_
91  << exit(FatalError);
92  }
93  }
94 }
95 
96 
98 {
99  switch (selectionMode_)
100  {
101  case smPoints:
102  {
103  Info<< indent << "- selecting cells using points" << endl;
104 
105  labelHashSet selectedCells;
106 
107  forAll(points_, i)
108  {
109  label cellI = mesh_.findCell(points_[i]);
110  if (cellI >= 0)
111  {
112  selectedCells.insert(cellI);
113  }
114 
115  label globalCellI = returnReduce(cellI, maxOp<label>());
116  if (globalCellI < 0)
117  {
119  << "Unable to find owner cell for point " << points_[i]
120  << endl;
121  }
122 
123  }
124 
125  cells_ = selectedCells.toc();
126 
127  break;
128  }
129  case smCellSet:
130  {
131  Info<< indent
132  << "- selecting cells using cellSet " << cellSetName_ << endl;
133 
134  cellSet selectedCells(mesh_, cellSetName_);
135  cells_ = selectedCells.toc();
136 
137  break;
138  }
139  case smCellZone:
140  {
141  Info<< indent
142  << "- selecting cells using cellZone " << cellSetName_ << endl;
143 
144  label zoneID = mesh_.cellZones().findZoneID(cellSetName_);
145  if (zoneID == -1)
146  {
148  << "Cannot find cellZone " << cellSetName_ << endl
149  << "Valid cellZones are " << mesh_.cellZones().names()
150  << exit(FatalError);
151  }
152  cells_ = mesh_.cellZones()[zoneID];
153 
154  break;
155  }
156  case smAll:
157  {
158  Info<< indent << "- selecting all cells" << endl;
159  cells_ = identity(mesh_.nCells());
160 
161  break;
162  }
163  default:
164  {
166  << "Unknown selectionMode "
167  << selectionModeTypeNames_[selectionMode_]
168  << ". Valid selectionMode types are" << selectionModeTypeNames_
169  << exit(FatalError);
170  }
171  }
172 
173  // Set volume information
174  V_ = 0.0;
175  forAll(cells_, i)
176  {
177  V_ += mesh_.V()[cells_[i]];
178  }
179  reduce(V_, sumOp<scalar>());
180 
181  Info<< indent
182  << "- selected " << returnReduce(cells_.size(), sumOp<label>())
183  << " cell(s) with volume " << V_ << endl;
184 }
185 
186 
187 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
188 
190 (
191  const word& name,
192  const word& modelType,
193  const dictionary& dict,
194  const fvMesh& mesh
195 )
196 :
197  option(name, modelType, dict, mesh),
198  timeStart_(-1.0),
199  duration_(0.0),
200  selectionMode_
201  (
202  selectionModeTypeNames_.read(coeffs_.lookup("selectionMode"))
203  ),
204  cellSetName_("none"),
205  V_(0.0)
206 {
207  Info<< incrIndent;
208  read(dict);
209  setSelection(coeffs_);
210  setCellSet();
211  Info<< decrIndent;
212 }
213 
214 
215 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
216 
218 {}
219 
220 
221 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
222 
224 {
225  if (option::isActive() && inTimeLimits(mesh_.time().value()))
226  {
227  // Update the cell set if the mesh is changing
228  if (mesh_.changing())
229  {
230  setCellSet();
231  }
232 
233  return true;
234  }
235  else
236  {
237  return false;
238  }
239 }
240 
241 
242 // ************************************************************************* //
volFields.H
Foam::maxOp
Definition: ops.H:172
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:86
Foam::HashTable::toc
List< Key > toc() const
Return the table of contents.
Definition: HashTable.C:201
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::fv::cellSetOption::cellSetOption
cellSetOption(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: cellSetOption.C:190
Foam::fv::cellSetOption::selectionMode_
selectionModeType selectionMode_
Cell selection mode.
Definition: cellSetOption.H:104
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::fv::cellSetOption::~cellSetOption
virtual ~cellSetOption()
Destructor.
Definition: cellSetOption.C:217
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::fv::cellSetOption::smPoints
@ smPoints
Definition: cellSetOption.H:82
fvOptionsLoad
void fvOptionsLoad()
Definition: cellSetOption.C:31
Foam::HashSet< label, Hash< label > >
Foam::incrIndent
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
cellSetOption.H
Foam::fv::cellSetOption::setSelection
void setSelection(const dictionary &dict)
Set the cellSet or points selection.
Definition: cellSetOption.C:62
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:43
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::fv::option
Finite volume options abtract base class. Provides a base set of controls, e.g.
Definition: fvOption.H:65
Foam::Info
messageStream Info
Foam::fv::cellSetOption::selectionModeTypeNames_
static const NamedEnum< selectionModeType, 4 > selectionModeTypeNames_
Word list of selection mode type names.
Definition: cellSetOption.H:90
Foam::fv::cellSetOption::isActive
virtual bool isActive()
Is the source active?
Definition: cellSetOption.C:223
Foam::fv::cellSetOption::selectionModeType
selectionModeType
Enumeration for selection mode types.
Definition: cellSetOption.H:80
Foam::identity
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::decrIndent
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:235
Foam::cellSet
A collection of cell labels.
Definition: cellSet.H:48
Foam::indent
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
Foam::fv::cellSetOption::smCellZone
@ smCellZone
Definition: cellSetOption.H:84
Foam::fv::option::isActive
virtual bool isActive()
Is the source active?
Definition: fvOption.C:100
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
fv
labelList fv(nPoints)
Foam::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(option, 0)
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::sumOp
Definition: ops.H:162
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116
Foam::fv::cellSetOption::cellSetName_
word cellSetName_
Name of cell set for "cellSet" and "cellZone" selectionMode.
Definition: cellSetOption.H:107
Foam::fv::cellSetOption::points_
List< point > points_
List of points for "points" selectionMode.
Definition: cellSetOption.H:110
Foam::fv::cellSetOption::smCellSet
@ smCellSet
Definition: cellSetOption.H:83
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::fv::cellSetOption::setCellSet
void setCellSet()
Set the cell set based on the user input selection mode.
Definition: cellSetOption.C:97
Foam::NamedEnum
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52
Foam::fv::cellSetOption::smAll
@ smAll
Definition: cellSetOption.H:85