fvCellSet.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-2021 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 "fvCellSet.H"
27 #include "volFields.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  template<> const char* NamedEnum
34  <
36  4
37  >::names[] =
38  {
39  "points",
40  "cellSet",
41  "cellZone",
42  "all"
43  };
44 
47 }
48 
49 
50 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 
52 void Foam::fvCellSet::setCellSet()
53 {
54  Info<< incrIndent;
55 
56  switch (selectionMode_)
57  {
59  {
60  Info<< indent << "- selecting cells using points" << endl;
61 
62  labelHashSet selectedCells;
63 
64  forAll(points_, i)
65  {
66  label celli = mesh_.findCell(points_[i]);
67  if (celli >= 0)
68  {
69  selectedCells.insert(celli);
70  }
71 
72  label globalCelli = returnReduce(celli, maxOp<label>());
73  if (globalCelli < 0)
74  {
76  << "Unable to find owner cell for point " << points_[i]
77  << endl;
78  }
79 
80  }
81 
82  cells_ = selectedCells.toc();
83 
84  break;
85  }
86  case selectionModeType::cellSet:
87  {
88  Info<< indent
89  << "- selecting cells using cellSet " << cellSetName_ << endl;
90 
91  cellSet selectedCells(mesh_, cellSetName_);
92  cells_ = selectedCells.toc();
93 
94  break;
95  }
96  case selectionModeType::cellZone:
97  {
98  Info<< indent
99  << "- selecting cells using cellZone " << cellSetName_ << endl;
100 
101  label zoneID = mesh_.cellZones().findZoneID(cellSetName_);
102  if (zoneID == -1)
103  {
105  << "Cannot find cellZone " << cellSetName_ << endl
106  << "Valid cellZones are " << mesh_.cellZones().names()
107  << exit(FatalError);
108  }
109  cells_ = mesh_.cellZones()[zoneID];
110 
111  break;
112  }
113  case selectionModeType::all:
114  {
115  Info<< indent << "- selecting all cells" << endl;
116  cells_ = identity(mesh_.nCells());
117 
118  break;
119  }
120  }
121 
122  // Set volume information
123  V_ = 0;
124  forAll(cells_, i)
125  {
126  V_ += mesh_.V()[cells_[i]];
127  }
128  reduce(V_, sumOp<scalar>());
129 
130  Info<< indent
131  << "- selected " << returnReduce(cells_.size(), sumOp<label>())
132  << " cell(s) with volume " << V_ << endl;
133 
134  Info<< decrIndent;
135 }
136 
137 
138 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
139 
141 (
142  const dictionary& dict,
143  const fvMesh& mesh
144 )
145 :
146  mesh_(mesh),
147  selectionMode_(selectionModeType::all),
148  cellSetName_(word::null),
149  V_(NaN)
150 {
151  read(dict);
152 }
153 
154 
155 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
156 
158 {}
159 
160 
161 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
162 
164 {
165  setCellSet();
166 }
167 
168 
170 {
171  selectionMode_ =
172  selectionModeTypeNames_.read(dict.lookup("selectionMode"));
173 
174  switch (selectionMode_)
175  {
177  {
178  dict.lookup("points") >> points_;
179  break;
180  }
181  case selectionModeType::cellSet:
182  {
183  dict.lookup("cellSet") >> cellSetName_;
184  break;
185  }
186  case selectionModeType::cellZone:
187  {
188  dict.lookup("cellZone") >> cellSetName_;
189  break;
190  }
191  case selectionModeType::all:
192  {
193  break;
194  }
195  default:
196  {
198  << "Unknown selectionMode "
199  << selectionModeTypeNames_[selectionMode_]
200  << ". Valid selectionMode types are" << selectionModeTypeNames_
201  << exit(FatalError);
202  }
203  }
204 
205  setCellSet();
206 
207  return true;
208 }
209 
210 
211 // ************************************************************************* //
#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
~fvCellSet()
Destructor.
Definition: fvCellSet.C:157
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:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
bool read(const dictionary &dict)
Read coefficients dictionary.
Definition: fvCellSet.C:169
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
void updateMesh(const mapPolyMesh &)
Update for mesh changes.
Definition: fvCellSet.C:163
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
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
bool read(const char *, int32_t &)
Definition: int32IO.C:85
const pointField & points
static const word null
An empty word.
Definition: word.H:77
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)
#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
selectionModeType
Enumeration for selection mode types.
Definition: fvCellSet.H:84
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
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
static const NamedEnum< selectionModeType, 4 > selectionModeTypeNames_
Word list of selection mode type names.
Definition: fvCellSet.H:94
fvCellSet(const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: fvCellSet.C:141
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:844