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-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 "ensightWrite.H"
29 #include "dictionary.H"
30 #include "cellBitSet.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 bool Foam::functionObjects::ensightWrite::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 bool Foam::functionObjects::ensightWrite::update()
56 {
57  if (meshState_ == polyMesh::UNCHANGED)
58  {
59  return false;
60  }
61 
62  // Even if selection doesn't nominally change, a new subMesh is built.
63  // Must update the reference for ensightMesh
64  if (meshSubset_.hasSubMesh())
65  {
66  ensMesh_.clear();
67  meshSubset_.clear();
68  }
69  // Probably not needed...
74 
75  updateSubset(meshSubset_);
76 
77  if (!ensMesh_)
78  {
79  ensMesh_.reset(new ensightMesh(meshSubset_.mesh(), writeOpts_));
80  }
81  else if (ensMesh_->needsUpdate())
82  {
83  ensMesh_->correct();
84  }
85 
86  meshState_ = polyMesh::UNCHANGED;
87  return true;
88 }
89 
90 
91 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
92 
93 bool Foam::functionObjects::ensightWrite::readSelection(const dictionary& dict)
94 {
95  // Ensure consistency
96  ensMesh_.clear();
97 
98  meshSubset_.clear();
99  meshState_ = polyMesh::TOPO_CHANGE;
100 
101  selectFields_.clear();
102  dict.readEntry("fields", selectFields_);
103  selectFields_.uniq();
104 
105  blockFields_.clear();
106  dict.readIfPresent("excludeFields", blockFields_);
107  blockFields_.uniq();
108 
109  // Actions to define selection
110  selection_ = dict.subOrEmptyDict("selection");
111 
112  return true;
113 }
114 
117 {
118  meshState_ = polyMesh::TOPO_CHANGE;
119 }
120 
121 
123 {
124  // Only move to worse states
125  if (meshState_ == polyMesh::UNCHANGED)
126  {
127  meshState_ = polyMesh::POINTS_MOVED;
128  }
129 }
130 
131 
132 // ************************************************************************* //
dictionary dict
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:157
virtual void movePoints(const polyMesh &mpm)
Update for mesh point-motion.
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.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74