Skip to content

Commit 249a40f

Browse files
authored
Add files via upload
1 parent ac1dfb6 commit 249a40f

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

test/test_helmholtzhodge.jl

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
include("helmholtzhodge.jl")
2+
3+
using Random
4+
Random.seed!(0)
5+
6+
function sphrandn(::Type{T}, m::Int, n::Int) where T
7+
A = zeros(T, m, 2n-1)
8+
for i = 1:m
9+
A[i,1] = randn(T)
10+
end
11+
for j = 1:n-1
12+
for i = 1:m-j
13+
A[i,2j] = randn(T)
14+
A[i,2j+1] = randn(T)
15+
end
16+
end
17+
A
18+
end
19+
20+
#=
21+
N = 2 .^(5:13)
22+
t = zeros(length(N), 2)
23+
err = zeros(length(N))
24+
25+
j = 1
26+
for n in N
27+
println("This is n: ", n)
28+
U1 = sphrandn(Float64, n, n)
29+
U2 = sphrandn(Float64, n, n)
30+
U1[1] = 0
31+
U2[1] = 0
32+
Us = zero(U1); Ut = zero(U1);
33+
V1 = zero(U1); V2 = zero(U1); V3 = zero(U1); V4 = zero(U1);
34+
35+
HH = HelmholtzHodge(Float64, n)
36+
t[j, 1] = @elapsed for k = 1:10
37+
HelmholtzHodge(Float64, n)
38+
end
39+
t[j, 1] /= 10
40+
41+
gradient!(U1, V1, V2)
42+
curl!(U2, V3, V4)
43+
44+
V5 = V1 + V3
45+
V6 = V2 + V4
46+
47+
helmholtzhodge!(HH, Us, Ut, V5, V6)
48+
49+
t[j, 2] = @elapsed for k = 1:10
50+
helmholtzhodge!(HH, Us, Ut, V5, V6)
51+
end
52+
t[j, 2] /= 10
53+
global j += 1
54+
end
55+
56+
j = 1
57+
for n in N
58+
println("This is n: ", n)
59+
HH = HelmholtzHodge(Float64, n)
60+
for k = 1:10
61+
U1 = sphrandn(Float64, n, n)
62+
U2 = sphrandn(Float64, n, n)
63+
U1[1] = 0
64+
U2[1] = 0
65+
Us = zero(U1); Ut = zero(U1);
66+
V1 = zero(U1); V2 = zero(U1); V3 = zero(U1); V4 = zero(U1);
67+
68+
gradient!(U1, V1, V2)
69+
curl!(U2, V3, V4)
70+
71+
V5 = V1 + V3
72+
V6 = V2 + V4
73+
74+
helmholtzhodge!(HH, Us, Ut, V5, V6)
75+
76+
println("This is the spheroidal relative backward error: ", norm(Us-U1)/norm(U1))
77+
println("This is the toroidal relative backward error: ", norm(Ut-U2)/norm(U2))
78+
err[j] += norm(Us-U1)/norm(U1) + norm(Ut-U2)/norm(U2)
79+
end
80+
err[j] /= 10
81+
global j += 1
82+
end
83+
=#
84+
85+
using PyPlot
86+
87+
cd("/Users/Mikael/Dropbox/Helmholtz")
88+
89+
t = [0.000301073 8.59417e-5; 0.000870661 0.000313344; 0.00371459 0.0013411; 0.0158751 0.00519203; 0.0629211 0.0214159; 0.272275 0.0841661; 1.18461 0.338013; 5.22898 1.34888; 20.2509 5.41399]
90+
err = [9.73175783254202e-16, 1.1848048133640504e-15, 1.2864591012075482e-15, 1.4887354817191668e-15, 2.0250488931546365e-15, 2.714940169354596e-15, 3.426270329252532e-15, 4.804155288069517e-15, 6.620111175740055e-15]
91+
92+
clf()
93+
loglog(N.-1, t[:, 1], "xk", N.-1, t[:, 2], "+k", N.-1, (N.-1).^2/2e6, "-k")
94+
xlabel("Degree \$n\$"); ylabel("Execution Time (s)"); grid()
95+
legend(["Pre-computation","Execution","\$\\mathcal{O}(n^2)\$"])
96+
savefig("helmholtzhodgetime.pdf")
97+
98+
clf()
99+
loglog(N.-1, err, "xk", N.-1, sqrt.(N.*log.(N))*eps()/7, "-k")
100+
xlabel("Degree \$n\$"); ylabel("Relative Error"); grid()
101+
ylim((6e-16,1.2e-14))
102+
legend(["Error","\$\\mathcal{O}(\\sqrt{n \\log(n)}\\epsilon)\$"])
103+
savefig("helmholtzhodgeerror.pdf")

0 commit comments

Comments
 (0)