On Jun 8, 2010, at 2:28 PM, Philipp Stephani wrote:
> I've checked out and installed the 2.1 branch and now I'm trying to
> solve a simple time-independent PDE with a non-constant diffusion
> tensor. The FAQ says that such diffusion terms can be created as follows:
>
>>>> x, y = mesh.getCellCenters()
>>>> DiffusionTerm([[[x**2, x * y], [-x * y, -y**2]]])
>
> However, the following example leads to an error:
>
> #!/usr/bin/env python2.6
> from fipy import *
> mesh = Grid2D(nx=5, ny=5)
> var = CellVariable(mesh=mesh)
> x, y = mesh.getCellCenters()
> diff = DiffusionTerm([[[x**2, x * y], [-x * y, -y**2]]])
> bc = FixedValue(faces=mesh.getExteriorFaces(), value=0)
> diff.solve(var=var, boundaryConditions=bc)
:
> TypeError: 'NoneType' object is unsubscriptable
>
> What am I doing wrong?
You're not doing anything wrong (other than trusting the FAQ)
Try either:
D = CellVariable(mesh=mesh, value=[[x**2, x * y], [-x * y, -y**2]], rank=2)
diff = DiffusionTerm([D])
or
X, Y = mesh.getFaceCenters()
diff = DiffusionTerm([[[X**2, X * Y], [-X * Y, -Y**2]]])
The issue is that DiffusionTerm needs a FaceVariable coefficient. If presented
with a CellVariable, it interpolates automatically, but x and y are not
CellVariables (and even if they were, [[x**2, x * y], [-x * y, -y**2]] would
not be a CellVariable, but a list of lists of CellVariables).
Filed for correct to FAQ and/or code as http://matforge.org/fipy/ticket/296.
Thanks for the succinct demonstration of the problem.