vtkWriteUpdate.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) 2018-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 "vtkWrite.H"
29 #include "cellBitSet.H"
30 #include "processorPolyPatch.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 bool Foam::functionObjects::vtkWrite::updateSubset
35 (
36  fvMeshSubset& subsetter
37 ) const
38 {
39  if (selection_.empty())
40  {
41  return false;
42  }
43 
44  bitSet selectedCells
45  (
46  cellBitSet::select(subsetter.baseMesh(), selection_)
47  );
48 
49  subsetter.reset(selectedCells);
50 
51  return true;
52 }
53 
54 
55 Foam::labelList Foam::functionObjects::vtkWrite::getSelectedPatches
56 (
57  const polyBoundaryMesh& patches
58 ) const
59 {
60  DynamicList<label> patchIDs(patches.size());
61 
62  wordRes::filter patchFilter(selectPatches_, blockPatches_);
63 
64  for (const polyPatch& pp : patches)
65  {
66  if (isType<emptyPolyPatch>(pp))
67  {
68  continue;
69  }
70  else if (isA<processorPolyPatch>(pp))
71  {
72  break; // No processor patches
73  }
74 
75  if (patchFilter(pp.name()))
76  {
77  patchIDs.append(pp.index());
78  }
79  }
80 
81  return patchIDs.shrink();
82 }
83 
84 
85 bool Foam::functionObjects::vtkWrite::update()
86 {
87  if
88  (
89  meshState_ == polyMesh::UNCHANGED
90  && (meshes_.size() == meshSubsets_.size())
91  && (meshes_.size() == vtuMappings_.size())
92  )
93  {
94  return false;
95  }
96 
97  meshSubsets_.resize(meshes_.size());
98  vtuMappings_.resize(meshes_.size());
99 
100  label regioni = 0;
101  for (const word& regionName : meshes_.sortedToc())
102  {
103  const fvMesh& mesh = *(meshes_[regionName]);
104 
105  if (meshSubsets_.set(regioni))
106  {
107  meshSubsets_[regioni].clear();
108  }
109  else
110  {
111  // Mesh subsetting, or pass through
112  meshSubsets_.set(regioni, new fvMeshSubset(mesh));
113  }
114 
115  if (vtuMappings_.set(regioni))
116  {
117  // Trigger change for vtk cells too
118  vtuMappings_[regioni].clear();
119  }
120  else
121  {
122  // VTU sizing and decomposition information
123  vtuMappings_.set
124  (
125  regioni,
126  new vtk::vtuCells(writeOpts_, decompose_)
127  );
128  }
129 
130  ++regioni;
131  }
132 
133  regioni = 0;
134  for (auto& subsetter : meshSubsets_)
135  {
136  updateSubset(subsetter);
137  vtuMappings_[regioni].reset(subsetter.mesh());
138  ++regioni;
139  }
140 
141  meshState_ = polyMesh::UNCHANGED;
142  return true;
143 }
144 
145 
146 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
147 
148 bool Foam::functionObjects::vtkWrite::readSelection(const dictionary& dict)
149 {
150  meshSubsets_.clear();
151  vtuMappings_.clear();
152  meshState_ = polyMesh::TOPO_CHANGE;
153 
154  // All possible meshes
155  meshes_ = time_.lookupClass<fvMesh>();
156 
157  selectRegions_.clear();
158  dict.readIfPresent("regions", selectRegions_);
159 
160  if (selectRegions_.empty())
161  {
162  selectRegions_.resize(1);
163  selectRegions_.first() =
164  dict.getOrDefault<word>("region", polyMesh::defaultRegion);
165  }
166 
167  // Restrict to specified meshes
168  meshes_.filterKeys(selectRegions_);
169 
170  if (meshes_.empty())
171  {
173  << "No mesh regions selected for function object " << name()
174  << nl;
175  }
176 
177  selectPatches_.clear();
178  dict.readIfPresent("patches", selectPatches_);
179 
180  blockPatches_.clear();
181  dict.readIfPresent("excludePatches", blockPatches_);
182 
183  selectFields_.clear();
184  dict.readEntry("fields", selectFields_);
185 
186  blockFields_.clear();
187  dict.readIfPresent("excludeFields", blockFields_);
188 
189  // Actions to define selection
190  selection_ = dict.subOrEmptyDict("selection");
191 
192  return true;
193 }
194 
197 {
198  meshState_ = polyMesh::TOPO_CHANGE;
199 }
200 
201 
203 {
204  // Only move to worse states
205  if (meshState_ == polyMesh::UNCHANGED)
206  {
207  meshState_ = polyMesh::POINTS_MOVED;
208  }
209 }
210 
211 
212 // ************************************************************************* //
dictionary dict
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:157
Foam::word regionName(Foam::polyMesh::defaultRegion)
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:52
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:397
static bitSet select(const polyMesh &mesh, const dictionary &dict, const bool verbosity=false)
Return a cell selection according to the dictionary specification of actions.
Definition: cellBitSet.C:90
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
#define WarningInFunction
Report a warning using Foam::Warning.
const polyBoundaryMesh & patches
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:73
virtual void movePoints(const polyMesh &mesh)
Update for mesh point-motion.