initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / applications / utilities / postProcessing / dataConversion / foamToVTK / vtkMesh.H
blob315a36561b5be9257846bf30c6c2498ada7f0614
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::vtkMesh
28 Description
29     Encapsulation of VTK mesh data. Holds mesh or meshsubset and
30     polyhedral-cell decomposition on it.
32 SourceFiles
33     vtkMesh.C
35 \*---------------------------------------------------------------------------*/
37 #ifndef vtkMesh_H
38 #define vtkMesh_H
40 #include "vtkTopo.H"
41 #include "fvMeshSubset.H"
42 #include "pointMesh.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 namespace Foam
49 // Forward declaration of classes
50 class Time;
52 /*---------------------------------------------------------------------------*\
53                            Class vtkMesh Declaration
54 \*---------------------------------------------------------------------------*/
56 class vtkMesh
58     // Private data
60         //- Reference to mesh
61         fvMesh& baseMesh_;
63         //- Demand driven pointMesh
64         mutable autoPtr<pointMesh> pointMeshPtr_;
66         //- Subsetting engine + sub-fvMesh
67         fvMeshSubset subsetter_;
69         //- Current cellSet (or empty)
70         const word setName_;
72         //- Current decomposition of topology
73         mutable autoPtr<vtkTopo> topoPtr_;
77     // Private Member Functions
79         //- Disallow default bitwise copy construct
80         vtkMesh(const vtkMesh&);
82         //- Disallow default bitwise assignment
83         void operator=(const vtkMesh&);
86 public:
88     // Constructors
90         //- Construct from components
91         vtkMesh(fvMesh& baseMesh, const word& setName = "");
94     // Member Functions
96         // Access
98             //- whole mesh
99             const fvMesh& baseMesh() const
100             {
101                 return baseMesh_;
102             }
104             const pointMesh& basePointMesh() const
105             {
106                 if (!pointMeshPtr_.valid())
107                 {
108                     pointMeshPtr_.reset(new pointMesh(baseMesh_));
109                 }
110                 return pointMeshPtr_();
111             }
113             const fvMeshSubset& subsetter() const
114             {
115                 return subsetter_;
116             }
118             //- Check if running subMesh
119             bool useSubMesh() const
120             {
121                 return setName_.size() > 0;
122             }
124             //- topology
125             const vtkTopo& topo() const
126             {
127                 if (!topoPtr_.valid())
128                 {
129                     topoPtr_.reset(new vtkTopo(mesh()));
130                 }
131                 return topoPtr_();
132             }
134             //- Access either mesh or submesh
135             const fvMesh& mesh() const
136             {
137                 if (useSubMesh())
138                 {
139                     return subsetter_.subMesh();
140                 }
141                 else
142                 {
143                     return baseMesh_;
144                 }
145             }
147             //- Access either pointMesh of base or pointMesh of subset
148             const pointMesh& pMesh() const
149             {
150                 if (useSubMesh())
151                 {
152                     return subsetter_.subPointMesh();
153                 }
154                 else
155                 {
156                     return basePointMesh();
157                 }
158             }
160             //- Number of field cells
161             label nFieldCells() const
162             {
163                 return topo().cellTypes().size();
164             }
166             //- Number of field points
167             label nFieldPoints() const
168             {
169                 return pMesh().size() + topo().addPointCellLabels().size();
170             }
173         // Edit
175             //- Read mesh
176             polyMesh::readUpdateState readUpdate();
179             //- Map volume field (does in fact do very little interpolation;
180             //  just copied from fvMeshSubset)
181             template<class GeoField>
182             tmp<GeoField> interpolate(const GeoField& fld) const
183             {
184                 if (useSubMesh())
185                 {
186                     tmp<GeoField> subFld = subsetter_.interpolate(fld);
187                     subFld().rename(fld.name());
188                     return subFld;
189                 }
190                 else
191                 {
192                     return fld;
193                 }
194             }
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200 } // End namespace Foam
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 #endif
206 // ************************************************************************* //