ensightWriteUpdate.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-2020 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 "ensightWrite.H"
29 #include "dictionary.H"
30 #include "cellBitSet.H"
31 #include "topoSetCellSource.H"
32 
33 // * * * * * * * * * * * * * * Local Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  // A limited selection of actions
38  const Enum<topoSetSource::setAction> actionNames
39  ({
40  { topoSetSource::NEW, "use" }, // Reuse NEW for "use" action name
41  { topoSetSource::ADD, "add" },
42  { topoSetSource::SUBTRACT, "subtract" },
43  { topoSetSource::SUBSET, "subset" },
44  { topoSetSource::INVERT, "invert" },
45  });
46 }
47 
48 
49 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 
51 bool Foam::functionObjects::ensightWrite::updateSubset
52 (
53  fvMeshSubset& subsetter
54 ) const
55 {
56  if (selection_.empty())
57  {
58  return false;
59  }
60 
61  const fvMesh& mesh = subsetter.baseMesh();
62 
63  // Start with all cells unselected
64  cellBitSet cellsToSelect(mesh, false);
65 
66  // Execute all actions
67  for (const entry& dEntry : selection_)
68  {
69  if (!dEntry.isDict())
70  {
72  << "Ignoring non-dictionary entry "
73  << dEntry << endl;
74  continue;
75  }
76 
77  const dictionary& dict = dEntry.dict();
78 
79  const auto action = actionNames.get("action", dict);
80 
81  // Handle manually
82  if (action == topoSetSource::INVERT)
83  {
84  cellsToSelect.invert(mesh.nCells());
85  continue;
86  }
87 
88  auto source = topoSetCellSource::New
89  (
90  dict.get<word>("source"),
91  mesh,
92  dict.optionalSubDict("sourceInfo")
93  );
94  source->verbose(false);
95 
96  switch (action)
97  {
98  case topoSetSource::NEW: // "use"
99  case topoSetSource::ADD:
101  if (topoSetSource::NEW == action)
102  {
103  // "use": only use this selection (clear + ADD)
104  // NEW is handled like ADD in applyToSet()
105  cellsToSelect.reset();
106  }
107  source->applyToSet(action, cellsToSelect);
108  break;
109 
111  {
112  cellBitSet other(mesh, false);
113  source->applyToSet(topoSetSource::NEW, other);
114 
115  cellsToSelect.subset(other);
116  }
117  break;
118 
119  default:
120  // Should already have been caught
122  << "Ignoring unhandled action '"
123  << actionNames[action] << "'" << endl;
124  break;
125  }
126  }
127 
128  subsetter.setCellSubset(cellsToSelect.addressing());
129 
130  return true;
131 }
132 
133 
134 bool Foam::functionObjects::ensightWrite::update()
135 {
136  if (meshState_ == polyMesh::UNCHANGED)
137  {
138  return false;
139  }
140 
141  // This is heavy-handed, but with a bounding-box limited sub-mesh,
142  // we don't readily know if the updates affect the subsetted mesh.
143 
144  // if (meshSubset_.hasSubMesh())
145  // {
146  // ensMesh_.clear();
147  // meshSubset_.clear();
148  // }
149  // else if (ensMesh_)
150  // {
151  // ensMesh_->expire();
152  // }
153 
154  meshSubset_.clear();
155 
156  updateSubset(meshSubset_);
157 
158  meshState_ = polyMesh::UNCHANGED;
159 
160  if (!ensMesh_)
161  {
162  ensMesh_.reset(new ensightMesh(meshSubset_.mesh(), writeOpts_));
163  }
164  else if (ensMesh_->needsUpdate())
165  {
166  ensMesh_->correct();
167  }
168 
169  return true;
170 }
171 
172 
173 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
174 
175 bool Foam::functionObjects::ensightWrite::readSelection(const dictionary& dict)
176 {
177  // Ensure consistency
178  ensMesh_.clear();
179 
180  meshSubset_.clear();
181  meshState_ = polyMesh::TOPO_CHANGE;
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 // ************************************************************************* //
Foam::topoSetSource::ADD
Add elements to current set.
Definition: topoSetSource.H:103
cellBitSet.H
Foam::polyMesh::POINTS_MOVED
Definition: polyMesh.H:93
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:104
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::polyMesh::UNCHANGED
Definition: polyMesh.H:92
Foam::polyMesh::TOPO_CHANGE
Definition: polyMesh.H:94
Foam::topoSetCellSource::New
static autoPtr< topoSetCellSource > New(const word &sourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected source type.
Definition: topoSetCellSource.C:62
topoSetCellSource.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::topoSetSource::SUBSET
Union of elements with current set.
Definition: topoSetSource.H:108
Foam::functionObjects::ensightWrite::updateMesh
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
Definition: ensightWriteUpdate.C:194
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::topoSetSource::SUBTRACT
Subtract elements from current set.
Definition: topoSetSource.H:105
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
dictionary.H
Foam::topoSetSource::INVERT
Invert the elements in the current set.
Definition: topoSetSource.H:109
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::actionNames
const Enum< topoSetSource::setAction > actionNames({ { topoSetSource::NEW, "use" }, { topoSetSource::ADD, "add" }, { topoSetSource::SUBTRACT, "subtract" }, { topoSetSource::SUBSET, "subset" }, { topoSetSource::INVERT, "invert" }, })
ensightWrite.H
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::functionObjects::ensightWrite::movePoints
virtual void movePoints(const polyMesh &mpm)
Update for mesh point-motion.
Definition: ensightWriteUpdate.C:200