Updating mesh and point data using python

I have a python program that updates the mesh and point data based on user input (sliders in matplotlib.widgets). Is it possible to write and update the paraview.servermanager object directly instead of writing to a file and then reading the same file back into the same paraview object?

Something like (if “a” is an InputProperty object):
# U is the displacement field
# p is the pressure field
# X is the nodes of an structured mesh

Is this the correct approach, if so, how do I use the SetData() function in this regards? I can create a MWE if desirable.

What do you mean by that ? is “the mesh” a vtkDataSet ?

The mesh is simply described by a vector of points X, alongside the dimensions of the structured mesh. The program is a Navier-Stokes solver.

You can use the GetClientSideObject() mechanism. (this does not work if you use a separate pvserver)

# create a reader proxy
pv_data = OpenDataFile('myFile')  
# force the data to be loaded
# get the vtk reader behind the paraview object
vtk_reader = pv_data.GetClientSideObject() 
# get the vtkDataObject produced by the reader
vtk_data = vtk_reader.GetOutput()

Then you may modify vtk_data on the fly.
To set data in pv object:


Note that this output may be overwritten by an update of the filter so you may want to put your data in a PVTrivialProducer as pv_data.

Do you have to create a new VTK object in this approach instead of updating a given array? In any case, I’m not sure how to get and update a given field in a VTK object. I can get i.e. the range for an array ‘U’ in the following manner:

obj = XMLUnstructuredGridReader(FileName=['myFile'])

it would be convenient if I could just set and get values for that array along the lines of the following

Uvalues = obj.PointData.GetArray("U").GetValues()

You cannot set values from this object.
PointData.GetArray() returns an ArrayInformation and not the data itself. You really need the GetClientSideObject(). Note that it does not create a vtk object but only access one already existing in memory

Ok. But how exactly do I use the GetClientSideObject() function for the example outlined above? How to convert from and to a numpy array?

Hi Zetison,
Do you have implement this feature? I just want to update the PointData value in vtkMultiBlockDataSet and refresh the colormap of paraview.
Do you have a good solution? Does any experts can help me?


Hi Nicolas,
My soure object is a multiblockObject. I get the ClientSideObject, and then I update the PointData of sub block of the multiblockObject. And then copy a new multiblockObject to setOutput(). But I find that paraview have no change.
The code is like this:

 vtkSMSourceProxy* soureProxy = m_pqSource->getSourceProxy();
 vtkObjectBase* objBase = soureProxy->GetClientSideObject();
 vtkFileSeriesReader* fileReader = vtkFileSeriesReader::SafeDownCast(objBase);
 vtkMultiBlockDataSet* newDataSet = vtkMultiBlockDataSet::New();

I have updated the vtkDataArray value in the PointData of the m_multiBlockDataSet.
Dose something else I need to do?



ParaView (and VTK) are based on a pipeline infrastructure (see more in the docs ). Each element (reader and filter) can be automatically recomputed as needed, so manually setting the output as you did is not a viable solution: it will certainly be overriden.

To set your own data in the pipeline, use the PVTrivialProducer.

1 Like

Hi Nicolas,
Yeah, I got it. thank you. Now I use the file as the input. If I want to display different field in the pointdata.I just can switch to openning different file. It can work, but it has a little ineffective.