differential-equationspoissonfipy

How to solve 1D Poisson equation with Dirichlet and Neumann boundary conditions on the same side using FiPy


Clearly an 1D Poisson equation with a constant source has an unique solution even if both Dirichlet and Newmann boundary conditions are on the same side. However I can't think of a way to solve this in FiPy. Please advise. I tried:

from fipy import CellVariable, Grid1D, DiffusionTerm
import matplotlib.pyplot as plt


L = 1.
nx = 20
dx = L/nx
mesh = Grid1D(nx=nx, dx=dx)


D = 1.
valueLeft = 1.
gradValue = 0.
source = 1.


var = CellVariable(mesh=mesh)
var.constrain(valueLeft, where=mesh.facesLeft)
var.faceGrad.constrain(gradValue, where=mesh.facesLeft)


eq = 0.0 == DiffusionTerm(coeff=D) + source
eq.solve(var=var)


plt.plot(var.value);

This is not setting gradValue at facesLeft. However, it can set the needed gradValue at facesRight.


Solution

  • Having both a Dirichlet and a Neumann on the same face in FV turns the nature of the problem from a boundary value problem into an initial value problem. In that sense the problem becomes over-specified as the right hand side boundary condition is still required. There may be ways to handle it with FD/FV with some hacks. However, FiPy certainly isn't set up to handle this type of problem.