vtkPV3FoamFaceField.H 5.24 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
Mark Olesen's avatar
Mark Olesen committed
5
    \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM; if not, write to the Free Software Foundation,
    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

InClass
    vtkPV3Foam

\*---------------------------------------------------------------------------*/

Mark Olesen's avatar
Mark Olesen committed
30
31
#ifndef vtkPV3FoamFaceField_H
#define vtkPV3FoamFaceField_H
32
33
34
35
36
37
38
39
40
41
42
43
44

// VTK includes
#include "vtkCellData.h"
#include "vtkFloatArray.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkPolyData.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

template<class Type>
void Foam::vtkPV3Foam::convertFaceField
(
    const GeometricField<Type, fvPatchField, volMesh>& tf,
    vtkMultiBlockDataSet* output,
Mark Olesen's avatar
Mark Olesen committed
45
    const partInfo& selector,
46
47
48
49
50
    const label datasetNo,
    const fvMesh& mesh,
    const labelList& faceLabels
)
{
51
    const label nComp = pTraits<Type>::nComponents;
52
53
54
55
56
    const label nInternalFaces = mesh.nInternalFaces();
    const labelList& faceOwner = mesh.faceOwner();
    const labelList& faceNeigh = mesh.faceNeighbour();

    vtkFloatArray *cellData = vtkFloatArray::New();
Mark Olesen's avatar
Mark Olesen committed
57
58
59
60
61
62
63
64
65
66
67
68
69
    cellData->SetNumberOfTuples( faceLabels.size() );
    cellData->SetNumberOfComponents( nComp );
    cellData->Allocate( nComp*faceLabels.size() );
    cellData->SetName( tf.name().c_str() );

    if (debug)
    {
        Info<< "convert convertFaceField: "
            << tf.name()
            << " size = " << tf.size()
            << " nComp=" << nComp
            << " nTuples = " << faceLabels.size() <<  endl;
    }
70

71
    float vec[nComp];
72

Mark Olesen's avatar
Mark Olesen committed
73
74
    // for interior faces: average owner/neighbour
    // for boundary faces: owner
75
76
77
78
79
    forAll(faceLabels, faceI)
    {
        const label faceNo = faceLabels[faceI];
        if (faceNo < nInternalFaces)
        {
80
            Type t = 0.5*(tf[faceOwner[faceNo]] + tf[faceNeigh[faceNo]]);
81

82
            for (direction d=0; d<nComp; d++)
83
            {
84
                vec[d] = component(t, d);
85
86
87
88
89
            }
        }
        else
        {
            const Type& t = tf[faceOwner[faceNo]];
90
            for (direction d=0; d<nComp; d++)
91
            {
92
                vec[d] = component(t, d);
93
94
95
96
97
98
            }
        }

        cellData->InsertTuple(faceI, vec);
    }

Mark Olesen's avatar
Mark Olesen committed
99
100
101
102
103
104
105

    vtkPolyData::SafeDownCast
    (
        GetDataSetFromBlock(output, selector, datasetNo)
    )   ->GetCellData()
        ->AddArray(cellData);

106
107
108
109
110
111
112
113
114
    cellData->Delete();
}


template<class Type>
void Foam::vtkPV3Foam::convertFaceField
(
    const GeometricField<Type, fvPatchField, volMesh>& tf,
    vtkMultiBlockDataSet* output,
Mark Olesen's avatar
Mark Olesen committed
115
    const partInfo& selector,
116
117
118
119
120
    const label datasetNo,
    const fvMesh& mesh,
    const faceSet& fSet
)
{
121
    const label nComp = pTraits<Type>::nComponents;
122
123
124
125
126
    const label nInternalFaces = mesh.nInternalFaces();
    const labelList& faceOwner = mesh.faceOwner();
    const labelList& faceNeigh = mesh.faceNeighbour();

    vtkFloatArray *cellData = vtkFloatArray::New();
Mark Olesen's avatar
Mark Olesen committed
127
128
129
130
131
132
133
134
135
136
137
138
139
    cellData->SetNumberOfTuples( fSet.size() );
    cellData->SetNumberOfComponents( nComp );
    cellData->Allocate( nComp*fSet.size() );
    cellData->SetName( tf.name().c_str() );

    if (debug)
    {
        Info<< "convert convertFaceField: "
            << tf.name()
            << " size = " << tf.size()
            << " nComp=" << nComp
            << " nTuples = " << fSet.size() <<  endl;
    }
140

141
    float vec[nComp];
142

Mark Olesen's avatar
Mark Olesen committed
143
144
    // for interior faces: average owner/neighbour
    // for boundary faces: owner
145
146
147
148
149
150
151
    label faceI = 0;
    forAllConstIter(faceSet, fSet, iter)
    {
        const label faceNo = iter.key();

        if (faceNo < nInternalFaces)
        {
152
            Type t = 0.5*(tf[faceOwner[faceNo]] + tf[faceNeigh[faceNo]]);
153

154
            for (direction d=0; d<nComp; d++)
155
            {
156
                vec[d] = component(t, d);
157
158
159
160
161
            }
        }
        else
        {
            const Type& t = tf[faceOwner[faceNo]];
162
            for (direction d=0; d<nComp; d++)
163
            {
164
                vec[d] = component(t, d);
165
166
167
168
169
170
171
            }
        }

        cellData->InsertTuple(faceI, vec);
        ++faceI;
    }

Mark Olesen's avatar
Mark Olesen committed
172
173
174
175
176
177
178

    vtkPolyData::SafeDownCast
    (
        GetDataSetFromBlock(output, selector, datasetNo)
    )   ->GetCellData()
        ->AddArray(cellData);

179
180
181
182
183
184
185
186
    cellData->Delete();
}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //