vtkPVFoamFaceField.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 | Copyright (C) 2011-2016 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 InClass
25  vtkPVFoam
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #ifndef vtkPVFoamFaceField_H
30 #define vtkPVFoamFaceField_H
31 
32 // VTK includes
33 #include "vtkCellData.h"
34 #include "vtkFloatArray.h"
35 #include "vtkMultiBlockDataSet.h"
36 #include "vtkPolyData.h"
37 
38 #include "vtkOpenFOAMTupleRemap.H"
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 template<class Type>
43 void Foam::vtkPVFoam::convertFaceField
44 (
45  const GeometricField<Type, fvPatchField, volMesh>& tf,
46  vtkMultiBlockDataSet* output,
47  const arrayRange& range,
48  const label datasetNo,
49  const fvMesh& mesh,
50  const labelList& faceLabels
51 )
52 {
53  const label nComp = pTraits<Type>::nComponents;
54  const label nInternalFaces = mesh.nInternalFaces();
55  const labelList& faceOwner = mesh.faceOwner();
56  const labelList& faceNeigh = mesh.faceNeighbour();
57 
58  vtkFloatArray* cellData = vtkFloatArray::New();
59  cellData->SetNumberOfTuples(faceLabels.size());
60  cellData->SetNumberOfComponents(nComp);
61  cellData->Allocate(nComp*faceLabels.size());
62  cellData->SetName(tf.name().c_str());
63 
64  if (debug)
65  {
66  Info<< "convert convertFaceField: "
67  << tf.name()
68  << " size = " << tf.size()
69  << " nComp=" << nComp
70  << " nTuples = " << faceLabels.size() << endl;
71  }
72 
73  float vec[nComp];
74 
75  // for interior faces: average owner/neighbour
76  // for boundary faces: owner
77  forAll(faceLabels, facei)
78  {
79  const label faceNo = faceLabels[facei];
80  if (faceNo < nInternalFaces)
81  {
82  Type t = 0.5*(tf[faceOwner[faceNo]] + tf[faceNeigh[faceNo]]);
83 
84  for (direction d=0; d<nComp; ++d)
85  {
86  vec[d] = component(t, d);
87  }
88  }
89  else
90  {
91  const Type& t = tf[faceOwner[faceNo]];
92  for (direction d=0; d<nComp; ++d)
93  {
94  vec[d] = component(t, d);
95  }
96  }
97  vtkOpenFOAMTupleRemap<Type>(vec);
98 
99  cellData->InsertTuple(facei, vec);
100  }
101 
102 
103  vtkPolyData::SafeDownCast
104  (
105  GetDataSetFromBlock(output, range, datasetNo)
106  ) ->GetCellData()
107  ->AddArray(cellData);
108 
109  cellData->Delete();
110 }
111 
112 
113 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
114 
115 #endif
116 
117 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
uint8_t direction
Definition: direction.H:46
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
List< label > labelList
A List of labels.
Definition: labelList.H:56
messageStream Info
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)