All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cellSetOption.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  namespace fv
34  {
35  defineTypeNameAndDebug(cellSetOption, 0);
36  }
37 
38  template<> const char* NamedEnum
39  <
41  4
42  >::names[] =
43  {
44  "points",
45  "cellSet",
46  "cellZone",
47  "all"
48  };
49 
52 }
53 
54 
55 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
56 
58 {
59  switch (selectionMode_)
60  {
61  case smPoints:
62  {
63  dict.lookup("points") >> points_;
64  break;
65  }
66  case smCellSet:
67  {
68  dict.lookup("cellSet") >> cellSetName_;
69  break;
70  }
71  case smCellZone:
72  {
73  dict.lookup("cellZone") >> cellSetName_;
74  break;
75  }
76  case smAll:
77  {
78  break;
79  }
80  default:
81  {
83  << "Unknown selectionMode "
84  << selectionModeTypeNames_[selectionMode_]
85  << ". Valid selectionMode types are" << selectionModeTypeNames_
86  << exit(FatalError);
87  }
88  }
89 }
90 
91 
93 {
94  switch (selectionMode_)
95  {
96  case smPoints:
97  {
98  Info<< indent << "- selecting cells using points" << endl;
99 
100  labelHashSet selectedCells;
101 
102  forAll(points_, i)
103  {
104  label celli = mesh_.findCell(points_[i]);
105  if (celli >= 0)
106  {
107  selectedCells.insert(celli);
108  }
109 
110  label globalCelli = returnReduce(celli, maxOp<label>());
111  if (globalCelli < 0)
112  {
114  << "Unable to find owner cell for point " << points_[i]
115  << endl;
116  }
117 
118  }
119 
120  cells_ = selectedCells.toc();
121 
122  break;
123  }
124  case smCellSet:
125  {
126  Info<< indent
127  << "- selecting cells using cellSet " << cellSetName_ << endl;
128 
129  cellSet selectedCells(mesh_, cellSetName_);
130  cells_ = selectedCells.toc();
131 
132  break;
133  }
134  case smCellZone:
135  {
136  Info<< indent
137  << "- selecting cells using cellZone " << cellSetName_ << endl;
138 
139  label zoneID = mesh_.cellZones().findZoneID(cellSetName_);
140  if (zoneID == -1)
141  {
143  << "Cannot find cellZone " << cellSetName_ << endl
144  << "Valid cellZones are " << mesh_.cellZones().names()
145  << exit(FatalError);
146  }
147  cells_ = mesh_.cellZones()[zoneID];
148 
149  break;
150  }
151  case smAll:
152  {
153  Info<< indent << "- selecting all cells" << endl;
154  cells_ = identity(mesh_.nCells());
155 
156  break;
157  }
158  default:
159  {
161  << "Unknown selectionMode "
162  << selectionModeTypeNames_[selectionMode_]
163  << ". Valid selectionMode types are" << selectionModeTypeNames_
164  << exit(FatalError);
165  }
166  }
167 
168  // Set volume information
169  V_ = 0.0;
170  forAll(cells_, i)
171  {
172  V_ += mesh_.V()[cells_[i]];
173  }
174  reduce(V_, sumOp<scalar>());
175 
176  Info<< indent
177  << "- selected " << returnReduce(cells_.size(), sumOp<label>())
178  << " cell(s) with volume " << V_ << endl;
179 }
180 
181 
182 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
183 
185 (
186  const word& name,
187  const word& modelType,
188  const dictionary& dict,
189  const fvMesh& mesh
190 )
191 :
192  option(name, modelType, dict, mesh),
193  timeStart_(-1.0),
194  duration_(0.0),
195  selectionMode_
196  (
197  selectionModeTypeNames_.read(coeffs_.lookup("selectionMode"))
198  ),
199  cellSetName_("none"),
200  V_(0.0)
201 {
202  Info<< incrIndent;
203  read(dict);
204  setSelection(coeffs_);
205  setCellSet();
206  Info<< decrIndent;
207 }
208 
209 
210 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
211 
213 {}
214 
215 
216 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
217 
219 {
220  if (option::isActive() && inTimeLimits(mesh_.time().value()))
221  {
222  // Update the cell set if the mesh is changing
223  if (mesh_.changing())
224  {
225  setCellSet();
226  }
227 
228  return true;
229  }
230  else
231  {
232  return false;
233  }
234 }
235 
236 
237 // ************************************************************************* //
defineTypeNameAndDebug(option, 0)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
static const NamedEnum< selectionModeType, 4 > selectionModeTypeNames_
Word list of selection mode type names.
Definition: cellSetOption.H:88
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:111
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:51
cellSetOption(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
virtual ~cellSetOption()
Destructor.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
virtual bool isActive()
Is the source active?
selectionModeType
Enumeration for selection mode types.
Definition: cellSetOption.H:78
A class for handling words, derived from string.
Definition: word.H:59
labelList fv(nPoints)
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:235
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
void setCellSet()
Set the cell set based on the user input selection mode.
Definition: cellSetOption.C:92
void setSelection(const dictionary &dict)
Set the cellSet or points selection.
Definition: cellSetOption.C:57
#define WarningInFunction
Report a warning using Foam::Warning.
A collection of cell labels.
Definition: cellSet.H:48
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
messageStream Info
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
virtual bool isActive()
Is the source active?
Definition: fvOption.C:107
List< Key > toc() const
Return the table of contents.
Definition: HashTable.C:202
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:812
Finite volume options abstract base class. Provides a base set of controls, e.g.: ...
Definition: fvOption.H:66