-
Notifications
You must be signed in to change notification settings - Fork 12
/
fourier_operators_2d_test.jl
57 lines (49 loc) · 2.05 KB
/
fourier_operators_2d_test.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using Test, SummationByPartsOperators
using LinearAlgebra
function accuracy_test!(res, ufunc, dufunc, D, direction)
u = compute_coefficients(ufunc, D)
du = compute_coefficients(dufunc, D)
mul!(res, D, u, direction)
maximum(abs, du-res) < 5*length(res)*eps(eltype(res))
end
# Accuracy Tests
for T in (Float32, Float64)
xmin = -one(T)
xmax = one(T)
ymin = -one(T)
ymax = one(T)
for N in 2 .^ (3:6)
D = fourier_derivative_operator(xmin, xmax, N, ymin, ymax, N)
println(devnull, D)
@test SummationByPartsOperators.derivative_order(D) == 1
@test issymmetric(D) == false
u = compute_coefficients(zero ∘ eltype, D)
res = similar(u)
for k in 0:(N÷2)-1
ufunc = x->sinpi(k*x[1])
dufunc = x->eltype(x)(k*π)*cospi(k*x[1])
@test accuracy_test!(res, ufunc, dufunc, D, Val(:x))
xplot, duplot = evaluate_coefficients(res, D)
@test maximum(abs, duplot - dufunc.(xplot)) < 5N*eps(T)
@test abs(integrate(u, D)) < N*eps(T)
ufunc = x->cospi(k*x[1])
dufunc = x->-eltype(x)(k*π)*sinpi(k*x[1])
@test accuracy_test!(res, ufunc, dufunc, D, Val(:x))
xplot, duplot = evaluate_coefficients(res, D)
@test maximum(abs, duplot - dufunc.(xplot)) < 5N*eps(T)
@test abs(integrate(u, D)) < N*eps(T)
ufunc = x->sinpi(k*x[2])
dufunc = x->eltype(x)(k*π)*cospi(k*x[2])
@test accuracy_test!(res, ufunc, dufunc, D, Val(:y))
xplot, duplot = evaluate_coefficients(res, D)
@test maximum(abs, duplot - dufunc.(xplot)) < 5N*eps(T)
@test abs(integrate(u, D)) < N*eps(T)
ufunc = x->cospi(k*x[2])
dufunc = x->-eltype(x)(k*π)*sinpi(k*x[2])
@test accuracy_test!(res, ufunc, dufunc, D, Val(:y))
xplot, duplot = evaluate_coefficients(res, D)
@test maximum(abs, duplot - dufunc.(xplot)) < 5N*eps(T)
@test abs(integrate(u, D)) < N*eps(T)
end
end
end