fvMeshSubsetter.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) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2015-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "fvMeshSubsetter.H"
30#include "mapPolyMesh.H"
31#include "polyTopoChange.H"
32#include "removeCells.H"
33
34// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
35
36namespace Foam
37{
38
39// Helper: extract cells-to-remove from cells-to-keep
41(
42 const label nCells,
43 const bitSet& selectedCells
44)
45{
46 // Work on a copy
47 bitSet cellsToRemove(selectedCells);
48
49 // Ensure we have the full range
50 cellsToRemove.resize(nCells, false);
51
52 // Invert the selection
53 cellsToRemove.flip();
54
55 return cellsToRemove;
56}
57
58
59// Helper: extract cells-to-remove from cells-to-keep
61(
62 const label nCells,
63 const label regioni,
64 const labelUList& regions
65)
66{
68 (
69 nCells,
70 regioni,
71 regions,
72 false // on=false: invert return cells to remove
73 );
74}
75
76} // End namespace Foam
77
78
79// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
80
81void Foam::fvMeshSubsetter::removeCellsImpl
82(
83 const bitSet& cellsToRemove,
84 const labelList& exposedFaces,
85 const labelList& patchIDs,
86 const bool syncPar
87)
88{
89 // Clear out all existing maps
90 clear();
91
92 // Mesh changing engine.
93 polyTopoChange meshMod(baseMesh());
94
95 removeCells cellRemover(baseMesh(), syncPar);
96
97 cellRemover.setRefinement
98 (
99 cellsToRemove,
100 exposedFaces,
101 patchIDs,
102 meshMod
103 );
104
105 // Create mesh, return map from old to new mesh.
106 autoPtr<fvMesh> newMeshPtr;
107 autoPtr<mapPolyMesh> map = meshMod.makeMesh
108 (
109 newMeshPtr,
110 IOobject
111 (
112 baseMesh().name(),
113 baseMesh().time().timeName(),
114 baseMesh().time(),
115 IOobject::READ_IF_PRESENT, // read fv* if present
117 ),
118 baseMesh(),
119 syncPar
120 );
121
122 reset
123 (
124 std::move(newMeshPtr),
125 labelList(map().pointMap()),
126 labelList(map().faceMap()),
127 labelList(map().cellMap()),
128 identity(baseMesh().boundaryMesh().size())
129 );
130}
131
132
133// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
134
136(
137 const bitSet& selectedCells,
138 const bool syncPar
139) const
140{
141 return
142 Foam::removeCells(baseMesh(), syncPar).getExposedFaces
143 (
144 invertCellSelection(baseMesh().nCells(), selectedCells)
145 );
146}
147
148
150(
151 const label regioni,
152 const labelUList& regions,
153 const bool syncPar
154) const
155{
156 return
157 Foam::removeCells(baseMesh(), syncPar).getExposedFaces
158 (
159 invertCellSelection(baseMesh().nCells(), regioni, regions)
160 );
161}
162
163
165(
166 const bitSet& selectedCells,
167 const labelList& exposedFaces,
168 const labelList& patchIDs,
169 const bool syncPar
170)
171{
172 removeCellsImpl
173 (
174 invertCellSelection(baseMesh().nCells(), selectedCells),
175 exposedFaces,
176 patchIDs,
177 syncPar
178 );
179}
180
181
183(
184 const label regioni,
185 const labelList& regions,
186 const labelList& exposedFaces,
187 const labelList& patchIDs,
188 const bool syncCouples
189)
190{
191 removeCellsImpl
192 (
193 invertCellSelection(baseMesh().nCells(), regioni, regions),
194 exposedFaces,
195 patchIDs,
196 syncCouples
197 );
198}
199
200
201// ************************************************************************* //
void resize(const label numElem, const unsigned int val=0u)
Reset addressable list size, does not shrink the allocated size.
Definition: PackedListI.H:409
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
void flip()
Invert all bits in the addressable region.
Definition: bitSetI.H:634
const fvMesh & baseMesh() const noexcept
Original mesh.
Definition: fvMeshSubsetI.H:30
const labelList & faceMap() const
Return face map.
Definition: fvMeshSubsetI.H:72
const labelList & cellMap() const
Return cell map.
Definition: fvMeshSubsetI.H:91
const labelList & pointMap() const
Return point map.
Definition: fvMeshSubsetI.H:64
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
labelList getExposedFaces(const bitSet &selectedCells, const bool syncPar=true) const
Get labels of exposed faces.
void setCellSubset(const bitSet &selectedCells, const labelList &exposedFaces, const labelList &patchIDs, const bool syncPar=true)
For every exposed face (from above getExposedFaces)
Given list of cells to remove, insert all the topology changes.
Definition: removeCells.H:64
labelList getExposedFaces(const bitSet &removedCell) const
Get labels of faces exposed after cells removal.
Definition: removeCells.C:84
word timeName
Definition: getTimeIndex.H:3
bitSet create(const label n, const labelHashSet &locations, const bool on=true)
Create a bitSet with length n with the specified on locations.
Definition: BitOps.C:212
Namespace for OpenFOAM.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
Definition: labelList.C:38
List< label > labelList
A List of labels.
Definition: List.H:66
static bitSet invertCellSelection(const label nCells, const bitSet &selectedCells)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59