# How do I formulate a Dirichlet boundary condition for which the boundary depends on the other variable?

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 =
NDSolve[
{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 in the boundary condition DirichletCondition[...] needs to be linear

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

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

## 1 Answer

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]},
f, {r, 0, RRMAX}, {\[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.)