Hello,
I was calculating gradients over a nonuniform mesh when I noticed that
the gradient that Fipy calculates is not what I expect. I have
constructed the simplest example I could think of below to show this
behavior. In this example, I calculate the gradient of a
monotonically increasing variable in 1D. I expected to see a gradient
of 1 on all interior cells. Understanding that Fipy expects zero-flux
boundary conditions on all variables, I expected to see a gradient of
0.5 for the boundary cells. These are exactly the results from using
the uniform grid.
When the gradient is calculated using the non-uniform grid spacing it
does not come back with these results. Instead, the gradient is
slightly larger than 1 except at the mid-point. In this example, the
mid-point is special because it is where the grid spacing switches
from getting smaller to getting larger. At this point, Fipy
calculates a gradient that is much too large (11% in this case).
I did not see any bug reports about such a problem in the archives.
This was run on a Windows Vista machine, Intel Centrino Duo2
processor, Fipy 1.2, and Python 2.4.
Is there an alternate way of specifying a nonuniform grid spacing to
avoid this unexpected behavior?
Thanks for your help,
Will Gathright
#------------ Begin Example Code -------------------------
from fipy import *
#The uniform grid will not cause the strange behavior
#dx = Variable("1 nm") * numerix.cumproduct(numerix.concatenate(([1]*100,)))
#The variable grid seems to change the way that FiPy calculates the gradient
#This grid spacing gets smaller and smaller for 10 points, then larger
for 10 points
dx = Variable("1 nm") *
numerix.cumproduct(numerix.concatenate(([0.9]*10, [1/.9]*10)))
L = numerix.sum(dx)
dx = dx / L
mesh = Grid1D(dx=dx)
A=CellVariable(mesh=mesh, name='A', hasOld=1)
x = mesh.getCellCenters()[...,0]
A.setValue(x)
print A.getGrad().getValue()
tsv=TSVViewer(vars=[A, A.getGrad()])
tsv.plot('getgrad_test.txt')