I’m working with a multiblock dataset. Block 0 has fields “vel_x” and “vel_y”, while block 2 has fields “vel_x_p” and “vel_y_p”. Block 1 does not have these fields. I’d like to write a programmable filter that assembles these fields into a “velocity” vector field for blocks 0 and 2.
Here’s what I have so far:
from vtk.numpy_interface import algorithms
output = inputs[0].ShallowCopy()
data = dataset_adapter.WrapDataObject(inputs[0])
vel = algorithms.make_vector(data.CellData['vel_x'], data.cellData['vel_y'])
vel_p = algorithms.make_vector(data.CellData['vel_x_p'], data.cellData['vel_y_p'])
How can I add these into the appropriate places in the output?
from paraview.vtk.numpy_interface import algorithms as algs
from paraview.vtk.util.numpy_support import numpy_to_vtk
for ind, (block_in, block_out) in enumerate(zip(inputs[0], output)):
if ind == 0:
component_names = ['vel_x', 'vel_y']
elif ind == 2:
component_names = ['vel_x_p', 'vel_y_p']
else:
component_names = None
if component_names:
components = [block_in.CellData[name] for name in component_names]
velocity = numpy_to_vtk(algs.make_vector(*components))
velocity.SetName('Velocity')
block_out.CellData.AddArray(velocity)