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-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
34namespace Foam
35{
36namespace Detail
37{
39}
40}
41
42
43// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
44
45bool 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_.reset(selectedCells.addressing());
99
100 return true;
101}
102
103
104// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
105
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
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// ************************************************************************* //
void clearStorage()
Clear the list and delete storage.
Definition: PackedListI.H:520
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
bitSet selection(const labelUList &zoneIds) const
Definition: ZoneMesh.C:605
unsigned int count(const bool on=true) const
Count number of bits set.
Definition: bitSetI.H:500
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
const fvMesh & baseMesh() const noexcept
Original mesh.
Definition: fvMeshSubsetI.H:30
void clear()
Reset subMesh and all maps.
Definition: fvMeshSubset.C:481
void reset()
Reset subMesh and all maps. Same as clear()
Definition: fvMeshSubset.C:493
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition: polyMesh.H:504
@ ADD
Add elements to current set.
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:215
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
dictionary dict