vtkPV3FoamMeshLagrangian.C 3.13 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
30
31
     \\/     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

Description

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

#include "vtkPV3Foam.H"

// Foam includes
Mark Olesen's avatar
Mark Olesen committed
32
33
34
35
#include "Cloud.H"
#include "fvMesh.H"
#include "IOobjectList.H"
#include "passiveParticle.H"
Mark Olesen's avatar
Mark Olesen committed
36
#include "vtkOpenFOAMPoints.H"
37
38

// VTK includes
Mark Olesen's avatar
Mark Olesen committed
39
#include "vtkCellArray.h"
Mark Olesen's avatar
Mark Olesen committed
40
#include "vtkPoints.h"
41
42
43
44
#include "vtkPolyData.h"

// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

Mark Olesen's avatar
Mark Olesen committed
45
vtkPolyData* Foam::vtkPV3Foam::lagrangianVTKMesh
46
(
Mark Olesen's avatar
Mark Olesen committed
47
48
    const fvMesh& mesh,
    const word& cloudName
49
50
)
{
Mark Olesen's avatar
Mark Olesen committed
51
52
    vtkPolyData* vtkmesh = NULL;

53
54
    if (debug)
    {
Mark Olesen's avatar
Mark Olesen committed
55
        Info<< "<beg> Foam::vtkPV3Foam::lagrangianVTKMesh - timePath "
56
            << mesh.time().timePath()/cloud::prefix/cloudName << endl;
Mark Olesen's avatar
Mark Olesen committed
57
        printMemory();
58
59
    }

60
61

    // the region name is already in the mesh db
Mark Olesen's avatar
Mark Olesen committed
62
63
64
65
    IOobjectList sprayObjs
    (
        mesh,
        mesh.time().timeName(),
66
        cloud::prefix/cloudName
Mark Olesen's avatar
Mark Olesen committed
67
    );
68

Mark Olesen's avatar
Mark Olesen committed
69
70
    IOobject* positionsPtr = sprayObjs.lookup("positions");
    if (positionsPtr)
71
    {
Mark Olesen's avatar
Mark Olesen committed
72
        Cloud<passiveParticle> parcels(mesh, cloudName, false);
73

Mark Olesen's avatar
Mark Olesen committed
74
75
76
77
        if (debug)
        {
            Info<< "cloud with " << parcels.size() << " parcels" << endl;
        }
78

Mark Olesen's avatar
Mark Olesen committed
79
80
        vtkmesh = vtkPolyData::New();
        vtkPoints* vtkpoints = vtkPoints::New();
Mark Olesen's avatar
Mark Olesen committed
81
82
        vtkCellArray* vtkcells = vtkCellArray::New();

Mark Olesen's avatar
Mark Olesen committed
83
        vtkpoints->Allocate( parcels.size() );
Mark Olesen's avatar
Mark Olesen committed
84
        vtkcells->Allocate( parcels.size() );
85

Mark Olesen's avatar
Mark Olesen committed
86
        vtkIdType particleId = 0;
Mark Olesen's avatar
Mark Olesen committed
87
        forAllConstIter(Cloud<passiveParticle>, parcels, iter)
88
        {
Mark Olesen's avatar
Mark Olesen committed
89
            vtkInsertNextOpenFOAMPoint(vtkpoints, iter().position());
Mark Olesen's avatar
Mark Olesen committed
90
91
92

            vtkcells->InsertNextCell(1, &particleId);
            particleId++;
93
94
        }

Mark Olesen's avatar
Mark Olesen committed
95
96
        vtkmesh->SetPoints(vtkpoints);
        vtkpoints->Delete();
Mark Olesen's avatar
Mark Olesen committed
97
98
99

        vtkmesh->SetVerts(vtkcells);
        vtkcells->Delete();
Mark Olesen's avatar
Mark Olesen committed
100
    }
101
102
103

    if (debug)
    {
Mark Olesen's avatar
Mark Olesen committed
104
        Info<< "<end> Foam::vtkPV3Foam::lagrangianVTKMesh" << endl;
Mark Olesen's avatar
Mark Olesen committed
105
        printMemory();
106
    }
Mark Olesen's avatar
Mark Olesen committed
107
108

    return vtkmesh;
109
110
111
112
}


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