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-2023 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 fvMesh& mesh : meshes_)
102  {
103  if (meshSubsets_.set(regioni))
104  {
105  meshSubsets_[regioni].clear();
106  }
107  else
108  {
109  // Mesh subsetting, or pass through
110  meshSubsets_.set(regioni, new fvMeshSubset(mesh));
111  }
112 
113  if (vtuMappings_.set(regioni))
114  {
115  // Trigger change for vtk cells too
116  vtuMappings_[regioni].clear();
117  }
118  else
119  {
120  // VTU sizing and decomposition information
121  vtuMappings_.set
122  (
123  regioni,
124  new vtk::vtuCells(writeOpts_, decompose_)
125  );
126  }
127 
128  ++regioni;
129  }
130 
131  regioni = 0;
132  for (auto& subsetter : meshSubsets_)
133  {
134  updateSubset(subsetter);
135  vtuMappings_[regioni].reset(subsetter.mesh());
136  ++regioni;
137  }
138 
139  meshState_ = polyMesh::UNCHANGED;
140  return true;
141 }
142 
143 
144 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
145 
146 bool Foam::functionObjects::vtkWrite::readSelection(const dictionary& dict)
147 {
148  meshSubsets_.clear();
149  vtuMappings_.clear();
150  meshes_.clear();
151  meshState_ = polyMesh::TOPO_CHANGE;
152 
153  selectRegions_.clear();
154  dict.readIfPresent("regions", selectRegions_);
155 
156  if (selectRegions_.empty())
157  {
158  selectRegions_.resize(1);
159  selectRegions_.front() =
160  dict.getOrDefault<word>("region", polyMesh::defaultRegion);
161  }
162 
163  // Restrict to specified meshes
164  meshes_ = time_.csorted<fvMesh>(selectRegions_);
165 
166  if (meshes_.empty())
167  {
169  << "No mesh regions selected for function object "
170  << name() << nl;
171  }
172 
173  selectPatches_.clear();
174  dict.readIfPresent("patches", selectPatches_);
175 
176  blockPatches_.clear();
177  dict.readIfPresent("excludePatches", blockPatches_);
178 
179  selectFields_.clear();
180  dict.readEntry("fields", selectFields_);
181 
182  blockFields_.clear();
183  dict.readIfPresent("excludeFields", blockFields_);
184 
185  // Actions to define selection
186  selection_ = dict.subOrEmptyDict("selection");
187 
188  return true;
189 }
190 
193 {
194  meshState_ = polyMesh::TOPO_CHANGE;
195 }
196 
197 
199 {
200  // Only move to worse states
201  if (meshState_ == polyMesh::UNCHANGED)
202  {
203  meshState_ = polyMesh::POINTS_MOVED;
204  }
205 }
206 
207 
208 // ************************************************************************* //
const labelList patchIDs(pbm.indices(polyPatchNames, true))
dictionary dict
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:406
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:84
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:75
virtual void movePoints(const polyMesh &mesh)
Update for mesh point-motion.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())