vtkPVFoamMeshLagrangian.C 3.02 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5 6 7 8
    \\  /    A nd           | Copyright (C) 2017-2018 OpenCFD Ltd.
     \\/     M anipulation  |
-------------------------------------------------------------------------------
                            | Copyright (C) 2011-2016 OpenFOAM Foundation
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
-------------------------------------------------------------------------------
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 3 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, see <http://www.gnu.org/licenses/>.

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

28
#include "vtkPVFoam.H"
29 30 31 32 33 34 35 36 37 38 39

// OpenFOAM includes
#include "Cloud.H"
#include "fvMesh.H"
#include "IOobjectList.H"
#include "passiveParticle.H"

// VTK includes
#include "vtkCellArray.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
40
#include "vtkSmartPointer.h"
41 42 43

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

44
vtkSmartPointer<vtkPolyData> Foam::vtkPVFoam::lagrangianVTKMesh
45
(
46
    const polyMesh& mesh,
47
    const word& cloudName
48
) const
49
{
50
    vtkSmartPointer<vtkPolyData> vtkmesh;
51 52 53

    if (debug)
    {
54
        Info<< "<beg> lagrangianVTKMesh - timePath "
55
            << mesh.time().timePath()/cloud::prefix/cloudName << nl;
56 57 58 59
        printMemory();
    }


60 61
    // The region name is already in the mesh db
    IOobjectList cloudObjects
62 63 64 65 66 67
    (
        mesh,
        mesh.time().timeName(),
        cloud::prefix/cloudName
    );

68 69 70 71 72
    if
    (
        cloudObjects.found("positions")
     || cloudObjects.found("coordinates")
    )
73 74 75
    {
        Cloud<passiveParticle> parcels(mesh, cloudName, false);

76
        DebugInfo << "cloud with " << parcels.size() << " parcels" << nl;
77

78
        auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
79
        vtkpoints->SetNumberOfPoints(parcels.size());
80 81

        vtkIdType particleId = 0;
82
        for (const passiveParticle& p : parcels)
83
        {
84
            vtkpoints->SetPoint(particleId, p.position().v_);
85
            ++particleId;
86 87
        }

88
        vtkmesh = vtkSmartPointer<vtkPolyData>::New();
89
        vtkmesh->SetPoints(vtkpoints);
90
        vtkmesh->SetVerts(vtk::Tools::identityVertices(parcels.size()));
91 92 93 94
    }

    if (debug)
    {
95
        Info<< "<end> lagrangianVTKMesh" << nl;
96 97 98 99 100 101 102 103
        printMemory();
    }

    return vtkmesh;
}


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