|
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) |
10 | 7 | 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) |
11 | 19 |
|
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 |
13 | 24 |
|
14 | | - D1 = CenteredDifference(dor,aor,dx,length(x)) |
| 25 | + D1 = CenteredDifference(dor,aor,dx,length(x)-2) |
15 | 26 |
|
16 | 27 | #take derivative |
17 | 28 | yprime1 = D1*y |
18 | 29 |
|
19 | 30 | #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 |
21 | 35 |
|
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 |
24 | 54 |
|
25 | 55 | #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 |
27 | 62 |
|
| 63 | + @test yprime1 ≈ dy[dor] atol = tol #2test operator with known derivative of exp(kx) |
28 | 64 |
|
29 | 65 | #TODO: implement specific tests for the left and right boundary regions, waiting until after update |
30 | 66 | end |
0 commit comments