Loading...
Searching...
No Matches
fvMeshSubsetProxy.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) 2016-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 "fvMeshSubsetProxy.H"
29#include "cellSet.H"
30#include "cellZone.H"
31#include "Time.H"
32
33// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34
35void Foam::fvMeshSubsetProxy::clearOut()
36{
37 subsetter_.clear();
38 type_ = subsetType::NONE;
39 name_.clear();
40 names_.clear();
41 selectedCells_.clearStorage();
42}
43
44
45// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46
47Foam::fvMeshSubsetProxy::fvMeshSubsetProxy(fvMesh& baseMesh)
48:
49 baseMesh_(baseMesh),
50 subsetter_(baseMesh),
51 exposedPatchId_(-1),
53 name_(),
54 names_(),
55 selectedCells_()
56{}
57
58
59Foam::fvMeshSubsetProxy::fvMeshSubsetProxy
60(
61 fvMesh& baseMesh,
62 const subsetType type,
63 const word& selectionName,
64 label exposedPatchId
65)
66:
67 baseMesh_(baseMesh),
68 subsetter_(baseMesh),
69 exposedPatchId_(exposedPatchId),
70 type_(selectionName.empty() ? subsetType::NONE : type),
71 name_(),
72 names_(),
73 selectedCells_()
74{
75 if (type_ == subsetType::ZONES)
76 {
77 // Populate wordRes for ZONES
78 names_.resize(1);
79 names_.first() = selectionName;
80 }
81 else if (type_ == subsetType::SET || type_ == subsetType::ZONE)
82 {
83 name_ = selectionName;
84 }
85
86 correct();
87}
88
89
90Foam::fvMeshSubsetProxy::fvMeshSubsetProxy
91(
92 fvMesh& baseMesh,
93 const wordRes& zoneNames,
94 label exposedPatchId
95)
96:
97 baseMesh_(baseMesh),
98 subsetter_(baseMesh),
99 exposedPatchId_(exposedPatchId),
100 type_(subsetType::ZONES),
101 name_(),
102 names_(zoneNames),
103 selectedCells_()
104{
105 correct();
106}
107
108
109Foam::fvMeshSubsetProxy::fvMeshSubsetProxy
110(
111 fvMesh& baseMesh,
112 wordRes&& zoneNames,
113 label exposedPatchId
114)
115:
116 baseMesh_(baseMesh),
117 subsetter_(baseMesh),
118 exposedPatchId_(exposedPatchId),
119 type_(subsetType::ZONES),
120 name_(),
121 names_(std::move(zoneNames)),
122 selectedCells_()
124 correct();
125}
126
127
128// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
129
130void Foam::fvMeshSubsetProxy::resetZones(const wordRes& zoneNames)
131{
132 fvMeshSubsetProxy::clearOut();
133
134 if (!zoneNames.empty())
135 {
137 names_ = zoneNames;
138 correct();
139 }
140}
141
142
143bool Foam::fvMeshSubsetProxy::correct(bool verbose)
144{
145 if (type_ == subsetType::NONE)
146 {
147 subsetter_.clear();
148 selectedCells_.clearStorage();
149 return false;
150 }
151
152 const label nCells = baseMesh_.nCells();
153
154 bitSet selectedCells;
155
156 if (type_ == subsetType::SET)
157 {
158 if (verbose)
159 {
160 Info<< "Subsetting mesh based on cellSet " << name_ << endl;
161 }
162
163 cellSet cset(baseMesh_, name_, IOobject::NO_REGISTER);
164
165 selectedCells.resize(nCells);
166 for (const label idx : cset)
167 {
168 selectedCells.set(idx);
169 }
170 }
171 else if (type_ == subsetType::ZONE)
172 {
173 if (verbose)
174 {
175 Info<< "Subsetting mesh based on cellZone " << name_ << endl;
176 }
177
178 selectedCells.resize(nCells);
179 selectedCells.set(baseMesh_.cellZones()[name_]);
180 }
181 else if (type_ == subsetType::ZONES)
182 {
183 if (verbose)
184 {
185 Info<< "Subsetting mesh based on cellZones "
186 << flatOutput(names_) << endl;
187 }
188
189 selectedCells = baseMesh_.cellZones().selection(names_);
190 }
191
192
193 const bool changed = (selectedCells_ != selectedCells);
194
195 // Use as a cached value for next time
196 selectedCells_.transfer(selectedCells);
197
198 if (changed || selectedCells_.empty())
199 {
200 subsetter_.reset(selectedCells_, exposedPatchId_);
201 }
202
203 return returnReduceOr(changed);
204}
205
206
208{
209 const polyMesh::readUpdateState meshState = baseMesh_.readUpdate();
210
211 if (meshState == polyMesh::POINTS_MOVED)
212 {
213 if (correct(true))
214 {
215 // The cellSet/cellZone changed on POINTS_MOVED,
216 // treat like TOPO_CHANGE
218 }
219 }
220 else if
221 (
224 )
225 {
226 correct(true);
227 }
228
229 return meshState;
230}
231
232
233// ************************************************************************* //
@ NO_REGISTER
Do not request registration (bool: false).
void resize(const label len)
Adjust allocated size of list.
Definition ListI.H:153
T & first()
Access first element of the list, position [0].
Definition UList.H:957
bool empty() const noexcept
True if List is empty (ie, size() is zero).
Definition UList.H:701
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition bitSet.H:61
void transfer(bitSet &bitset)
Transfer the contents of the argument list into this list and annul the argument list.
Definition bitSetI.H:468
A collection of cell labels.
Definition cellSet.H:50
const fvMesh & baseMesh() const noexcept
The entire base mesh.
const bitSet & selectedCells() const noexcept
The current cell selection, when subsetting is active.
void resetZones(const wordRes &zoneNames)
Define the zones selection, subset the mesh accordingly.
polyMesh::readUpdateState readUpdate()
Read mesh. Correct on topo-change.
subsetType
Internal bookkeeping for subset type.
@ ZONES
Subset with multiple cellZones.
@ ZONE
Subset with a cellZone.
@ SET
Subset with a cellSet.
bool correct(bool verbose=false)
Update of mesh subset.
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
Database for mesh data, solution data, solver performance and other reduced data.
Definition meshState.H:56
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition polyMesh.H:92
A List of wordRe with additional matching capabilities.
Definition wordRes.H:56
A class for handling words, derived from Foam::string.
Definition word.H:66
thermo correct()
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition FlatOutput.H:217