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-2021 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
48:
49 baseMesh_(baseMesh),
50 subsetter_(baseMesh),
51 exposedPatchId_(-1),
52 type_(subsetType::NONE),
53 name_(),
54 names_(),
55 selectedCells_()
56{}
57
58
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
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
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_()
123{
124 correct();
125}
126
127
128// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
129
131{
132 fvMeshSubsetProxy::clearOut();
133
134 if (!zoneNames.empty())
135 {
136 type_ = subsetType::ZONES;
137 names_ = zoneNames;
138 correct();
139 }
140}
141
142
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_);
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 returnReduce(changed, orOp<bool>());
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 (
222 meshState == polyMesh::TOPO_CHANGE
223 || meshState == polyMesh::TOPO_PATCH_CHANGE
224 )
225 {
226 correct(true);
227 }
228
229 return meshState;
230}
231
232
233// ************************************************************************* //
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:116
void resize(const label numElem, const unsigned int val=0u)
Reset addressable list size, does not shrink the allocated size.
Definition: PackedListI.H:409
void clearStorage()
Clear the list and delete storage.
Definition: PackedListI.H:520
virtual void correct()
Solve the turbulence equations and correct the turbulence viscosity.
T & first()
Return the first element of the list.
Definition: UListI.H:202
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
void set(const bitSet &bitset)
Set specified bits from another bitset.
Definition: bitSetI.H:590
void transfer(bitSet &bitset)
Definition: bitSetI.H:560
A collection of cell labels.
Definition: cellSet.H:54
Simple proxy for holding a mesh, or mesh-subset. The subMeshes are currently limited to cellSet or ce...
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.
void clear()
Reset subMesh and all maps.
Definition: fvMeshSubset.C:481
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:91
@ TOPO_PATCH_CHANGE
Definition: polyMesh.H:95
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
A class for handling words, derived from Foam::string.
Definition: word.H:68
thermo correct()
messageStream Info
Information stream (stdout output on master, null elsewhere)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
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.