zoneSubSet.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) 2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "zoneSubSet.H"
29 #include "cellBitSet.H"
30 #include "haloToCell.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace Detail
37 {
39 }
40 }
41 
42 
43 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
44 
45 bool Foam::Detail::zoneSubSet::correct()
46 {
47  subsetter_.clear();
48  haloCells_.clearStorage();
49 
50  if (zoneMatcher_.empty())
51  {
52  return false;
53  }
54 
55  // Select named zones
56  cellBitSet selectedCells
57  (
58  subsetter_.baseMesh(),
59  subsetter_.baseMesh().cellZones().selection(zoneMatcher_)
60  );
61 
62  if (debug)
63  {
64  Pout<< "Subsetting "
65  << selectedCells.addressing().count()
66  << " cells based on cellZones "
67  << flatOutput(zoneMatcher_) << endl;
68  }
69 
70  if (nLayers_ > 0)
71  {
72  // Add halo layer(s)
73  haloToCell haloSource(subsetter_.baseMesh(), nLayers_);
74  haloSource.verbose(false);
75 
76  // Before adding halo cells
77  haloCells_ = selectedCells.addressing();
78 
79  haloSource.applyToSet(topoSetSource::ADD, selectedCells);
80 
81  // Halo cells: anything new, not in the original set
82  haloCells_ ^= selectedCells.addressing();
83  }
84 
85  if (debug)
86  {
87  const label nHalo = haloCells_.count();
88  const label nSubCell = selectedCells.addressing().count();
89 
90  Info<< " overall "
91  << returnReduce(nSubCell, sumOp<label>())
92  << " cells after adding " << nLayers_ << " layers with "
93  << returnReduce(nHalo, sumOp<label>())
94  << " halo cells"
95  << endl;
96  }
97 
98  subsetter_.setCellSubset(selectedCells.addressing());
99 
100  return true;
101 }
102 
103 
104 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
105 
106 Foam::Detail::zoneSubSet::zoneSubSet
107 (
108  const fvMesh& mesh,
109  const wordRes& zoneSelector,
110  const label nZoneLayers
111 )
112 :
113  subsetter_(mesh),
114  zoneMatcher_(zoneSelector),
115  nLayers_(nZoneLayers),
116  haloCells_()
117 {
118  correct();
119 }
120 
121 
122 Foam::Detail::zoneSubSet::zoneSubSet
123 (
124  const fvMesh& mesh,
125  const dictionary& dict
126 )
127 :
128  subsetter_(mesh),
129  zoneMatcher_(),
130  nLayers_(dict.getOrDefault<label>("nLayers", 0)),
131  haloCells_()
132 {
133  dict.readIfPresent("cellZones", zoneMatcher_);
134 
135  correct();
136 }
137 
138 
139 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::topoSetSource::ADD
Add elements to current set.
Definition: topoSetSource.H:103
cellBitSet.H
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
haloToCell.H
Foam::fvMeshSubset::setCellSubset
void setCellSubset(const bitSet &selectedCells, const label patchID=-1, const bool syncPar=true)
Define cell subset based on the selectedCells.
Definition: fvMeshSubset.C:558
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::Detail::defineTypeNameAndDebug
defineTypeNameAndDebug(zoneSubSet, 0)
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Foam::bitSet::count
unsigned int count(const bool on=true) const
Count number of bits set.
Definition: bitSetI.H:499
Foam::fvMeshSubset::clear
void clear()
Reset maps and subsetting.
Definition: fvMeshSubset.C:545
Foam::Detail::zoneSubSet
Definition: zoneSubSet.H:98
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::polyMesh::cellZones
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition: polyMesh.H:492
correct
fvOptions correct(rho)
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::flatOutput
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:216
Foam::fvMeshSubset::baseMesh
const fvMesh & baseMesh() const noexcept
Original mesh.
Definition: fvMeshSubsetI.H:30
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::PackedList::clearStorage
void clearStorage()
Clear the list and delete storage.
Definition: PackedListI.H:520
zoneSubSet.H
Foam::ZoneMesh::selection
bitSet selection(const labelUList &zoneIds) const
Definition: ZoneMesh.C:599