vtkPV3FoamLagrangianFields.H 3.14 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 vtkPV3FoamLagrangianFields_H
#define vtkPV3FoamLagrangianFields_H
32

Mark Olesen's avatar
Mark Olesen committed
33
34
#include "Cloud.H"

35
36
37
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

template<class Type>
Mark Olesen's avatar
Mark Olesen committed
38
39
40
41
42
43
44
void Foam::vtkPV3Foam::convertLagrangianFields
(
    const IOobjectList& objects,
    vtkMultiBlockDataSet* output,
    const label datasetNo
)
{
Mark Olesen's avatar
Mark Olesen committed
45
    const partInfo& selector = partInfoLagrangian_;
Mark Olesen's avatar
Mark Olesen committed
46

Mark Olesen's avatar
Mark Olesen committed
47
    forAllConstIter(IOobjectList, objects, iter)
Mark Olesen's avatar
Mark Olesen committed
48
    {
Mark Olesen's avatar
Mark Olesen committed
49
50
51
52
53
54
        // restrict to this IOField<Type>
        if (iter()->headerClassName() == IOField<Type>::typeName)
        {
            IOField<Type> tf(*iter());
            convertLagrangianField(tf, output, selector, datasetNo);
        }
Mark Olesen's avatar
Mark Olesen committed
55
56
57
58
59
60
    }
}


template<class Type>
void Foam::vtkPV3Foam::convertLagrangianField
61
(
Mark Olesen's avatar
Mark Olesen committed
62
    const IOField<Type>& tf,
63
    vtkMultiBlockDataSet* output,
Mark Olesen's avatar
Mark Olesen committed
64
    const partInfo& selector,
65
66
67
    const label datasetNo
)
{
68
69
    const label nComp = pTraits<Type>::nComponents;

70
    vtkFloatArray *pointData = vtkFloatArray::New();
Mark Olesen's avatar
Mark Olesen committed
71
72
73
74
    pointData->SetNumberOfTuples( tf.size() );
    pointData->SetNumberOfComponents( nComp );
    pointData->Allocate( nComp*tf.size() );
    pointData->SetName( tf.name().c_str() );
75

Mark Olesen's avatar
Mark Olesen committed
76
77
78
79
80
81
82
83
    if (debug)
    {
        Info<< "convert LagrangianField: "
            << tf.name()
            << " size = " << tf.size()
            << " nComp=" << nComp
            << " nTuples = " << tf.size() <<  endl;
    }
84

Mark Olesen's avatar
Mark Olesen committed
85
86
    float vec[nComp];
    forAll(tf, i)
87
    {
Mark Olesen's avatar
Mark Olesen committed
88
        const Type& t = tf[i];
89
        for (direction d=0; d<nComp; d++)
90
        {
Mark Olesen's avatar
Mark Olesen committed
91
            vec[d] = component(t, d);
92
93
94
95
96
        }

        pointData->InsertTuple(i, vec);
    }

Mark Olesen's avatar
Mark Olesen committed
97
98
99
100
101
102
103

    vtkPolyData::SafeDownCast
    (
        GetDataSetFromBlock(output, selector, datasetNo)
    )   ->GetPointData()
        ->AddArray(pointData);

104
105
106
107
108
109
110
111
    pointData->Delete();
}

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

#endif

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