vtkLagrangianParticleTracker python commands

I am trying to understand and implement how the vtkLagrangianParticleTracker (LPT) works. I tried to modify the kitchen example. Basically, replaced the vtkStreamTracer arguments with the LPT arguments. My issue is how the particle data is inputted.

I tried something like this…

paths = vtk.LagrangianParticleTracker()
paths.SetInputConnection(reader.GetOutputPort())
paths.SetSourceConnection(point.GetOutputPort())
matida = vtk.vtkLagrangianMatidaIntegrationModel()
paths.SetIntegrationModel(matida)
paths.Update()

The reader comes from the kitchen example and I replaced the line with point. In the code, I am missing particle arguments. I need help with creating a particle with random specifications and inputting this data into the LPT.

Thanks for your help in advance!!

This example is for the stream tracer.

The LPT is a very special filter that let you define your own integration model, are you sure you need it ?

In any case, you will find an example usage here:
https://gitlab.kitware.com/vtk/vtk/-/blob/master/Filters/FlowPaths/Testing/Cxx/TestLagrangianParticleTracker.cxx

Thanks! :slightly_smiling_face: This really helped me in understanding of how to implement LPT. Could you also elaborate on where the particles are spawned? For example, in the test case you provided, the spawn locations for the particles are not specified. Are they being spawned at random?

To elaborate,
If I have a (x,y,z) location, how would I input it to spawn particles at this location?
OR
If I have a line object, how would I make particles spawn along the line?

Ther are specified here:

tracker->SetSourceConnection(groupSeed->GetOutputPort());

You need to create a source input or dataset.

Thanks for the quick reply. That clarifies things! Could you help me understand what this part of the code is doing?

Code link

tracker->GenerateParticlePathsOutputOn();
 tracker->SetInputConnection(ugFlow->GetOutputPort());
  tracker->SetMaximumNumberOfSteps(30);
  tracker->SetCellLengthComputationMode(vtkLagrangianParticleTracker::STEP_CUR_CELL_DIV_THEO);
  tracker->Update();

I am trying to better understand the code. I was able to port your test code to python and modify the kitchen example. I will post the codes to both for reference shortly.

tracker->GenerateParticlePathsOutputOn();

With this option to on, the path will be generated, not only the interactions

 tracker->SetInputConnection(ugFlow->GetOutputPort());

Set the volumic flow input

tracker->SetMaximumNumberOfSteps(30);

Set the number of maximum of steps per paticle to 30 (quite a low number for real life data)

tracker->SetCellLengthComputationMode(vtkLagrangianParticleTracker::STEP_CUR_CELL_DIV_THEO);

See here: https://vtk.org/doc/nightly/html/classvtkLagrangianParticleTracker.html#a931ba3f4ef4258e95fa1fc521a474478

tracker->Update();

Actual computation

Hello again,

Sorry for the delayed reply. As I have mentioned, I have been trying to get the kitchen example to work. For some reason, creating a surface and setting it’s component to vtk.vtkLagrangianBasicIntegrationModel.SURFACE_TYPE_BOUNCE is not working as expected. Here’s a part of the code I have written, trying to replicate the test code you provided…

# Create a plane
surfaceBounce = vtk.vtkPlaneSource()
surfaceBounce.SetOrigin(4, 0, 0)
surfaceBounce.SetPoint1(4, 3, 0)
surfaceBounce.SetPoint2(4, 0, 1)
bouncePd = surfaceBounce.GetOutput()

# Plane actor
surfaceMapper = vtk.vtkPolyDataMapper()
surfaceMapper.SetInputConnection(surfaceBounce.GetOutputPort())
surfaceActor = vtk.vtkActor()
surfaceActor.SetMapper(surfaceMapper)
surfaceActor.GetProperty().SetColor(colors.GetColor3d('Blue'))

# Set the surface tpe to bounce
surfaceTypeBounce = vtk.vtkDoubleArray()
surfaceTypeBounce.SetNumberOfComponents(1)
surfaceTypeBounce.SetName('SurfaceType')
surfaceTypeBounce.SetNumberOfTuples(bouncePd.GetNumberOfCells())
surfaceTypeBounce.FillComponent(0, vtk.vtkLagrangianBasicIntegrationModel.SURFACE_TYPE_BOUNCE)
bouncePd.GetCellData().AddArray(surfaceTypeBounce)

# Group it to send it to tracker
groupSurface = vtk.vtkMultiBlockDataGroupFilter()
groupSurface.AddInputDataObject(bouncePd)

The rest of the code is same as yours! Below is the result I am getting, the blue surface is the one I created. Do you have any debugging steps/ideas I could use to figure out what’s happening? Thanks!

I’d put a breakpoint in the surface interaction code to see what is going on.

I think it’s an issue with using jupyter-notebook. When I ran the same code in PyCharm, it worked fine. I tried running the whole code from a single cell in jupyter-notebook, still did not work. Do you know of any reasons what might cause this issue?

Here’s the result from PyCharm…

I do not see any reasons for this, but I’m not using LPT with python.

Thanks for all the help! I really appreciate it. :+1:

I made a mistake in the code. Forgot to do surfaceBounce.Update(). The code works fine now. Nothing to do with the IDEs. I’ll post links to the code as soon as I am done cleaning it up.

1 Like

I added the test-cases in python here. Hope this will help anyone wanting to do LPT in python

@amaclean : this may be of interest to you

@kal this would make a nice addition to the VTK Examples. You would need to convert it to a Python script, and create a MR. Please see ForDevelopers for instructions and Guidelines for guidelines. I would recommend calling it KitchenLPT and putting it in the Visualization folder where the original Kitchen example is.