foamVtkVtuAdaptorTemplates.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) 2017-2019 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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// VTK includes
29#include "vtkFloatArray.h"
30#include "vtkCellData.h"
31#include "vtkPointData.h"
32#include "vtkSmartPointer.h"
33
34// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35
36template<class Type>
37vtkSmartPointer<vtkFloatArray>
39(
41 const vtuAdaptor& vtuData
42)
43{
44 const int nComp(pTraits<Type>::nComponents);
45 const labelUList& cellMap = vtuData.cellMap();
46
47 auto data = vtkSmartPointer<vtkFloatArray>::New();
48 data->SetName(fld.name().c_str());
49 data->SetNumberOfComponents(nComp);
50 data->SetNumberOfTuples(cellMap.size());
51
52 // DebugInfo
53 // << "Convert field: " << fld.name()
54 // << " size=" << cellMap.size()
55 // << " (" << fld.size() << " + "
56 // << (cellMap.size() - fld.size())
57 // << ") nComp=" << nComp << endl;
58
59
60 float scratch[pTraits<Type>::nComponents];
61
62 vtkIdType celli = 0;
63 for (const label meshCelli : cellMap)
64 {
65 vtk::Tools::foamToVtkTuple(scratch, fld[meshCelli]);
66 data->SetTuple(celli++, scratch);
67 }
68
69 return data;
70}
71
72
73template<class Type>
74vtkSmartPointer<vtkFloatArray>
76(
78 const vtuAdaptor& vtuData
79)
80{
81 return convertField<Type>(fld.internalField(), vtuData);
82}
83
84
85template<class Type>
86vtkSmartPointer<vtkFloatArray>
88(
90) const
91{
92 return convertField<Type>(fld, *this);
93}
94
95
96template<class Type>
97vtkSmartPointer<vtkFloatArray>
99(
101) const
102{
103 return convertField<Type>(fld, *this);
104}
105
106
107// ************************************************************************* //
Info<< nl<< "Wrote faMesh in vtk format: "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.mesh().time().globalPath()/"finiteArea-edges"));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Generic GeometricField class.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Database for solution data, solver performance and other reduced data.
Definition: data.H:58
const labelList & cellMap() const noexcept
Original cell ids for all cells (regular and decomposed).
A traits class, which is primarily used for primitives.
Definition: pTraits.H:59
Bookkeeping for vtkUnstructuredGrid.
static vtkSmartPointer< vtkFloatArray > convertField(const DimensionedField< Type, volMesh > &fld, const vtuAdaptor &vtuData)
Convert internal volume field (CellData)
void foamToVtkTuple(float output[], const Type &val)
Copy/transcribe OpenFOAM data types to VTK format.