Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

Commit c202130

Browse files
committed
add irregular grid test
1 parent f42cc79 commit c202130

1 file changed

Lines changed: 51 additions & 15 deletions

File tree

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,66 @@
1-
using DiffEqOperators
2-
3-
n = 100
4-
x=0.0:0.005:2π
5-
xprime = x[2:(end-1)]
6-
dx=diff(x)
7-
y = exp.(π*x)
8-
y_im = exp.(π*im*x)
9-
yim_ = y_im[2:(end-1)]
1+
using DiffEqOperators, SparseArrays, LinearAlgebra
2+
3+
x = 0.0:0.01:π
4+
x_ = x[2:end-1]
5+
dx = diff(x)
6+
y = sin.(2x)
107
y_ = y[2:(end-1)]
8+
dy = [2cos.(2x_),-4sin.(2x_),-8cos.(2x_),16y_,32cos.(2x_)]
9+
10+
11+
12+
# test concretization against regular grid operator
13+
for dor in 1:4, aor in 2:2:6
14+
Dr = CenteredDifference(dor,aor,dx[1],length(x)-2)
15+
Dir = CenteredDifference(dor,aor,dx,length(x)-2)
16+
17+
@test sparse(Dr)sparse(Dir)
18+
@test Array(Dr)Array(Dir)
1119

12-
@test_broken for dor in 1:6, aor in 1:6
20+
end
21+
22+
# test irregular grid operator with regular grid
23+
for dor in 1:4, aor in 2:6
1324

14-
D1 = CenteredDifference(dor,aor,dx,length(x))
25+
D1 = CenteredDifference(dor,aor,dx,length(x)-2)
1526

1627
#take derivative
1728
yprime1 = D1*y
1829

1930
#test result
20-
@test_broken yprime1 ^dor)*y_ # test operator with known derivative of exp(kx)
31+
@test yprime1 dy[dor] atol = 10.0^(1-aor)#2test operator with known derivative of exp(kx)
32+
33+
#TODO: implement specific tests for the left and right boundary regions, waiting until after update
34+
end
2135

22-
#take derivatives
23-
y_imprime1 = D1*y_im
36+
37+
# test irregular grid
38+
39+
x = sin.(0.0:0.05:π)
40+
x = cumsum(x)
41+
x = x/x[end]*π
42+
x_ = x[2:end-1]
43+
dx = diff(x)
44+
y = sin.(2x)
45+
y_ = y[2:(end-1)]
46+
dy = [2cos.(2x_), -4sin.(2x_), -8cos.(2x_), 16y_, 32cos.(2x_)]
47+
48+
for dor in 1:4, aor in 4:10
49+
50+
D1 = CenteredDifference(dor,aor,dx,length(x)-2)
51+
52+
#take derivative
53+
yprime1 = D1*y
2454

2555
#test result
26-
@test_broken y_imprime1 ((pi*im)^dor)*yim_ # test operator with known derivative of exp(jkx)
56+
tol = 2*10.0^(2-aor)*maximum(dx)^(2-dor)
57+
# error estimate is fairly difficult for high order derivatives and small dx.
58+
59+
# err = norm(yprime1.-dy[dor])
60+
# @show err
61+
# @show tol
2762

63+
@test yprime1 dy[dor] atol = tol #2test operator with known derivative of exp(kx)
2864

2965
#TODO: implement specific tests for the left and right boundary regions, waiting until after update
3066
end

0 commit comments

Comments
 (0)