-
Notifications
You must be signed in to change notification settings - Fork 177
Description
Update
For those new to this thread, a little context... This started out with me asking about 1st order interpolation. I thought that the FiPy behavior was wrong. I learned that FiPy is behaving as intended. Rather, I learned that what I had expected as 1st order interpolation is actually higher order interpolation. Hence, this turned from a question into an enhancement request.
Background
The CellVariable.__call__() method supports 0th and 1st order interpolation via its order argument. I have been doing some experiments and getting unexpected results, as demonstrated below.
MWE
All results are from the following script. I have been adjusting the two inputs cell_values and order.
import numpy as np
import matplotlib.pyplot as plt
from fipy import Grid1D, CellVariable
# Inputs
cell_values = [1., 2., 3., 4., 5.]
order = 1
# FiPy setup
mesh = Grid1D(dx=1, nx=5)
y = CellVariable(mesh)
y.setValue(cell_values)
# Get data
x_exact, = mesh.cellCenters
y_exact = y
x_inter = np.linspace(start=0, stop=5)
y_inter = []
for x in x_inter:
y_inter.append(y((x,), order=order))
# Plot
plt.scatter(x_exact, y_exact, label='Cell centers')
plt.scatter(x_inter, y_inter, label='Interpolated', s=5)
plt.xlabel('x')
plt.ylabel('y')
plt.xticks([0, 1, 2, 3, 4, 5])
plt.grid(axis='x')
plt.legend()
plt.show()Plots
First, lets trial order=0 (nearest neighbour) interpolation. The results are as expected.

Second, lets trial order=1 (linear) interpolation. The results are intuitively wrong for the cells at either end of the domain.

Finally, lets change the cell_values slightly. These results are wrong for even more of the cells.
