Any coefficient in FiPy can be a function of space. For example, you can set the diffusion coefficient as follows,
diffusion_coefficient = dielectric_solvent * ((mesh.x > -0.5) & (mesh.x < 0.5))
and then use that directly in your equation
LHS = (DiffusionTerm(coeff = diffusion_coefficient))
Just define your spatially varying functions using the cell centers, mesh.x
and mesh.y
.
Another pointer, it might be better to change your equation to
eq = TransientTerm() == DiffusionTerm(diffusion_coefficient) - ImplicitSourceTerm(phi)
so that
the variable
phi
is solved implicitly in one sweepadding in a
TransientTerm
stabilizes the problem for me, just use a very large time step to approximate a steady state problem
See my comment on your gist for the changes.