|
| 1 | +using Test, LinearAlgebra |
| 2 | +using MethodOfLines |
| 3 | + |
| 4 | +@testset "finite-difference weights from fornberg(1988) & fornberg(2020)" begin |
| 5 | + order = 2; z = 0.0; x = [-1, 0, 1.0]; |
| 6 | + @test MethodOfLines.calculate_weights(order, z, x) == [1,-2,1] # central difference of second-derivative with unit-step |
| 7 | + |
| 8 | + order = 1; z = 0.0; x = [-1., 1.0]; |
| 9 | + @test MethodOfLines.calculate_weights(order, z, x) == [-0.5,0.5] # central difference of first-derivative with unit step |
| 10 | + |
| 11 | + order = 1; z = 0.0; x = [0, 1]; |
| 12 | + @test MethodOfLines.calculate_weights(order, z, x) == [-1, 1] # forward difference |
| 13 | + |
| 14 | + order = 1; z = 1.0; x = [0, 1]; |
| 15 | + @test MethodOfLines.calculate_weights(order, z, x) == [-1, 1] # backward difference |
| 16 | + |
| 17 | + # forward-diff of third derivative with order of accuracy == 3 |
| 18 | + order = 3; z = 0.0; x = [0,1,2,3,4,5] |
| 19 | + @test MethodOfLines.calculate_weights(order, z, x) == [-17/4, 71/4 ,−59/2, 49/2, −41/4, 7/4] |
| 20 | + |
| 21 | + order = 3; z = 0.0; x = collect(-3:3) |
| 22 | + d, e = MethodOfLines.calculate_weights(order, z, x;dfdx = true) |
| 23 | + @test d ≈ [-167/18000, -963/2000, -171/16,0,171/16,963/2000,167/18000] |
| 24 | + @test e ≈ [-1/600,-27/200,-27/8,-49/3,-27/8,-27/200,-1/600] |
| 25 | + |
| 26 | + order = 3; z = 0.0; x = collect(-4:4) |
| 27 | + d, e = MethodOfLines.calculate_weights(order, z, x;dfdx = true) |
| 28 | + @test d ≈ [-2493/5488000, -12944/385875, -87/125 ,-1392/125,0,1392/125,87/125,12944/385875,2493/5488000] |
| 29 | + @test e ≈ [-3/39200,-32/3675,-6/25,-96/25,-205/12, -96/25, -6/25,-32/3675,-3/39200] |
| 30 | +end |
0 commit comments