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-2019 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 "fvMeshSubsetProxy.H"
29 #include "cellSet.H"
30 #include "cellZone.H"
31 #include "Time.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
35 Foam::fvMeshSubsetProxy::fvMeshSubsetProxy(fvMesh& baseMesh)
36 :
37  baseMesh_(baseMesh),
38  subsetter_(baseMesh),
39  exposedPatchId_(-1),
40  type_(NONE),
41  name_(),
42  names_(),
43  selectedCells_()
44 {
45  if (useSubMesh())
46  {
47  correct();
48  }
49 }
50 
51 
52 Foam::fvMeshSubsetProxy::fvMeshSubsetProxy
53 (
54  fvMesh& baseMesh,
55  const subsetType type,
56  const word& selectionName,
57  label exposedPatchId
58 )
59 :
60  baseMesh_(baseMesh),
61  subsetter_(baseMesh),
62  exposedPatchId_(exposedPatchId),
63  type_(selectionName.empty() ? NONE : type),
64  name_(),
65  names_(),
66  selectedCells_()
67 {
68  if (type_ == ZONES)
69  {
70  // Populate wordRes for ZONES
71  names_.resize(1);
72  names_.first() = selectionName;
73  }
74  else if (type_ != NONE)
75  {
76  name_ = selectionName;
77  }
78 
79  if (useSubMesh())
80  {
81  correct();
82  }
83 }
84 
85 
86 Foam::fvMeshSubsetProxy::fvMeshSubsetProxy
87 (
88  fvMesh& baseMesh,
89  const wordRes& zoneNames,
90  label exposedPatchId
91 )
92 :
93  baseMesh_(baseMesh),
94  subsetter_(baseMesh),
95  exposedPatchId_(exposedPatchId),
96  type_(ZONES),
97  name_(),
98  names_(zoneNames),
99  selectedCells_()
100 {
101  if (useSubMesh())
102  {
103  correct();
104  }
105 }
106 
107 
108 Foam::fvMeshSubsetProxy::fvMeshSubsetProxy
109 (
110  fvMesh& baseMesh,
111  wordRes&& zoneNames,
112  label exposedPatchId
113 )
114 :
115  baseMesh_(baseMesh),
116  subsetter_(baseMesh),
117  exposedPatchId_(exposedPatchId),
118  type_(ZONES),
119  name_(),
120  names_(std::move(zoneNames)),
121  selectedCells_()
122 {
123  if (useSubMesh())
124  {
125  correct();
126  }
127 }
128 
129 
130 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
131 
133 {
134  if (type_ == NONE)
135  {
136  subsetter_.clear();
137  selectedCells_.clearStorage();
138  return false;
139  }
140 
141  const label nCells = baseMesh_.nCells();
142 
143  bitSet selectedCells;
144 
145  if (type_ == SET)
146  {
147  if (verbose)
148  {
149  Info<< "Subsetting mesh based on cellSet " << name_ << endl;
150  }
151 
152  cellSet cset(baseMesh_, name_);
153 
154  selectedCells.resize(nCells);
155  for (const label idx : cset)
156  {
157  selectedCells.set(idx);
158  }
159  }
160  else if (type_ == ZONE)
161  {
162  if (verbose)
163  {
164  Info<< "Subsetting mesh based on cellZone " << name_ << endl;
165  }
166 
167  selectedCells.resize(nCells);
168  selectedCells.set(baseMesh_.cellZones()[name_]);
169  }
170  else if (type_ == ZONES)
171  {
172  if (verbose)
173  {
174  Info<< "Subsetting mesh based on cellZones "
175  << flatOutput(names_) << endl;
176  }
177 
178  selectedCells = baseMesh_.cellZones().selection(names_);
179  }
180 
181 
182  const bool changed = (selectedCells_ != selectedCells);
183 
184  // Use as a cached value for next time
185  selectedCells_.transfer(selectedCells);
186 
187  if (changed || selectedCells_.empty())
188  {
189  subsetter_.setCellSubset(selectedCells_, exposedPatchId_);
190  }
191 
192  return returnReduce(changed, orOp<bool>());
193 }
194 
195 
197 {
198  const polyMesh::readUpdateState meshState = baseMesh_.readUpdate();
199 
200  if (meshState == polyMesh::POINTS_MOVED)
201  {
202  if (correct(true))
203  {
204  // The cellSet/cellZone changed on POINTS_MOVED,
205  // treat like TOPO_CHANGE
206  return polyMesh::TOPO_CHANGE;
207  }
208  }
209  else if
210  (
211  meshState == polyMesh::TOPO_CHANGE
212  || meshState == polyMesh::TOPO_PATCH_CHANGE
213  )
214  {
215  correct(true);
216  }
217 
218  return meshState;
219 }
220 
221 
222 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::polyMesh::POINTS_MOVED
Definition: polyMesh.H:93
Foam::bitSet::set
void set(const bitSet &bitset)
Set specified bits from another bitset.
Definition: bitSetI.H:574
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::PackedList::resize
void resize(const label nElem, const unsigned int val=0u)
Reset addressable list size, does not shrink the allocated size.
Definition: PackedListI.H:399
Foam::fvMeshSubsetProxy::subsetType
subsetType
Internal bookkeeping for subset type.
Definition: fvMeshSubsetProxy.H:62
Foam::fvMeshSubsetProxy::useSubMesh
bool useSubMesh() const
Check if a sub-mesh is being used.
Definition: fvMeshSubsetProxy.H:156
Foam::polyMesh::TOPO_PATCH_CHANGE
Definition: polyMesh.H:95
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
correct
fvOptions correct(rho)
Foam::polyMesh::TOPO_CHANGE
Definition: polyMesh.H:94
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
Foam::flatOutput
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:217
fvMeshSubsetProxy.H
Foam::cellSet
A collection of cell labels.
Definition: cellSet.H:51
Foam::polyMesh::readUpdateState
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:90
Time.H
cellZone.H
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
cellSet.H
Foam::fvMeshSubsetProxy::correct
bool correct(bool verbose=false)
Update of mesh subset.
Definition: fvMeshSubsetProxy.C:132
Foam::orOp
Definition: ops.H:234
Foam::fvMeshSubsetProxy::readUpdate
polyMesh::readUpdateState readUpdate()
Read mesh. Correct on topo-change.
Definition: fvMeshSubsetProxy.C:196
Foam::bitSet::transfer
void transfer(bitSet &bitset)
Definition: bitSetI.H:544