OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

vtkPV3FoamMeshLagrangian.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "vtkPV3Foam.H"
00030 
00031 // Foam includes
00032 #include "Cloud.H"
00033 #include "fvMesh.H"
00034 #include "IOobjectList.H"
00035 #include "passiveParticle.H"
00036 #include "vtkPV3FoamPoints.H"
00037 
00038 // VTK includes
00039 #include "vtkCellArray.h"
00040 #include "vtkPoints.h"
00041 #include "vtkPolyData.h"
00042 
00043 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00044 
00045 vtkPolyData* Foam::vtkPV3Foam::lagrangianVTKMesh
00046 (
00047     const fvMesh& mesh,
00048     const word& cloudName
00049 )
00050 {
00051     vtkPolyData* vtkmesh = NULL;
00052 
00053     if (debug)
00054     {
00055         Info<< "<beg> Foam::vtkPV3Foam::lagrangianVTKMesh - timePath "
00056             << mesh.time().timePath()/cloud::prefix/cloudName << endl;
00057         printMemory();
00058     }
00059 
00060 
00061     // the region name is already in the mesh db
00062     IOobjectList sprayObjs
00063     (
00064         mesh,
00065         mesh.time().timeName(),
00066         cloud::prefix/cloudName
00067     );
00068 
00069     IOobject* positionsPtr = sprayObjs.lookup("positions");
00070     if (positionsPtr)
00071     {
00072         Cloud<passiveParticle> parcels(mesh, cloudName, false);
00073 
00074         if (debug)
00075         {
00076             Info<< "cloud with " << parcels.size() << " parcels" << endl;
00077         }
00078 
00079         vtkmesh = vtkPolyData::New();
00080         vtkPoints* vtkpoints = vtkPoints::New();
00081         vtkCellArray* vtkcells = vtkCellArray::New();
00082 
00083         vtkpoints->Allocate( parcels.size() );
00084         vtkcells->Allocate( parcels.size() );
00085 
00086         vtkIdType particleId = 0;
00087         forAllConstIter(Cloud<passiveParticle>, parcels, iter)
00088         {
00089             vtkPV3FoamInsertNextPoint(vtkpoints, iter().position());
00090 
00091             vtkcells->InsertNextCell(1, &particleId);
00092             particleId++;
00093         }
00094 
00095         vtkmesh->SetPoints(vtkpoints);
00096         vtkpoints->Delete();
00097 
00098         vtkmesh->SetVerts(vtkcells);
00099         vtkcells->Delete();
00100     }
00101 
00102     if (debug)
00103     {
00104         Info<< "<end> Foam::vtkPV3Foam::lagrangianVTKMesh" << endl;
00105         printMemory();
00106     }
00107 
00108     return vtkmesh;
00109 }
00110 
00111 
00112 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd