0

I am trying to use fipy to solve a non linear pde and i have a couple of questions regarding the usage.

1- can i set the grid1D object to start from a specific number rather than 0 ?

2- is it possible to use a coefficient variable with x as a diffusion coefficient ( if the phi is a function of t and x)? And how to do it?

BerlAb
  • 1
  • Please, take a few minutes to read [how to ask useful questions](https://stackoverflow.com/help/mcve) and improve yours. – LMC Feb 06 '18 at 00:07

1 Answers1

0
  1. 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]]
  1. 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)

jeguyer
  • 2,379
  • 1
  • 11
  • 15