I am trying to solve the Poisson equation on a cylindrical grid.

$$ \frac{1}{r^2} \frac{\partial}{\partial r} r^2 \frac{\partial f(r, \theta)}{\partial r} = n(r, \theta) $$

Analytically, there is no angular dependence to the function $n(r, \theta)$, which is why I'm working in cylindrical coordinates. I would like to define a Dirichlet boundary condition for which $f(r_{max}(\theta), \theta) = 0$, but where $r_{max}(\theta)$ determines the distance from the origin to the boundary of a cylindrical box containing the simulation space.

Succinctly, I'd like to ask how to define a Dirichlet boundary condition on one variable which depends on the other variable for a 2D PDE.

The code I have tried is simple, but most likely naive:

sol = 
    {1/r^2 D[r^2*D[f[r, θ], r], r] == n[r], 
     Derivative[1, 0][f][0, θ] == 0, 
     DirichletCondition[f[r, θ] == 0, r == RRMAX[θ]]}, 
    f, {r, θ}]

RRMAX is defined elsewhere, although I suspect it isn't important exactly what for it has for the purpose of the question. For example,

RRMAX[θ_] := 60 (1 - 0.1 Cos[θ])

I get an error message which says the following:

The dependent variable in TemporaryVariable$xxxxxxxx[0] == 0 in the boundary condition DirichletCondition[...] needs to be linear

If anyone could help me, I'll give my firstborn to you.

  • 2
    $\begingroup$ Please provide n[r]. $\endgroup$
    – bbgodfrey
    Commented Sep 13, 2019 at 21:31
  • 1
    $\begingroup$ Can you let us know what the extend of the domain is? $\endgroup$
    – user21
    Commented Sep 16, 2019 at 6:17
  • $\begingroup$ n[r] is arbitrary, but I'm testing it with a Gaussian - n[r] = Exp[-r^2]. $\endgroup$
    – user139632
    Commented Sep 16, 2019 at 20:56
  • $\begingroup$ The domain includes r = 0 and extends up to a maximum of RMAX (~100). The domain for theta is theta in {0, Pi} $\endgroup$
    – user139632
    Commented Sep 16, 2019 at 20:57

1 Answer 1


If I understand you right:

RRMAX[\[Theta]_] := 60 (1 - 0.1 Cos[\[Theta]])
n[r] = Exp[-r^2]
sol = NDSolveValue[{1/r^2 D[r^2*D[f[r, \[Theta]], r], r] == n[r], 
   DirichletCondition[f[r, \[Theta]] == 0, r == RRMAX[100]]}, 
  f, {r, 0, RRMAX[100]}, {\[Theta], 0, 2 \[Pi]}]

NDSolveValue::femcscd: The PDE is convection dominated and the result may not be stable. Adding artificial diffusion may help.

(For the future, it's better to edit your question if you have additional information to provide. Also, to respond to comments you'd need to use @username other wise people will not know you made changes.)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.