vtkMesh.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::vtkMesh
26 
27 Description
28  Encapsulation of VTK mesh data. Holds mesh or meshsubset and
29  polyhedral-cell decomposition on it.
30 
31 SourceFiles
32  vtkMesh.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef vtkMesh_H
37 #define vtkMesh_H
38 
39 #include "vtkTopo.H"
40 #include "fvMeshSubset.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 // Forward declaration of classes
48 class Time;
49 
50 /*---------------------------------------------------------------------------*\
51  Class vtkMesh Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class vtkMesh
55 {
56  // Private Data
57 
58  //- Reference to mesh
59  fvMesh& baseMesh_;
60 
61  //- Subsetting engine
62  fvMeshSubset subsetter_;
63 
64  //- Cell types to retain as polyhedra
65  const vtkTopo::vtkPolyhedra polyhedra_;
66 
67  //- Current cellSet (or empty)
68  const word setName_;
69 
70  //- Current decomposition of topology
71  mutable autoPtr<vtkTopo> topoPtr_;
72 
73 
74 public:
75 
76  // Constructors
77 
78  //- Construct from components
79  vtkMesh
80  (
83  const word& setName = word::null
84  );
85 
86  //- Disallow default bitwise copy construction
87  vtkMesh(const vtkMesh&) = delete;
88 
89 
90  // Member Functions
91 
92  // Access
93 
94  //- Whole mesh
95  const fvMesh& baseMesh() const
96  {
97  return baseMesh_;
98  }
99 
100  //- Subsetting engine
101  const fvMeshSubset& subsetter() const
102  {
103  return subsetter_;
104  }
105 
106  //- Check if running subMesh
107  bool useSubMesh() const
108  {
109  return setName_.size();
110  }
111 
112  //- VTK topology
113  const vtkTopo& topo() const
114  {
115  if (topoPtr_.empty())
116  {
117  topoPtr_.reset(new vtkTopo(mesh(), polyhedra_));
118  }
119  return topoPtr_();
120  }
121 
122  //- Access either mesh or submesh
123  const fvMesh& mesh() const
124  {
125  if (useSubMesh())
126  {
127  return subsetter_.subMesh();
128  }
129  else
130  {
131  return baseMesh_;
132  }
133  }
134 
135  //- Number of field cells
136  label nFieldCells() const
137  {
138  return topo().cellTypes().size();
139  }
140 
141  //- Number of field points
142  label nFieldPoints() const
143  {
144  return mesh().nPoints() + topo().addPointCellLabels().size();
145  }
146 
147 
148  // Edit
149 
150  //- Read mesh
152 
153 
154  //- Map volume field (does in fact do very little interpolation;
155  // just copied from fvMeshSubset)
156  template<class GeoField>
157  tmp<GeoField> interpolate(const GeoField& fld) const
158  {
159  if (useSubMesh())
160  {
161  tmp<GeoField> subFld = subsetter_.interpolate(fld);
162  subFld.ref().rename(fld.name());
163  return subFld;
164  }
165  else
166  {
167  return fld;
168  }
169  }
170 
171 
172  // Member Operators
173 
174  //- Disallow default bitwise assignment
175  void operator=(const vtkMesh&) = delete;
176 };
177 
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 } // End namespace Foam
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 #endif
186 
187 // ************************************************************************* //
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
bool empty() const
Return true if the autoPtr is empty (ie, no pointer set)
Definition: autoPtrI.H:76
void reset(T *=nullptr)
If object pointer already set, delete object and set to given.
Definition: autoPtrI.H:114
Post-processing mesh subset tool. Given the original mesh and the list of selected cells,...
Definition: fvMeshSubset.H:74
const fvMesh & subMesh() const
Return reference to subset mesh.
static tmp< VolField< Type > > interpolate(const VolField< Type > &, const fvMesh &sMesh, const labelList &patchMap, const labelList &cellMap, const labelList &faceMap)
Map volume field.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:99
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: fvMesh.H:108
label nPoints() const
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
Encapsulation of VTK mesh data. Holds mesh or meshsubset and polyhedral-cell decomposition on it.
Definition: vtkMesh.H:54
const fvMesh & baseMesh() const
Whole mesh.
Definition: vtkMesh.H:94
const fvMeshSubset & subsetter() const
Subsetting engine.
Definition: vtkMesh.H:100
const fvMesh & mesh() const
Access either mesh or submesh.
Definition: vtkMesh.H:122
bool useSubMesh() const
Check if running subMesh.
Definition: vtkMesh.H:106
label nFieldPoints() const
Number of field points.
Definition: vtkMesh.H:141
tmp< GeoField > interpolate(const GeoField &fld) const
Map volume field (does in fact do very little interpolation;.
Definition: vtkMesh.H:156
vtkMesh(fvMesh &baseMesh, const vtkTopo::vtkPolyhedra polyhedra=vtkTopo::vtkPolyhedra::none, const word &setName=word::null)
Construct from components.
label nFieldCells() const
Number of field cells.
Definition: vtkMesh.H:135
void operator=(const vtkMesh &)=delete
Disallow default bitwise assignment.
const vtkTopo & topo() const
VTK topology.
Definition: vtkMesh.H:112
fvMesh::readUpdateState readUpdate()
Read mesh.
Polyhedral cell decomposition for VTK.
Definition: vtkTopo.H:52
const labelList & cellTypes() const
Definition: vtkTopo.H:125
const labelList & addPointCellLabels() const
Definition: vtkTopo.H:130
vtkPolyhedra
Groups of cell types retain as polyhedra.
Definition: vtkTopo.H:59
A class for handling words, derived from string.
Definition: word.H:62
static const word null
An empty word.
Definition: word.H:77
gmvFile<< "tracers "<< particles.size()<< nl;{ pointField positions(particles.size());label particlei=0;forAllConstIter(Cloud< passiveParticle >, particles, iter) { positions[particlei++]=iter().position(mesh);} for(i=0;i< pTraits< point >::nComponents;i++) { forAll(positions, particlei) { gmvFile<< component(positions[particlei], i)<< ' ';} gmvFile<< nl;}}forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59