I need to perform function interpolation on the values on some pointData in the exodus file.
x_data = [0.258, 0.3, 0.344, 0.381, 0.4, 0.416, 0.454, 0.498, 0.534, 0.556, 0.581, 0.598, 0.624, 0.655, 0.685, 0.71, 0.74, 0.772, 0.799, 0.84, 0.871, 0.898, 0.917]
y_data = [4.283, 4.201, 4.12, 4.059, 4.025, 3.998, 3.94, 3.875, 3.834, 3.811, 3.79, 3.78, 3.763, 3.753, 3.736, 3.726, 3.712, 3.695, 3.678, 3.651, 3.631, 3.607, 3.58]
def linear_interpolation_extrapolation(x_data, y_data, x_point):
if x_data[0] <= x_point <= x_data[-1]:
for i in range(len(x_data) - 1):
if x_data[i] <= x_point <= x_data[i + 1]:
return y_data[i] + (y_data[i + 1] - y_data[i]) * (x_point - x_data[i]) / (x_data[i + 1] - x_data[i])
else:
if x_point < x_data[0]:
return y_data[0] + (y_data[1] - y_data[0]) * (x_point - x_data[0]) / (x_data[1] - x_data[0])
elif x_point > x_data[-1]:
return y_data[-2] + (y_data[-1] - y_data[-2]) * (x_point - x_data[-2]) / (x_data[-1] - x_data[-2])
vs = inputs[0].PointData['particle_0'] # the value range is between 0-1
newValue = linear_interpolation_extrapolation(x_data ,y_data,vs)
# The above call results in unexpected values.
# vs is an array of scalar values. I want to perform the function linear_interpolation_extrapolation operation on all values on vs, and then return objects of the same type as vs.
# I try to output the size of vs, the type of vs, and the type of the first element.
print(vs.GetSize(),type(vs),type(vs[0]))
# 59363 <class 'paraview.vtk.numpy_interface.dataset_adapter.VTKCompositeDataArray'> <class 'paraview.vtk.numpy_interface.dataset_adapter.VTKCompositeDataArray'>
I don’t know how to implement this situation.