foamVtkVtuAdaptorI.H
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) 2016-2019 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 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29 
32 (
33  const fvMesh& mesh
34 ) const
35 {
36  // Convert OpenFOAM mesh vertices to VTK
37  auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
38 
39  // Normal points
40  const pointField& pts = mesh.points();
41 
42  // Additional cell centres
43  const labelUList& addPoints = this->additionalIds();
44 
45  vtkpoints->SetNumberOfPoints(pts.size() + addPoints.size());
46 
47  // Normal points
48  vtkIdType pointId = 0;
49  for (const point& p : pts)
50  {
51  vtkpoints->SetPoint(pointId++, p.v_);
52  }
53 
54  // Cell centres
55  for (const label meshCelli : addPoints)
56  {
57  vtkpoints->SetPoint(pointId++, mesh.cellCentres()[meshCelli].v_);
58  }
59 
60  return vtkpoints;
61 }
62 
63 
66 (
67  const fvMesh& mesh,
68  const labelUList& pointMap
69 ) const
70 {
71  // Convert OpenFOAM mesh vertices to VTK
72  auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
73 
74  // Normal points
75  const pointField& pts = mesh.points();
76 
77  // Additional cell centres
78  const labelUList& addPoints = this->additionalIds();
79 
80  vtkpoints->SetNumberOfPoints(pointMap.size() + addPoints.size());
81 
82  // Normal points
83  vtkIdType pointId = 0;
84  for (const label meshPointi : pointMap)
85  {
86  vtkpoints->SetPoint(pointId++, pts[meshPointi].v_);
87  }
88 
89  // Cell centres
90  for (const label meshCelli : addPoints)
91  {
92  vtkpoints->SetPoint(pointId++, mesh.cellCentres()[meshCelli].v_);
93  }
94 
95  return vtkpoints;
96 }
97 
98 
101 (
102  const fvMesh& mesh,
103  const bool decompPoly
104 )
105 {
106  vtk::vtuSizing sizing(mesh, decompPoly);
107 
109 
112 
113  auto cellLocations = vtkSmartPointer<vtkIdTypeArray>::New();
114  auto faceLocations = vtkSmartPointer<vtkIdTypeArray>::New();
115 
116  UList<uint8_t> cellTypesUL =
118 
119  UList<vtkIdType> cellsUL =
121  (
122  cells,
123  sizing.nFieldCells(),
124  sizing.sizeInternal(vtk::vtuSizing::slotType::CELLS)
125  );
126 
127  UList<vtkIdType> cellLocationsUL =
129  (
130  cellLocations,
131  sizing.sizeInternal(vtk::vtuSizing::slotType::CELLS_OFFSETS)
132  );
133 
134  UList<vtkIdType> facesUL =
136  (
137  faces,
138  sizing.sizeInternal(vtk::vtuSizing::slotType::FACES)
139  );
140 
141  UList<vtkIdType> faceLocationsUL =
143  (
144  faceLocations,
145  sizing.sizeInternal(vtk::vtuSizing::slotType::FACES_OFFSETS)
146  );
147 
148 
149  sizing.populateInternal
150  (
151  mesh,
152  cellTypesUL,
153  cellsUL,
154  cellLocationsUL,
155  facesUL,
156  faceLocationsUL,
157  static_cast<foamVtkMeshMaps&>(*this)
158  );
159 
161 
162  // Convert OpenFOAM mesh vertices to VTK
163  // - can only do this *after* populating the decompInfo with cell-ids
164  // for any additional points (ie, mesh cell-centres)
165  vtkmesh->SetPoints(this->points(mesh));
166 
167  if (facesUL.size())
168  {
169  vtkmesh->SetCells
170  (
171  cellTypes,
172  cellLocations,
173  cells,
174  faceLocations,
175  faces
176  );
177  }
178  else
179  {
180  vtkmesh->SetCells
181  (
182  cellTypes,
183  cellLocations,
184  cells,
185  nullptr,
186  nullptr
187  );
188  }
189 
190  return vtkmesh;
191 }
192 
193 
194 // ************************************************************************* //
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::vtk::Tools::asUList
UList< uint8_t > asUList(vtkUnsignedCharArray *array, const label size)
Wrap vtkUnsignedCharArray as a UList.
Definition: foamVtkToolsI.H:31
vtkSmartPointer
Definition: runTimePostProcessing.H:148
Foam::vtk::vtuAdaptor::points
vtkSmartPointer< vtkPoints > points(const fvMesh &mesh) const
The vtk points for the mesh (and decomposition)
Definition: foamVtkVtuAdaptorI.H:32
Foam::vtk::vtuSizing::nFieldCells
label nFieldCells() const
Number of field cells = nCells + nAddCells.
Definition: foamVtuSizingI.H:92
Foam::label
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:62
Foam::Field< vector >
Foam::vtk::vtuSizing::populateInternal
void populateInternal(const polyMesh &mesh, UList< uint8_t > &cellTypes, UList< int > &connectivity, UList< int > &offsets, UList< int > &faces, UList< int > &facesOffsets, foamVtkMeshMaps &maps) const
Populate lists for Internal VTK format.
Definition: foamVtuSizing.C:347
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
Foam::vtk::vtuSizing
Sizing descriptions and routines for transcribing an OpenFOAM volume mesh into a VTK unstructured gri...
Definition: foamVtuSizing.H:166
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
cellTypes
const labelList & cellTypes
Definition: setCellMask.H:33
Foam::vtk::vtuSizing::sizeInternal
label sizeInternal(const enum slotType slot) const
The calculated size for vtk-internal storage of the specified slot.
Definition: foamVtuSizingI.H:129
Foam::Vector< scalar >
Foam::UList< label >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::UList::size
void size(const label n) noexcept
Override size to be inconsistent with allocated storage.
Definition: UListI.H:360
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::foamVtkMeshMaps
Bookkeeping for mesh subsetting and/or polyhedral cell decomposition. Although the main use case is f...
Definition: foamVtkMeshMaps.H:57
Foam::vtk::vtuAdaptor::internal
vtkSmartPointer< vtkUnstructuredGrid > internal(const fvMesh &mesh, const bool decompPoly=false)
Internal mesh as vtkUnstructuredGrid.
Definition: foamVtkVtuAdaptorI.H:101