how to multiply point data by global variable

Is it possible to multiply point data by a global variable? How is it done?

Thanks team!

@cory.quammen @utkarsh.ayachit

1 Like

There’s nothing in the Calculator filter to access global variables stored in field data, but you can use the Python Calculator to do that.

As an example, if you open the can.exo file, you can add a Python Calculator with the Expression property set to inputs[0].FieldData['KE'][0] * ACCL. Make sure you set the Array Association to ā€œPoint Dataā€.

Exactly what I was looking for. Thanks.

Cory, I believe your formula is incorrect. the [0] is forcing time step zero. What worked for me, using the can.exo dataset, is inputs[0].FieldData[ā€˜NSTEPS’][time_index] * DISPL. I originally missed it, but this is documented in bottom of the ParaView Guide, section 5.9.2.4.

Note, to find the NSTEPS, I used the Annotate Global Data filter.

Ah, thanks for the correction! Here is the section you cited in the ParaView Guide.

This is useful enough, and requested enough, that I added it into the SNL tutorial.

@cory.quammen I have a user asking about this exact information. When I tried creating a Python Calculator as suggested, using result as the output variable name, I could not get any result variable to appear. is this broken, or am I doing something wrong?
I’m using exactly the line of code you present above. Using Master from April 28th, Linux.

Hi @cory.quammen and @mwestphal . I also tried a Programmable filter, and failed miserably. What I want to do in the programmable filter is just:

  • Load can.exo.
  • In a programmable filter pick up Field Data KE, multiply it by 2, and add it to a new Field Data.
  • Do this for multiple timesteps.

Thanks!
Alan

Alan, I am also unable to get either the Python Calculator or Programmable Filter to use existing field data arrays or create new field data arrays in ParaView 5.12.1 or 5.13.3. Something is amiss and I’ll need to investigate more thoroughly when I have a chance.

It seems to be an issue with the numpy wrapping. Testing Programmable filter on can.ex2 with the following:

ke = inputs[0].FieldData["KE"]
print(ke)
ke_vtk = inputs[0].VTKObject.GetFieldData().GetArray("KE")
print(ke_vtk)

Prints

<paraview.vtk.numpy_interface.dataset_adapter.VTKNoneArray object at 0x734669e530e0>
vtkDoubleArray (0x5ab2d652ed70)
  Debug: Off
  Modified Time: 685176
  Reference Count: 37
  Registered Events: (none)
  Name: KE
  Data type: double
  Size: 1
  MaxId: 0
  NumberOfComponents: 1
  Information: 0
  Name: KE
  Number Of Components: 1
  Number Of Tuples: 1
  Size: 1
  MaxId: 0
  LookupTable: (none)

So in pure VTK we have a valid array but not with the wrapping… Do not know why for now.

Ah. Want me to write an issue up? What should I mark it - showstopper for 6.1?

Two more requests. Could we add global data input, processing and output to a test? This has broken more than once. Next, could we document how to use the programmable filter with global data? That doesn’t exist.
Thanks.

I think it is worth an issue, no idea about the label.

And indeed, improving testing would be great.