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 -------------------------------------------------------------------------------
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 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 void 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 
47 Foam::fvMeshSubsetProxy::fvMeshSubsetProxy(fvMesh& baseMesh)
48 :
49  baseMesh_(baseMesh),
50  subsetter_(baseMesh),
51  exposedPatchId_(-1),
52  type_(subsetType::NONE),
53  name_(),
54  names_(),
55  selectedCells_()
56 {}
57 
58 
59 Foam::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 
90 Foam::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 
109 Foam::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_()
123 {
124  correct();
125 }
126 
127 
128 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
129 
130 void Foam::fvMeshSubsetProxy::resetZones(const wordRes& zoneNames)
131 {
132  fvMeshSubsetProxy::clearOut();
133 
134  if (!zoneNames.empty())
135  {
136  type_ = subsetType::ZONES;
137  names_ = zoneNames;
138  correct();
139  }
140 }
141 
142 
143 bool 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_);
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
217  return polyMesh::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:160
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:666
T & first()
Access first element of the list, position [0].
Definition: UList.H:853
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
void resetZones(const wordRes &zoneNames)
Define the zones selection, subset the mesh accordingly.
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:137
A class for handling words, derived from Foam::string.
Definition: word.H:63
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
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
polyMesh::readUpdateState readUpdate()
Read mesh. Correct on topo-change.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
bool correct(bool verbose=false)
Update of mesh subset.
messageStream Info
Information stream (stdout output on master, null elsewhere)
void clearStorage()
Clear the list and delete storage.
Definition: PackedListI.H:566
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:90
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
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