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

Commit e777fba

Browse files
committed
coverage tests added
1 parent 6484158 commit e777fba

2 files changed

Lines changed: 62 additions & 6 deletions

File tree

test/KdV.jl

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ using DiffEqOperators, OrdinaryDiffEq, LinearAlgebra
4545
@test soln(t) ϕ(x,t) atol = 0.01;
4646
end
4747

48-
# Using Biased Upwinds with 1 offside pont
48+
# Using Biased Upwinds with 1 offside point
4949
A2 = UpwindDifference{Float64}(1,3,Δx,length(x),-1,offside=1);
5050
function KdV(du, u, p, t)
5151
bc = GeneralBC([0,1,-6*ϕ(-10,t),0,-1],[0,1,-6*ϕ(10,t),0,-1],Δx,3)
@@ -56,6 +56,7 @@ using DiffEqOperators, OrdinaryDiffEq, LinearAlgebra
5656
for t in 0:0.5:5
5757
@test soln(t) ϕ(x,t) atol = 0.01;
5858
end
59+
5960
A3 = UpwindDifference{Float64}(1,3,Δx*ones(length(x)+1),length(x),-1,offside=1);
6061
function KdV(du, u, p, t)
6162
bc = GeneralBC([0,1,-6*ϕ(-10,t),0,-1],[0,1,-6*ϕ(10,t),0,-1],Δx,3)
@@ -66,6 +67,29 @@ using DiffEqOperators, OrdinaryDiffEq, LinearAlgebra
6667
for t in 0:0.5:5
6768
@test soln(t) ϕ(x,t) atol = 0.01;
6869
end
70+
71+
# Using Biased Upwinds with 2 offside points
72+
A4 = UpwindDifference{Float64}(1,4,Δx,length(x),-1,offside=2);
73+
function KdV(du, u, p, t)
74+
bc = GeneralBC([0,1,-6*ϕ(-10,t),0,-1],[0,1,-6*ϕ(10,t),0,-1],Δx,3)
75+
mul!(du,A4,bc*u)
76+
end
77+
single_solition = ODEProblem(KdV, u0, (0.,5.));
78+
soln = solve(single_solition,Tsit5(),abstol=1e-6,reltol=1e-6);
79+
for t in 0:0.5:5
80+
@test soln(t) ϕ(x,t) atol = 0.01;
81+
end
82+
83+
A5 = UpwindDifference{Float64}(1,4,Δx,length(x),1,offside=2);
84+
function KdV(du, u, p, t)
85+
bc = GeneralBC([0,1,-6*ϕ(-10,t),0,-1],[0,1,-6*ϕ(10,t),0,-1],Δx,3)
86+
mul!(du,-1*A5,bc*u)
87+
end
88+
single_solition = ODEProblem(KdV, u0, (0.,5.));
89+
soln = solve(single_solition,Tsit5(),abstol=1e-6,reltol=1e-6);
90+
for t in 0:0.5:5
91+
@test soln(t) ϕ(x,t) atol = 0.01;
92+
end
6993
end
7094

7195
# Conduct interesting experiments by referring to

test/heat_eqn.jl

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ end
3333
dx = 2π/(N-1)
3434
x = collect(-pi : dx : pi)
3535
u0 = @. -(x - 0.5)^2 + 1/12
36-
B = CenteredDifference(1,2,dx,N)
36+
B = CenteredDifference(1,2,dx,N-2)
3737
deriv_start, deriv_end = (B*u0)[1], (B*u0)[end]
3838

3939
A = CenteredDifference(2,2,dx,N)
@@ -53,6 +53,23 @@ end
5353

