vtkPVFoamMeshLagrangian.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "vtkPVFoam.H"
27 
28 // OpenFOAM includes
29 #include "Cloud.H"
30 #include "fvMesh.H"
31 #include "IOobjectList.H"
32 #include "passiveParticle.H"
33 #include "vtkOpenFOAMPoints.H"
34 
35 // VTK includes
36 #include "vtkCellArray.h"
37 #include "vtkPoints.h"
38 #include "vtkPolyData.h"
39 
40 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
41 
42 vtkPolyData* Foam::vtkPVFoam::lagrangianVTKMesh
43 (
44  const fvMesh& mesh,
45  const word& cloudName
46 )
47 {
48  vtkPolyData* vtkmesh = nullptr;
49 
50  if (debug)
51  {
52  InfoInFunction<< "timePath "
53  << mesh.time().timePath()/cloud::prefix/cloudName << endl;
54  printMemory();
55  }
56 
57 
58  // The region name is already in the mesh db
59  IOobjectList sprayObjs
60  (
61  mesh,
62  mesh.time().timeName(),
64  );
65 
66  IOobject* positionsPtr = sprayObjs.lookup(word("positions"));
67  if (positionsPtr)
68  {
69  Cloud<passiveParticle> parcels(mesh, cloudName, false);
70 
71  if (debug)
72  {
73  Info<< " cloud with " << parcels.size()
74  << " parcels" << endl;
75  }
76 
77  vtkmesh = vtkPolyData::New();
78  vtkPoints* vtkpoints = vtkPoints::New();
79  vtkCellArray* vtkcells = vtkCellArray::New();
80 
81  vtkpoints->Allocate(parcels.size());
82  vtkcells->Allocate(parcels.size());
83 
84  vtkIdType particleId = 0;
85  forAllConstIter(Cloud<passiveParticle>, parcels, iter)
86  {
87  vtkInsertNextOpenFOAMPoint(vtkpoints, iter().position());
88 
89  vtkcells->InsertNextCell(1, &particleId);
90  particleId++;
91  }
92 
93  vtkmesh->SetPoints(vtkpoints);
94  vtkpoints->Delete();
95 
96  vtkmesh->SetVerts(vtkcells);
97  vtkcells->Delete();
98  }
99 
100  if (debug)
101  {
102  printMemory();
103  }
104 
105  return vtkmesh;
106 }
107 
108 
109 // ************************************************************************* //
static void printMemory()
Simple memory used debugging information.
void vtkInsertNextOpenFOAMPoint(vtkPoints *points, const Foam::point &p)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
autoPtr< BasicCompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleMomentumTransportModel::transportModel &transport)
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
static const word prefix
The prefix to local: lagrangian.
Definition: cloud.H:62
messageStream Info
const word cloudName(propsDict.lookup("cloudName"))
#define InfoInFunction
Report an information message using Foam::Info.