Hi,

I'm trying to solve the diffusion equation with a moving point source. In otherwords,

        \partial\phi/\partial t = \nabla^2 \phi + \delta(x_s(t))

To represent the delta function on a discrete grid, I need to initialize a zero array and set certain points on the grid (given by position x_s) to non-zero values. Unfortunately, x_s is a function of time, but indexing an array with a Variable object doesn't retain lazy evaluation. Here's a toy example:

#############
from fipy import *

mesh = Grid1D(nx=10)
phi = CellVariable(mesh=mesh, value=0)
delta = CellVariable(mesh=mesh, value=0)
time = Variable(value=0)

x_s = time
x, = mesh.getCellCenters()
delta.setValue(1, where=(x > x_s) * (x < x_s + 1))

eq = TransientTerm() == ImplicitDiffusionTerm(coeff=1.) + delta
BCs = (FixedValue(faces=mesh.getFacesLeft(), value=0.),
       FixedValue(faces=mesh.getFacesRight(), value=0.))
for t in range(0, 10):
    time.setValue(t)
    print delta
    eq.solve(phi, dt=1)
#############

In this example, the loop doesn't change `delta` because `delta.setValue` evaluates the `x_s` Variable such that it's no longer affected by changes to `time`. Is it possible to index arrays with Variable objects and retain lazy evaluation capabilities?

Alternatively, if I move `delta.setValue` into the loop, I get something similar to the desired solution (i.e. I have a moving source). But I believe this gives me an incorrect solution (checked against analytical solution) since the time integration would assume that the source has a fixed position during each time interval `dt`.

Any ideas?

Thanks,
-Tony

Reply via email to