# Poisson equation solver

**URL:** <https://discourse.julialang.org/t/poisson-equation-solver/19786>\
**Category:** General Usage\
**Tags:** question, diffeq\
**Created:** [January 18, 2019, 2:23pm UTC](https://discourse.julialang.org/t/poisson-equation-solver/19786 "2019-01-18T14:23:21Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [January 18, 2019, 2:23pm UTC](https://discourse.julialang.org/t/poisson-equation-solver/19786/1 "2019-01-18T14:23:21Z")

</div>

I would like to solve the [poisson equation](https://en.wikipedia.org/wiki/Poisson%27s_equation) on an [annulus](https://en.wikipedia.org/wiki/Annulus_(mathematics)) (the problem is also rotation symmetric).  
Is there a recommended package for this? Ideally I would like something that does not need manual installation of dependencies and can do the job in \< 50 lines of code say. I do remember, that there was some basic PDE support in `DiffEq`, but it seems that it is gone?

---

<div class="post-metadata">

**Author:** ![isaacsas](https://avatars.discourse-cdn.com/v4/letter/i/f6c823/32.png) [@isaacsas](https://discourse.julialang.org/u/isaacsas)\
**Post date:** [January 18, 2019, 4:11pm UTC](https://discourse.julialang.org/t/poisson-equation-solver/19786/2 "2019-01-18T16:11:20Z")

</div>

Have you looked at Approxfun.jl? If you can assume the problem is radially symmetric you just have an ODE BVP, which they show how to solve in the readme for several examples.

---

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [January 18, 2019, 4:20pm UTC](https://discourse.julialang.org/t/poisson-equation-solver/19786/3 "2019-01-18T16:20:13Z")

</div>

Thanks thats a clever idea! I guess I could also use DiffEq for the ODE then. I am still interested in a PDE solution (I want to tweak the problem later and then it is not rotation symmetric anymore).

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [January 18, 2019, 4:30pm UTC](https://discourse.julialang.org/t/poisson-equation-solver/19786/4 "2019-01-18T16:30:20Z")

</div>

You can also use the space `Fourier() * Chebyshev(a..b)` for an annulus

---

<div class="post-metadata">

**Author:** ![isaacsas](https://avatars.discourse-cdn.com/v4/letter/i/f6c823/32.png) [@isaacsas](https://discourse.julialang.org/u/isaacsas)\
**Post date:** [January 18, 2019, 4:32pm UTC](https://discourse.julialang.org/t/poisson-equation-solver/19786/5 "2019-01-18T16:32:32Z")

</div>

That is good to know. I figured there was an easy way to use ApproxFun.jl to do this, but haven’t really learned the package well-enough yet to know what it is myself…

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [January 18, 2019, 4:33pm UTC](https://discourse.julialang.org/t/poisson-equation-solver/19786/6 "2019-01-18T16:33:33Z")

</div>

The examples might help here, there’s several examples of PDEs with different spaces: [GitHub - JuliaApproximation/ApproxFunExamples: Examples for using ApproFun.jl](https://github.com/JuliaApproximation/ApproxFunExamples)

---

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [January 19, 2019, 1:55pm UTC](https://discourse.julialang.org/t/poisson-equation-solver/19786/7 "2019-01-19T13:55:07Z")

</div>

@dlfivefifty Can you help me with the boundary conditions? I just want Dirichlet = 0. condition along the boundary of the annulus. So I need no condition in the “Fourier direction” and the Dirichlet condition in the “Chebyshev direction”, right?. But I am not sure to code this?

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [January 19, 2019, 9:38pm UTC](https://discourse.julialang.org/t/poisson-equation-solver/19786/8 "2019-01-19T21:38:15Z")

</div>

For zero Dirichlet the easiest is to incorporate it into the basis, this seems to work well:

```julia
using ApproxFun

S = JacobiWeight(1,1,Jacobi(1,1,1..2)) * Fourier()
r = Fun((r,θ) -> r, Chebyshev(1..2) * Fourier())
f = Fun((r,θ) -> exp(r*cos(θ)), Jacobi(1,1,1..2) * Fourier())
Dr = Derivative([1,0]) : S
Dθ = Derivative([0,1]) : S;
r2L = r^2 * Dr^2 + r * Dr + Dθ^2 
u = \(r2L, r^2 * f; tolerance=1E-8)

```

Though it’s not particularly fast.

---

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [January 19, 2019, 10:24pm UTC](https://discourse.julialang.org/t/poisson-equation-solver/19786/9 "2019-01-19T22:24:32Z")

</div>

Thanks! I am trying to understand this a bit better. I am not very familiar with Jacobi polynomials, is it correct that `JacobiWeight(1,1,Jacobi(1,1,1..2))` is a basis that consists of functions vanishing at the boundary points? And `operator : S` restricts the domain of the operator to a function space `S`?

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [January 19, 2019, 10:35pm UTC](https://discourse.julialang.org/t/poisson-equation-solver/19786/10 "2019-01-19T22:35:44Z")

</div>

Pretty much. `JacobiWeight(b, a, space)` on `-1..1` weights the `space` by `(1+x)^b*(1-x)^a`, so if `a = b = 1` then we get vanishing at the boundary. If the interval is other than `-1..1`, everything is translated to `-1..1` first. `Jacobi(1,1,1..2)` is then the space, it could probably be `Chebyshev(1..2)`, but Jacobi polynomials have some special relationships that mean the operators are a bit sparser.

But given how slow the calculation is, this not clearly being leveraged properly. Probably because the operators are falling back to slow `getindex` instead of fast operator building routines. There’s a long term goal to make this “high performance” via LazyArrays.jl + InfiniteArrays.jl + BlockBandedMatrices.jl, but that’s probably a year away from coming together. (This is a really “easy” problem as there are no corners, so if the generation of the operators was fast enough, it should feel instantaneous.)

---

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [January 19, 2019, 10:47pm UTC](https://discourse.julialang.org/t/poisson-equation-solver/19786/11 "2019-01-19T22:47:16Z")

</div>

> [@dlfivefifty](#):
>
> `JacobiWeight(b, a, space)` on `-1..1` weights the `space` by `(1+x)^b*(1-x)^a`

Weighting a space by `w` means replacing the measure `mu` by `w^(-2) * mu` and each basis element `f_i` by `w*f_i`?

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [January 19, 2019, 10:53pm UTC](https://discourse.julialang.org/t/poisson-equation-solver/19786/12 "2019-01-19T22:53:55Z")

</div>

There’s no notion of “measure”/inner product in ApproxFun, a space is usually just a span of a basis. The second part is correct: the basis is weighted as `w*f_i`.

---

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [January 19, 2019, 11:11pm UTC](https://discourse.julialang.org/t/poisson-equation-solver/19786/13 "2019-01-19T23:11:23Z")

</div>

Thanks again for all the detailed answers! And of course for creating `ApproxFun`. It amazes me how easy to use and powerful it is at the same time!