5454
# UpwindDifference with equal no. of primay wind and offside points should behave like a CenteredDifference
5555
A2 = UpwindDifference(2,1,dx,N,1,offside=1)
56+
B2 = UpwindDifference(1,2,dx,N-2,1,offside=1)
57+
deriv_start, deriv_end = (B2*u0)[1], (B2*u0)[end]
58+
bc = NeumannBC((deriv_start,deriv_end),dx,1)
59+
60+
step(u,p,t) = A2*bc*u
61+
heat_eqn = ODEProblem(step, u0, (0.,10.))
62+
soln = solve(heat_eqn,Tsit5(),dense=false,tstops=0:0.01:10)
63+
64+
for t in 0:0.1:10
65+
@test sum(first_order_coeffs_start .* soln(t)[1:4]) deriv_start atol=1e-1
66+
@test sum(first_order_coeffs_end .* soln(t)[end-3:end]) deriv_end atol=1e-1
67+
end
68+
# Testing for 2 offside points against Standard Vector input
69+
B3 = UpwindDifference(1,4,dx,N-2,-1,offside=2)
70+
deriv_start, deriv_end = (-1*B3*u0)[1], (-1*B3*u0)[end]
71+
bc = NeumannBC((deriv_start,deriv_end),dx,1)
72+
5673
step(u,p,t) = A2*bc*u
5774
heat_eqn = ODEProblem(step, u0, (0.,10.))
5875
soln = solve(heat_eqn,Tsit5(),dense=false,tstops=0:0.01:10)
@@ -68,7 +85,7 @@ end
6885
dx = 2π/(N-1)
6986
x = collect(-pi : dx : pi)
7087
u0 = @. -(x - 0.5)^2 + 1/12
71-
B = CenteredDifference(1,2,dx,N);
88+
B = CenteredDifference(1,2,dx,N-2);
7289
deriv_start, deriv_end = (B*u0)[1], (B*u0)[end]
7390
params = [1.0,0.5]
7491

@@ -92,13 +109,28 @@ end
92109
end
93110

94111
# UpwindDifference with equal no. of primay wind and offside points should behave like a CenteredDifference
95-
A2 = UpwindDifference(2,1,dx*ones(513),N,1,offside=1);
96-
B2 = UpwindDifference(1,2,dx,N,1,offside=1)
112+
A2 = UpwindDifference(2,1,dx*ones(N+1),N,1,offside=1)
113+
B2 = UpwindDifference(1,2,dx*ones(N-1),N-2,1,offside=1)
97114
deriv_start, deriv_end = (B2*u0)[1], (B2*u0)[end]
98115
left_RBC = params[1]*u0[1] - params[2]*deriv_start
99116
right_RBC = params[1]*u0[end] + params[2]*deriv_end
100117
bc = RobinBC((params[1],-params[2],left_RBC), (params[1],params[2],right_RBC),dx,1);
101-
118+
119+
step(u,p,t) = A2*bc*u
120+
heat_eqn = ODEProblem(step, u0, (0.,10.));
121+
soln = solve(heat_eqn,Tsit5(),dense=false,tstops=0:0.01:10);
122+
123+
for t in 0.2:0.1:9.8
124+
@test params[1]*soln(t)[1] - params[2]*sum(first_order_coeffs_start .* soln(t)[1:4]) left_RBC atol=1e-1
125+
@test params[1]*soln(t)[end] + params[2]*sum(first_order_coeffs_end .* soln(t)[end-3:end]) right_RBC atol=1e-1
126+
end
127+
# Testing for 2 offside points against Standard Vector input
128+
B3 = UpwindDifference(1,4,dx*ones(N-1),N-2,-1,offside=2)
129+
deriv_start, deriv_end = (-1*B3*u0)[1], (-1*B3*u0)[end]
130+
left_RBC = params[1]*u0[1] - params[2]*deriv_start
131+
right_RBC = params[1]*u0[end] + params[2]*deriv_end
132+
bc = RobinBC((params[1],-params[2],left_RBC), (params[1],params[2],right_RBC),dx,1);
133+
102134
step(u,p,t) = A2*bc*u
103135
heat_eqn = ODEProblem(step, u0, (0.,10.));
104136
soln = solve(heat_eqn,Tsit5(),dense=false,tstops=0:0.01:10);

0 commit comments

Comments
 (0)