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 -------------------------------------------------------------------------------
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_.reset(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 // ************************************************************************* //
dictionary dict
unsigned int count(const bool on=true) const
Count number of bits set.
Definition: bitSetI.H:426
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Add elements to current set.
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:666
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
const fvMesh & baseMesh() const noexcept
Original mesh.
Definition: fvMeshSubsetI.H:23
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
defineTypeNameAndDebug(zoneSubSet, 0)
dynamicFvMesh & mesh
void reset()
Reset subMesh and all maps. Same as clear()
Definition: fvMeshSubset.C:485
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
int debug
Static debugging option.
Info<< "Predicted p max-min : "<< max(p).value()<< " "<< min(p).value()<< endl;rho==max(psi *p+alphal *rhol0+((alphav *psiv+alphal *psil) - psi) *pSat, rhoMin);# 1 "/home/chef2/andy/OpenFOAM/release/v2312/OpenFOAM-v2312/applications/solvers/multiphase/cavitatingFoam/alphavPsi.H" 1{ alphav=clamp((rho - rholSat)/(rhovSat - rholSat), zero_one{});alphal=1.0 - alphav;Info<< "max-min alphav: "<< max(alphav).value()<< " "<< min(alphav).value()<< endl;psiModel-> correct()
Definition: pEqn.H:63
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition: polyMesh.H:678
messageStream Info
Information stream (stdout output on master, null elsewhere)
bitSet selection(const labelUList &zoneIds) const
Return all elements (cells, faces, points) contained in the listed zones.
Definition: ZoneMesh.C:706
void clearStorage()
Clear the list and delete storage.
Definition: PackedListI.H:566
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Namespace for OpenFOAM.
void clear()
Reset subMesh and all maps.
Definition: fvMeshSubset.C:473
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:225