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

Commit

Permalink
coverage tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
mjsheikh committed Mar 21, 2021
1 parent 6484158 commit e777fba
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 6 deletions.
26 changes: 25 additions & 1 deletion test/KdV.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ using DiffEqOperators, OrdinaryDiffEq, LinearAlgebra
@test soln(t) ϕ(x,t) atol = 0.01;
end

# Using Biased Upwinds with 1 offside pont
# Using Biased Upwinds with 1 offside point
A2 = UpwindDifference{Float64}(1,3,Δx,length(x),-1,offside=1);
function KdV(du, u, p, t)
bc = GeneralBC([0,1,-6*ϕ(-10,t),0,-1],[0,1,-6*ϕ(10,t),0,-1],Δx,3)
Expand All @@ -56,6 +56,7 @@ using DiffEqOperators, OrdinaryDiffEq, LinearAlgebra
for t in 0:0.5:5
@test soln(t) ϕ(x,t) atol = 0.01;
end

A3 = UpwindDifference{Float64}(1,3,Δx*ones(length(x)+1),length(x),-1,offside=1);
function KdV(du, u, p, t)
bc = GeneralBC([0,1,-6*ϕ(-10,t),0,-1],[0,1,-6*ϕ(10,t),0,-1],Δx,3)
Expand All @@ -66,6 +67,29 @@ using DiffEqOperators, OrdinaryDiffEq, LinearAlgebra
for t in 0:0.5:5
@test soln(t) ϕ(x,t) atol = 0.01;
end

# Using Biased Upwinds with 2 offside points
A4 = UpwindDifference{Float64}(1,4,Δx,length(x),-1,offside=2);
function KdV(du, u, p, t)
bc = GeneralBC([0,1,-6*ϕ(-10,t),0,-1],[0,1,-6*ϕ(10,t),0,-1],Δx,3)
mul!(du,A4,bc*u)
end
single_solition = ODEProblem(KdV, u0, (0.,5.));
soln = solve(single_solition,Tsit5(),abstol=1e-6,reltol=1e-6);
for t in 0:0.5:5
@test soln(t) ϕ(x,t) atol = 0.01;
end

A5 = UpwindDifference{Float64}(1,4,Δx,length(x),1,offside=2);
function KdV(du, u, p, t)
bc = GeneralBC([0,1,-6*ϕ(-10,t),0,-1],[0,1,-6*ϕ(10,t),0,-1],Δx,3)
mul!(du,-1*A5,bc*u)
end
single_solition = ODEProblem(KdV, u0, (0.,5.));
soln = solve(single_solition,Tsit5(),abstol=1e-6,reltol=1e-6);
for t in 0:0.5:5
@test soln(t) ϕ(x,t) atol = 0.01;
end
end

# Conduct interesting experiments by referring to
Expand Down
42 changes: 37 additions & 5 deletions test/heat_eqn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ end
dx = 2π/(N-1)
x = collect(-pi : dx : pi)
u0 = @. -(x - 0.5)^2 + 1/12
B = CenteredDifference(1,2,dx,N)
B = CenteredDifference(1,2,dx,N-2)
deriv_start, deriv_end = (B*u0)[1], (B*u0)[end]

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

# UpwindDifference with equal no. of primay wind and offside points should behave like a CenteredDifference
A2 = UpwindDifference(2,1,dx,N,1,offside=1)
B2 = UpwindDifference(1,2,dx,N-2,1,offside=1)
deriv_start, deriv_end = (B2*u0)[1], (B2*u0)[end]
bc = NeumannBC((deriv_start,deriv_end),dx,1)

step(u,p,t) = A2*bc*u
heat_eqn = ODEProblem(step, u0, (0.,10.))
soln = solve(heat_eqn,Tsit5(),dense=false,tstops=0:0.01:10)

for t in 0:0.1:10
@test sum(first_order_coeffs_start .* soln(t)[1:4]) deriv_start atol=1e-1
@test sum(first_order_coeffs_end .* soln(t)[end-3:end]) deriv_end atol=1e-1
end
# Testing for 2 offside points against Standard Vector input
B3 = UpwindDifference(1,4,dx,N-2,-1,offside=2)
deriv_start, deriv_end = (-1*B3*u0)[1], (-1*B3*u0)[end]
bc = NeumannBC((deriv_start,deriv_end),dx,1)

step(u,p,t) = A2*bc*u
heat_eqn = ODEProblem(step, u0, (0.,10.))
soln = solve(heat_eqn,Tsit5(),dense=false,tstops=0:0.01:10)
Expand All @@ -68,7 +85,7 @@ end
dx = 2π/(N-1)
x = collect(-pi : dx : pi)
u0 = @. -(x - 0.5)^2 + 1/12
B = CenteredDifference(1,2,dx,N);
B = CenteredDifference(1,2,dx,N-2);
deriv_start, deriv_end = (B*u0)[1], (B*u0)[end]
params = [1.0,0.5]

Expand All @@ -92,13 +109,28 @@ end
end

# UpwindDifference with equal no. of primay wind and offside points should behave like a CenteredDifference
A2 = UpwindDifference(2,1,dx*ones(513),N,1,offside=1);
B2 = UpwindDifference(1,2,dx,N,1,offside=1)
A2 = UpwindDifference(2,1,dx*ones(N+1),N,1,offside=1)
B2 = UpwindDifference(1,2,dx*ones(N-1),N-2,1,offside=1)
deriv_start, deriv_end = (B2*u0)[1], (B2*u0)[end]
left_RBC = params[1]*u0[1] - params[2]*deriv_start
right_RBC = params[1]*u0[end] + params[2]*deriv_end
bc = RobinBC((params[1],-params[2],left_RBC), (params[1],params[2],right_RBC),dx,1);


step(u,p,t) = A2*bc*u
heat_eqn = ODEProblem(step, u0, (0.,10.));
soln = solve(heat_eqn,Tsit5(),dense=false,tstops=0:0.01:10);

for t in 0.2:0.1:9.8
@test params[1]*soln(t)[1] - params[2]*sum(first_order_coeffs_start .* soln(t)[1:4]) left_RBC atol=1e-1
@test params[1]*soln(t)[end] + params[2]*sum(first_order_coeffs_end .* soln(t)[end-3:end]) right_RBC atol=1e-1
end
# Testing for 2 offside points against Standard Vector input
B3 = UpwindDifference(1,4,dx*ones(N-1),N-2,-1,offside=2)
deriv_start, deriv_end = (-1*B3*u0)[1], (-1*B3*u0)[end]
left_RBC = params[1]*u0[1] - params[2]*deriv_start
right_RBC = params[1]*u0[end] + params[2]*deriv_end
bc = RobinBC((params[1],-params[2],left_RBC), (params[1],params[2],right_RBC),dx,1);

step(u,p,t) = A2*bc*u
heat_eqn = ODEProblem(step, u0, (0.,10.));
soln = solve(heat_eqn,Tsit5(),dense=false,tstops=0:0.01:10);
Expand Down

0 comments on commit e777fba

Please sign in to comment.