Adding new field to mergeblock data

I have an issue adding new scalar field to the existing dataset.

  • The simulation output is from NEK5000 code.
  • First, I read the file, get the u and v field data.
  • Then, Merge the blocks.
  • Applied the servermanager.Fetch.
  • Now the merge_data is ready to be converted to numpy arrays.
  • Get the values of u and v for all the points and store them in data_numpy with the shape (number of points, 2).
  • Calculate my desire field. Please note the real fc function is more complicated that the toy example below, requiring other python packages, so I can not use the Calculator.
  • Up to this point everything looks great.
  • But when I have tried to add this new field to the merge_data,
    • There is no error.
    • I still can use GetRange() function.
    • But I can not see the filed in the GUI or I can not color my grid with new filed fc

Thanks for help

from paraview.simple import *
nek3d = VisItNek5000Reader(FileName='a.nek3d')
merge_data =  MergeBlocks(nek3d)
merge_data = servermanager.Fetch(merge_data)

# Get all values of u and v for all the points 
from paraview import numpy_support as ns
import numpy as np
data_numpy = []
for name in ['u', 'v']:

data_numpy = np.array(data_numpy).T
# data_numpy has the shape (number of points, 2)
# Calculate some function
fc = data_numpy[:,0]+data_numpy[:,1]

fc = ns.numpy_to_vtk(fc.ravel())

I don’t think servermanager.Fetch() is what you want here. That just brings the data to the client. You should use either the Calculator filter, or even more efficiently, the Python Calculator filter to combine your two separate scalar fields into a single new field.

As a side note, you will also want to add a z-component to the new field in order to have ParaView register this field as a vector field since ParaView really only works in 3D space. Maybe you’re already doing this and I’m just going through your code snippet too fast though.

I am not sure why I don’t need to use Fetch().

  • Let assume I have just read the data set with
nek3d = VisItNek5000Reader(FileName='a.nek3d')

Here is the nek3d object. I can not get the data following the manual chapter 13. It just print the data name.

>>> print(type(nek3d))
<class 'paraview.servermanager.VisItNek5000Reader'>

>>> nek3d.PointData
<paraview.servermanager.FieldDataInformation object at 0x7fef17407050>

>>> print(nek3d.PointData['u'])
Array: u
  • Now assume I have used the MergeBlocks, still the same issue.
>>> merge_data =  MergeBlocks(nek3d)
>>> print(type(merge_data))
<class 'paraview.servermanager.MergeBlocks'>
>>> print(merge_data.PointData['u'])
Array: u
  • If I try to convert in this level without Fetch() I got the following error:
Traceback (most recent call last):
  File "<string>", line 28, in <module>
  File "/usr/local/lib/python3.7/site-packages/paraview/", line 497, in __getattr__
    return getattr(self.SMProxy, name)
AttributeError: 'vtkPVServerManagerCorePython.vtkSMSourceProxy' object has no attribute 'GetPointData'
  • The only way I can get the point data and hence doing the pointwise calculation is to Fetch it.
merge_data =  MergeBlocks(nek3d)
merge_data = servermanager.Fetch(merge_data) 
from paraview import numpy_support as ns
import numpy as np
data_numpy = []
for name in ['u', 'v']:
     data_numpy.append(ns.vtk_to_numpy(merge_data.GetPointData().GetArra    y(name))[:])
data_numpy = np.array(data_numpy).T

Which correctly gave me the (100000, 2) dimensional array.

  • And now I don’t know how to add the new field to my dataset, as I explained in the first thread.