cellSet.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 OpenFOAM Foundation
9  Copyright (C) 2016-2018 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 "cellSet.H"
30 #include "mapPolyMesh.H"
31 #include "polyMesh.H"
32 #include "Time.H"
34 #include "mapDistributePolyMesh.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 defineTypeNameAndDebug(cellSet, 0);
41 
42 addToRunTimeSelectionTable(topoSet, cellSet, word);
43 addToRunTimeSelectionTable(topoSet, cellSet, size);
44 addToRunTimeSelectionTable(topoSet, cellSet, set);
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
50 Foam::cellSet::cellSet(const IOobject& obj)
51 :
52  topoSet(obj, typeName)
53 {}
54 
55 
56 Foam::cellSet::cellSet
57 (
58  const polyMesh& mesh,
59  const word& name,
60  readOption r,
61  writeOption w
62 )
63 :
64  topoSet(mesh, typeName, name, r, w)
65 {
66  // Make sure set within valid range
67  check(mesh.nCells());
68 }
69 
70 
71 Foam::cellSet::cellSet
72 (
73  const polyMesh& mesh,
74  const word& name,
75  const label size,
76  writeOption w
77 )
78 :
79  topoSet(mesh, name, size, w)
80 {}
81 
82 
83 Foam::cellSet::cellSet
84 (
85  const polyMesh& mesh,
86  const word& name,
87  const topoSet& set,
88  writeOption w
89 )
90 :
91  topoSet(mesh, name, set, w)
92 {}
93 
94 
95 Foam::cellSet::cellSet
96 (
97  const polyMesh& mesh,
98  const word& name,
99  const labelHashSet& labels,
100  writeOption w
101 )
102 :
103  topoSet(mesh, name, labels, w)
104 {}
105 
106 
107 Foam::cellSet::cellSet
108 (
109  const polyMesh& mesh,
110  const word& name,
111  labelHashSet&& labels,
112  writeOption w
113 )
114 :
115  topoSet(mesh, name, std::move(labels), w)
116 {}
117 
118 
119 Foam::cellSet::cellSet
120 (
121  const polyMesh& mesh,
122  const word& name,
123  const labelUList& labels,
124  writeOption w
125 )
126 :
127  topoSet(mesh, name, labels, w)
128 {}
129 
130 
131 // Database constructors (for when no mesh available)
132 Foam::cellSet::cellSet
133 (
134  const Time& runTime,
135  const word& name,
136  readOption r,
137  writeOption w
138 )
139 :
140  topoSet
141  (
142  findIOobject(runTime, name, r, w),
143  typeName
144  )
145 {}
146 
147 
148 Foam::cellSet::cellSet
149 (
150  const Time& runTime,
151  const word& name,
152  const label size,
153  writeOption w
154 )
155 :
156  topoSet
157  (
158  findIOobject(runTime, name, IOobject::NO_READ, w),
159  size
160  )
161 {}
162 
163 
164 Foam::cellSet::cellSet
165 (
166  const Time& runTime,
167  const word& name,
168  const labelHashSet& labels,
169  writeOption w
170 )
171 :
172  topoSet
173  (
174  findIOobject(runTime, name, IOobject::NO_READ, w),
175  labels
176  )
177 {}
178 
179 
180 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
181 
182 Foam::label Foam::cellSet::maxSize(const polyMesh& mesh) const
183 {
184  return mesh.nCells();
185 }
186 
187 
189 {
190  updateLabels(morphMap.reverseCellMap());
191 }
192 
193 
195 {
196  labelHashSet& labels = *this;
197 
198  boolList contents(map.nOldCells(), false);
199 
200  for (const label celli : labels)
201  {
202  contents.set(celli);
203  }
204 
205  map.distributeCellData(contents);
206 
207  // The new length
208  const label len = contents.size();
209 
210  // Count
211  label n = 0;
212  for (label i=0; i < len; ++i)
213  {
214  if (contents.test(i))
215  {
216  ++n;
217  }
218  }
219 
220  // Update labelHashSet
221 
222  labels.clear();
223  labels.resize(2*n);
224 
225  for (label i=0; i < len; ++i)
226  {
227  if (contents.test(i))
228  {
229  labels.set(i);
230  }
231  }
232 }
233 
234 
236 (
237  Ostream& os,
238  const primitiveMesh& mesh,
239  const label maxLen
240 ) const
241 {
243 }
244 
245 
246 // ************************************************************************* //
Foam::topoSet::writeDebug
void writeDebug(Ostream &os, const label maxElem, topoSet::const_iterator &iter, label &elemI) const
Write part of contents nicely formatted. Prints labels only.
Definition: topoSet.C:224
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::mapDistributePolyMesh::distributeCellData
void distributeCellData(List< T > &lst) const
Distribute list of cell data.
Definition: mapDistributePolyMesh.H:256
mapPolyMesh.H
Foam::cellSet::writeDebug
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition: cellSet.C:236
polyMesh.H
Foam::HashSet< label, Hash< label > >
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::IOobject::writeOption
writeOption
Enumeration defining the write options.
Definition: IOobject.H:192
mapDistributePolyMesh.H
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::primitiveMesh::nCells
label nCells() const noexcept
Number of mesh cells.
Definition: primitiveMeshI.H:96
Foam::check
static void check(const int retVal, const char *what)
Definition: ptscotchDecomp.C:80
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:63
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::cellSet::distribute
virtual void distribute(const mapDistributePolyMesh &map)
Update any stored data for mesh redistribution.
Definition: cellSet.C:194
Time.H
Foam::mapPolyMesh::reverseCellMap
const labelList & reverseCellMap() const
Reverse cell map.
Definition: mapPolyMesh.H:532
Foam::primitiveMesh::cellCentres
const vectorField & cellCentres() const
Definition: primitiveMeshCellCentresAndVols.C:84
Foam::cellSet::updateMesh
virtual void updateMesh(const mapPolyMesh &morphMap)
Update any stored data for new labels.
Definition: cellSet.C:188
Foam::cellSet::maxSize
virtual label maxSize(const polyMesh &mesh) const
Return max index+1.
Definition: cellSet.C:182
Foam::List< bool >
Foam::UList< label >
Foam::List::set
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type set(const label i, bool val=true)
A bitSet::set() method for a list of bool.
Definition: List.H:341
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
cellSet.H
Foam::IOobject::readOption
readOption
Enumeration defining the read options.
Definition: IOobject.H:183
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::mapDistributePolyMesh
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Definition: mapDistributePolyMesh.H:66
Foam::mapDistributePolyMesh::nOldCells
label nOldCells() const
Number of cells in mesh before distribution.
Definition: mapDistributePolyMesh.H:187
Foam::IOobject::NO_READ
Definition: IOobject.H:188
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::primitiveMesh
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:78