Skip to content

Commit bb6a04e

Browse files
committed
tests for fractional laplacian: constant, radial and non radial
1 parent a201c75 commit bb6a04e

File tree

1 file changed

+172
-3
lines changed

1 file changed

+172
-3
lines changed

test/test_disk.jl

Lines changed: 172 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using MultivariateOrthogonalPolynomials, ClassicalOrthogonalPolynomials, StaticArrays, BlockArrays, BandedMatrices, FastTransforms, LinearAlgebra, RecipesBase, Test
1+
using MultivariateOrthogonalPolynomials, ClassicalOrthogonalPolynomials, StaticArrays, BlockArrays, BandedMatrices, FastTransforms, LinearAlgebra, RecipesBase, Test, SpecialFunctions
22
import MultivariateOrthogonalPolynomials: DiskTrav, grid, ZernikeTransform, ZernikeITransform, *
33
import ClassicalOrthogonalPolynomials: HalfWeighted
44

@@ -247,11 +247,180 @@ import ClassicalOrthogonalPolynomials: HalfWeighted
247247
end
248248

249249
@testset "Fractional Laplacian on Disk: (-Δ)^(β) == -Δ when β=1" begin
250-
# setup
251250
WZ = Weighted(Zernike(1.))
252251
Δ = Laplacian(axes(WZ,1))
253252
Δ_Z = Zernike(1) \* WZ)
254253
Δfrac = AbsLaplacianPower(axes(WZ,1),1.)
255254
Δ_Zfrac = Zernike(1) \ (Δfrac * WZ)
256255
@test Δ_Z[1:100,1:100] -Δ_Zfrac[1:100,1:100]
257-
end
256+
end
257+
258+
@testset "Fractional Laplacian on Disk: Computing f where (-Δ)^(β) u = f" begin
259+
@testset "Set 1 - Explicitly known constant f" begin
260+
# set up basis
261+
β = 1.34
262+
Z = Zernike(β)
263+
WZ = Weighted(Z)
264+
xy = axes(WZ,1)
265+
x,y = first.(xy),last.(xy)
266+
# generate fractional Laplacian
267+
Δfrac = AbsLaplacianPower(axes(WZ,1),β)
268+
Δ_Zfrac = Z \ (Δfrac * WZ)
269+
# define function whose fractional Laplacian is a known constant
270+
u = @. (1 - x^2 - y^2).^β
271+
# explicit and computed solutions
272+
fexplicit0(d,α) = 2^α*gamma/2+1)*gamma((d+α)/2)/gamma(d/2) # note that here, α = 2*β
273+
f = Z*(Δ_Zfrac*(WZ \ u))
274+
# compare
275+
@test fexplicit0(2,2*β) f[(0.1,0.4)] f[(0.1137,0.001893)] f[(0.3721,0.3333)]
276+
277+
# again for different β
278+
β = 2.11
279+
Z = Zernike(β)
280+
WZ = Weighted(Z)
281+
xy = axes(WZ,1)
282+
x,y = first.(xy),last.(xy)
283+
# generate fractional Laplacian
284+
Δfrac = AbsLaplacianPower(axes(WZ,1),β)
285+
Δ_Zfrac = Z \ (Δfrac * WZ)
286+
# define function whose fractional Laplacian is a known constant
287+
u = @. (1 - x^2 - y^2).^β
288+
# computed solution
289+
f = Z*(Δ_Zfrac*(WZ \ u))
290+
# compare
291+
@test fexplicit0(2,2*β) f[(0.14,0.41)] f[(0.1731,0.091893)] f[(0.3791,0.333333)]
292+
293+
# again for different β
294+
β = 3.14159
295+
Z = Zernike(β)
296+
WZ = Weighted(Z)
297+
xy = axes(WZ,1)
298+
x,y = first.(xy),last.(xy)
299+
# generate fractional Laplacian
300+
Δfrac = AbsLaplacianPower(axes(WZ,1),β)
301+
Δ_Zfrac = Z \ (Δfrac * WZ)
302+
# define function whose fractional Laplacian is a known constant
303+
u = @. (1 - x^2 - y^2).^β
304+
# computed solution
305+
f = Z*(Δ_Zfrac*(WZ \ u))
306+
# compare
307+
@test fexplicit0(2,2*β) f[(0.14,0.41)] f[(0.1837,0.101893)] f[(0.37222,0.2222)]
308+
end
309+
@testset "Set 2 - Explicitly known radially symmetric f" begin
310+
β = 1.1
311+
Z = Zernike(β)
312+
WZ = Weighted(Z)
313+
xy = axes(WZ,1)
314+
x,y = first.(xy),last.(xy)
315+
# generate fractional Laplacian
316+
Δfrac = AbsLaplacianPower(axes(WZ,1),β)
317+
Δ_Zfrac = Z \ (Δfrac * WZ)
318+
# define function whose fractional Laplacian is a known constant
319+
u = @. (1 - x^2 - y^2).^+1)
320+
# explicit and computed solutions
321+
fexplicit1(d,α,x) = 2^α*gamma/2+2)*gamma((d+α)/2)/gamma(d/2)*(1-(1+α/d)*norm(x)^2) # α = 2*β
322+
f = Z*(Δ_Zfrac*(WZ \ u))
323+
# compare
324+
@test fexplicit1(2,2*β,(0.94,0.01)) f[(0.94,0.01)]
325+
@test fexplicit1(2,2*β,(0.14,0.41)) f[(0.14,0.41)]
326+
@test fexplicit1(2,2*β,(0.221,0.333)) f[(0.221,0.333)]
327+
328+
# again for different β
329+
β = 2.71999
330+
Z = Zernike(β)
331+
WZ = Weighted(Z)
332+
xy = axes(WZ,1)
333+
x,y = first.(xy),last.(xy)
334+
# generate fractional Laplacian
335+
Δfrac = AbsLaplacianPower(axes(WZ,1),β)
336+
Δ_Zfrac = Z \ (Δfrac * WZ)
337+
# define function whose fractional Laplacian is a known constant
338+
u = @. (1 - x^2 - y^2).^+1)
339+
# explicit and computed solutions
340+
f = Z*(Δ_Zfrac*(WZ \ u))
341+
# compare
342+
@test fexplicit1(2,2*β,(0.94,0.01)) f[(0.94,0.01)]
343+
@test fexplicit1(2,2*β,(0.14,0.41)) f[(0.14,0.41)]
344+
@test fexplicit1(2,2*β,(0.221,0.333)) f[(0.221,0.333)]
345+
end
346+
@testset "Set 3 - Explicitly known f, not radially symmetric" begin
347+
# dependence on x
348+
β = 2.71999
349+
Z = Zernike(β)
350+
WZ = Weighted(Z)
351+
xy = axes(WZ,1)
352+
x,y = first.(xy),last.(xy)
353+
# generate fractional Laplacian
354+
Δfrac = AbsLaplacianPower(axes(WZ,1),β)
355+
Δ_Zfrac = Z \ (Δfrac * WZ)
356+
# define function whose fractional Laplacian is a known constant
357+
u = @. (1 - x^2 - y^2).^(β)*x
358+
# explicit and computed solutions
359+
fexplicit2(d,α,x) = 2^α*gamma/2+1)*gamma((d+α)/2+1)/gamma(d/2+1)*x[1] # α = 2*β
360+
f = Z*(Δ_Zfrac*(WZ \ u))
361+
# compare
362+
@test fexplicit2(2,2*β,(0.94,0.01)) f[(0.94,0.01)]
363+
@test fexplicit2(2,2*β,(0.14,0.41)) f[(0.14,0.41)]
364+
@test fexplicit2(2,2*β,(0.221,0.333)) f[(0.221,0.333)]
365+
366+
# different β, dependence on y
367+
β = 1.91239
368+
Z = Zernike(β)
369+
WZ = Weighted(Z)
370+
xy = axes(WZ,1)
371+
x,y = first.(xy),last.(xy)
372+
# generate fractional Laplacian
373+
Δfrac = AbsLaplacianPower(axes(WZ,1),β)
374+
Δ_Zfrac = Z \ (Δfrac * WZ)
375+
# define function whose fractional Laplacian is a known constant
376+
u = @. (1 - x^2 - y^2).^(β)*y
377+
# explicit and computed solutions
378+
fexplicit3(d,α,x) = 2^α*gamma/2+1)*gamma((d+α)/2+1)/gamma(d/2+1)*x[2] # α = 2*β
379+
f = Z*(Δ_Zfrac*(WZ \ u))
380+
# compare
381+
@test fexplicit3(2,2*β,(0.94,0.01)) f[(0.94,0.01)]
382+
@test fexplicit3(2,2*β,(0.14,0.41)) f[(0.14,0.41)]
383+
@test fexplicit3(2,2*β,(0.221,0.333)) f[(0.221,0.333)]
384+
end
385+
@testset "Set 4 - Explicitly known f, different non-radially-symmetric example" begin
386+
# dependence on x
387+
β = 1.21999
388+
Z = Zernike(β)
389+
WZ = Weighted(Z)
390+
xy = axes(WZ,1)
391+
x,y = first.(xy),last.(xy)
392+
# generate fractional Laplacian
393+
Δfrac = AbsLaplacianPower(axes(WZ,1),β)
394+
Δ_Zfrac = Z \ (Δfrac * WZ)
395+
# define function whose fractional Laplacian is a known constant
396+
u = @. (1 - x^2 - y^2).^+1)*x
397+
# explicit and computed solutions
398+
fexplicit4(d,α,x) = 2^α*gamma/2+2)*gamma((d+α)/2+1)/gamma(d/2+1)*(1-(1+α/(d+2))*norm(x)^2)*x[1] # α = 2*β
399+
f = Z*(Δ_Zfrac*(WZ \ u))
400+
# compare
401+
@test fexplicit4(2,2*β,(0.94,0.01)) f[(0.94,0.01)]
402+
@test fexplicit4(2,2*β,(0.14,0.41)) f[(0.14,0.41)]
403+
@test fexplicit4(2,2*β,(0.221,0.333)) f[(0.221,0.333)]
404+
405+
# different β, dependence on y
406+
β = 0.141
407+
Z = Zernike(β)
408+
WZ = Weighted(Z)
409+
xy = axes(WZ,1)
410+
x,y = first.(xy),last.(xy)
411+
# generate fractional Laplacian
412+
Δfrac = AbsLaplacianPower(axes(WZ,1),β)
413+
Δ_Zfrac = Z \ (Δfrac * WZ)
414+
# define function whose fractional Laplacian is a known constant
415+
u = @. (1 - x^2 - y^2).^+1)*y
416+
# explicit and computed solutions
417+
fexplicit5(d,α,x) = 2^α*gamma/2+2)*gamma((d+α)/2+1)/gamma(d/2+1)*(1-(1+α/(d+2))*norm(x)^2)*x[2] # α = 2*β
418+
f = Z*(Δ_Zfrac*(WZ \ u))
419+
# compare
420+
@test fexplicit5(2,2*β,(0.94,0.01)) f[(0.94,0.01)]
421+
@test fexplicit5(2,2*β,(0.14,0.41)) f[(0.14,0.41)]
422+
@test fexplicit5(2,2*β,(0.221,0.333)) f[(0.221,0.333)]
423+
end
424+
end
425+
426+

0 commit comments

Comments
 (0)