All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2022 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::setCells()
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  Info<< decrIndent;
123 }
124 
125 
126 void Foam::fvCellSet::setV()
127 {
128  Info<< incrIndent;
129 
130  V_ = 0;
131  forAll(cells_, i)
132  {
133  V_ += mesh_.V()[cells_[i]];
134  }
135  reduce(V_, sumOp<scalar>());
136 
137  Info<< indent
138  << "- selected " << returnReduce(cells_.size(), sumOp<label>())
139  << " cell(s) with volume " << V_ << endl;
140 
141  Info<< decrIndent;
142 }
143 
144 
145 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
146 
148 (
149  const dictionary& dict,
150  const fvMesh& mesh
151 )
152 :
153  mesh_(mesh),
154  selectionMode_(selectionModeType::all),
155  cellSetName_(word::null),
156  V_(NaN)
157 {
158  read(dict);
159 }
160 
161 
162 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
163 
165 {}
166 
167 
168 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
169 
171 {
172  if (selectionMode_ == selectionModeType::points)
173  {
174  setCells();
175  }
176  setV();
177 }
178 
179 
181 {
182  setCells();
183  setV();
184 }
185 
186 
188 {
189  setCells();
190  setV();
191 }
192 
193 
195 {
196  setCells();
197  setV();
198 }
199 
200 
202 {
203  selectionMode_ =
204  selectionModeTypeNames_.read(dict.lookup("selectionMode"));
205 
206  switch (selectionMode_)
207  {
209  {
210  dict.lookup("points") >> points_;
211  break;
212  }
213  case selectionModeType::cellSet:
214  {
215  dict.lookup("cellSet") >> cellSetName_;
216  break;
217  }
218  case selectionModeType::cellZone:
219  {
220  dict.lookup("cellZone") >> cellSetName_;
221  break;
222  }
223  case selectionModeType::all:
224  {
225  break;
226  }
227  default:
228  {
230  << "Unknown selectionMode "
231  << selectionModeTypeNames_[selectionMode_]
232  << ". Valid selectionMode types are" << selectionModeTypeNames_
233  << exit(FatalError);
234  }
235  }
236 
237  setCells();
238  setV();
239 
240  return true;
241 }
242 
243 
244 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: fvCellSet.C:187
~fvCellSet()
Destructor.
Definition: fvCellSet.C:164
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:306
bool read(const dictionary &dict)
Read coefficients dictionary.
Definition: fvCellSet.C:201
void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
Definition: fvCellSet.C:180
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
void movePoints()
Update for mesh motion.
Definition: fvCellSet.C:170
void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
Definition: fvCellSet.C:194
bool read(const char *, int32_t &)
Definition: int32IO.C:85
const pointField & points
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
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:95
messageStream Info
selectionModeType
Enumeration for selection mode types.
Definition: fvCellSet.H:86
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
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:50
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:96
fvCellSet(const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: fvCellSet.C:148
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864