|
| 1 | +# # Integration on an annulus |
| 2 | +# In this example, we explore integration of the function: |
| 3 | +# ```math |
| 4 | +# f(x,y) = \frac{x^3}{x^2+y^2-\frac{1}{4}}, |
| 5 | +# ``` |
| 6 | +# over the annulus defined by $\{(r,\theta) : \frac{2}{3} < r < 1, 0 < \theta < 2\pi\}$. |
| 7 | +# We will calculate the integral: |
| 8 | +# ```math |
| 9 | +# \int_0^{2\pi}\int_{\frac{2}{3}}^1 f(r\cos\theta,r\sin\theta)^2r{\rm\,d}r{\rm\,d}\theta, |
| 10 | +# ``` |
| 11 | +# by analyzing the function in an annulus polynomial series. |
| 12 | +# We analyze the function on an $N\times M$ tensor product grid defined by: |
| 13 | +# ```math |
| 14 | +# \begin{aligned} |
| 15 | +# r_n & = \sqrt{\cos^2\left[(n+\tfrac{1}{2})\pi/2N\right] + \rho^2 \sin^2\left[(n+\tfrac{1}{2})\pi/2N\right]},\quad{\rm for}\quad 0\le n < N,\quad{\rm and}\\ |
| 16 | +# \theta_m & = 2\pi m/M,\quad{\rm for}\quad 0\le m < M; |
| 17 | +# \end{aligned} |
| 18 | +# ``` |
| 19 | +# we convert the function samples to Chebyshev×Fourier coefficients using |
| 20 | +# `plan_annulus_analysis`; and finally, we transform the Chebyshev×Fourier |
| 21 | +# coefficients to annulus polynomial coefficients using `plan_ann2cxf`. |
| 22 | +# |
| 23 | +# For the storage pattern of the arrays, please consult the |
| 24 | +# [documentation](https://MikaelSlevinsky.github.io/FastTransforms). |
| 25 | + |
| 26 | +using FastTransforms, LinearAlgebra, Plots |
| 27 | +const GENFIGS = joinpath(pkgdir(FastTransforms), "docs/src/generated") |
| 28 | +!isdir(GENFIGS) && mkdir(GENFIGS) |
| 29 | +plotlyjs() |
| 30 | + |
| 31 | +# Our function $f$ on the annulus: |
| 32 | +f = (x,y) -> x^3/(x^2+y^2-1/4) |
| 33 | + |
| 34 | +# The annulus polynomial degree: |
| 35 | +N = 8 |
| 36 | +M = 4N-3 |
| 37 | + |
| 38 | +# The annulus inner radius: |
| 39 | +ρ = 2/3 |
| 40 | + |
| 41 | +# The radial grid: |
| 42 | +r = [begin t = (N-n-0.5)/(2N); ct2 = sinpi(t); st2 = cospi(t); sqrt(ct2^2+ρ^2*st2^2) end; for n in 0:N-1] |
| 43 | + |
| 44 | +# The angular grid (mod $\pi$): |
| 45 | +θ = (0:M-1)*2/M |
| 46 | + |
| 47 | +# On the mapped tensor product grid, our function samples are: |
| 48 | +F = [f(r*cospi(θ), r*sinpi(θ)) for r in r, θ in θ] |
| 49 | + |
| 50 | +# We superpose a surface plot of $f$ on top of the grid: |
| 51 | +X = [r*cospi(θ) for r in r, θ in θ] |
| 52 | +Y = [r*sinpi(θ) for r in r, θ in θ] |
| 53 | +scatter3d(vec(X), vec(Y), vec(0F); markersize=0.75, markercolor=:red) |
| 54 | +surface!(X, Y, F; legend=false, xlabel="x", ylabel="y", zlabel="f") |
| 55 | +savefig(joinpath(GENFIGS, "annulus.html")) |
| 56 | +###```@raw html |
| 57 | +###<object type="text/html" data="../annulus.html" style="width:100%;height:400px;"></object> |
| 58 | +###``` |
| 59 | + |
| 60 | +# We precompute an Annulus--Chebyshev×Fourier plan: |
| 61 | +α, β, γ = 0, 0, 0 |
| 62 | +P = plan_ann2cxf(F, α, β, γ, ρ) |
| 63 | + |
| 64 | +# And an FFTW Chebyshev×Fourier analysis plan on the annulus: |
| 65 | +PA = plan_annulus_analysis(F, ρ) |
| 66 | + |
| 67 | +# Its annulus coefficients are: |
| 68 | +U = P\(PA*F) |
| 69 | + |
| 70 | +# The annulus coefficients are useful for integration. |
| 71 | +# The integral of $[f(x,y)]^2$ over the annulus is |
| 72 | +# approximately the square of the 2-norm of the coefficients: |
| 73 | +norm(U)^2, 5π/8*(1675/4536+9*log(3)/32-3*log(7)/32) |
0 commit comments