- All FiPy meshes can be displaced from \vec{0} by adding a vector of appropriate dimensionality, e.g.,
>>> m1 = fp.Grid1D(nx=10, dx=.5) + [[5.]]
>>> print m1.cellCenters
[[ 5.25 5.75 6.25 6.75 7.25 7.75 8.25 8.75 9.25 9.75]]
>>> m2 = fp.Grid2D(nx=3, ny=2, dx=.2, dy=.7) + [[2.], [8.]]
>>> print m2.cellCenters
[[ 2.1 2.3 2.5 2.1 2.3 2.5 ]
[ 8.35 8.35 8.35 9.05 9.05 9.05]]
mesh.cellCenters
is a CellVariable
and mesh.faceCenters
is a FaceVariable
, so just write your expression as you would any other:
>>> x = mesh.cellCenters[0]
>>> D = x**2 + 3.
Because FiPy interpolates diffusion coefficients defined at cell centers onto the face centers, thus you'll probably get more accurate results if you define your coefficient on face centers yourself
>>> X = mesh.faceCenters[0]
>>> D = X**2 + 3.
(see https://www.ctcms.nist.gov/fipy/documentation/FAQ.html#why-the-distinction-between-cellvariable-and-facevariable-coefficients)