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