Skip to content

Commit

Permalink
modifying tests to test against analytic solution and removing print …
Browse files Browse the repository at this point in the history
…statements
  • Loading branch information
tamaratambyah committed Nov 15, 2023
1 parent 1a2b41f commit 99b40e1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
3 changes: 3 additions & 0 deletions test/ODEsTests/ODEsTests/ODEOperatorMocks.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Toy linear ODE with 2 DOFs
# u_1_t - a * u_1 = 0
# u_2_t - b * u_1 - c * u_2 = 0
# For a = 1, b = 0, c = 1, the analytical solution is:
# u_1 = u0*exp(t)
# u_2 = u0*exp(t)

# Toy 2nd order ODE with 2 DOFs
# u_1_tt + b * u_1_t - a * u_1 = 0
Expand Down
25 changes: 13 additions & 12 deletions test/ODEsTests/ODEsTests/ODESolversTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,36 +101,37 @@ _J = jacobian(sop,x)
ls = LUSolver()

# BackwardEuler tests
dt = 0.01
odesol = BackwardEuler(ls,dt)
uf = copy(u0)
uf.=1.0
cache = nothing
uf, tf, cache = solve_step!(uf,odesol,op,u0,t0,cache)
@test tf==t0+dt
@test all(uf.1+11/9)
@test all( (uf.- u0*exp(dt)) .< 1e-3 )
@test test_ode_solver(odesol,op,u0,t0,tf)

# Affine and nonlinear solvers
op = ODEOperatorMock{Float64,Nonlinear}(1.0,0.0,1.0,1)
cache = nothing
uf, tf, cache = solve_step!(uf,odesol,op,u0,t0,cache)
@test tf==t0+dt
@test all(uf.1+11/9)
@test all( (uf.- u0*exp(dt)) .< 1e-3 )
@test test_ode_solver(odesol,op,u0,t0,tf)

op = ODEOperatorMock{Float64,Affine}(1.0,0.0,1.0,1)
cache = nothing
uf, tf, cache = solve_step!(uf,odesol,op,u0,t0,cache)
@test tf==t0+dt
@test all(uf.1+11/9)
@test all( (uf.- u0*exp(dt)) .< 1e-3 )
@test test_ode_solver(odesol,op,u0,t0,tf)

# ThetaMethod tests
odesolθ = ThetaMethod(ls,dt,0.5)
ufθ = copy(u0)
ufθ.=1.0
ufθ, tf, cache = solve_step!(ufθ,odesolθ,op,u0,t0,nothing)
@test all(ufθ.≈(dt/(1-0.5dt) + 1)*u0)
@test all( (uf.- u0*exp(dt)) .< 1e-3 )
@test test_ode_solver(odesol,op,u0,t0,tf)

# RK tests
Expand All @@ -139,63 +140,63 @@ odesol = RungeKutta(ls,ls,dt,:BE_1_0_1)
cache = nothing
uf, tf, cache = solve_step!(uf,odesol,op,u0,t0,cache)
@test tf==t0+dt
@test all(uf.1+11/9)
@test all( (uf.- u0*exp(dt)) .< 1e-3 )
@test test_ode_solver(odesol,op,u0,t0,tf)

# RK: CN 2nd order
odesol = RungeKutta(ls,ls,dt,:CN_2_0_2)
cache = nothing
uf, tf, cache = solve_step!(uf,odesol,op,u0,t0,cache)
@test tf==t0+dt
@test all(uf.ufθ)
@test all( (uf.- u0*exp(dt)) .< 1e-3 )
@test test_ode_solver(odesol,op,u0,t0,tf)

# RK: SDIRK 2nd order
odesol = RungeKutta(ls,ls,dt,:SDIRK_2_0_2)
cache = nothing
uf, tf, cache = solve_step!(uf,odesol,op,u0,t0,cache)
@test tf==t0+dt
@test all(uf.u0*1.1051939513477975)
@test all( (uf.- u0*exp(dt)) .< 1e-3 )
@test test_ode_solver(odesol,op,u0,t0,tf)

# RK: TRBDF (2nd order with some 0 on the diagonal)
odesol = RungeKutta(ls,ls,dt,:TRBDF2_3_2_3)
cache = nothing
uf, tf, cache = solve_step!(uf,odesol,op,u0,t0,cache)
@test tf==t0+dt
@test all(uf.u0*1.105215241)
@test all( (uf.- u0*exp(dt)) .< 1e-3 )
@test test_ode_solver(odesol,op,u0,t0,tf)

# IMEX RK tests (explicit part = 0)
odesol = IMEXRungeKutta(ls,ls,dt,:IMEX_FE_BE_2_0_1)
cache = nothing
uf, tf, cache = solve_step!(uf,odesol,op,u0,t0,cache)
@test tf==t0+dt
@test all(uf.1+11/9)
@test all( (uf.- u0*exp(dt)) .< 1e-3 )
@test test_ode_solver(odesol,op,u0,t0,tf)

# EX-RK: FE equivalent
odesol = EXRungeKutta(ls,dt,:EX_FE_1_0_1)
cache = nothing
uf, tf, cache = solve_step!(uf,odesol,op,u0,t0,cache)
@test tf==t0+dt
@test all( (uf.- u0*1.1) .< 1e-3 )
@test all( (uf.- u0*exp(dt)) .< 1e-3 )
@test test_ode_solver(odesol,op,u0,t0,tf)

# EX-RK: SSP equivalent
odesol = EXRungeKutta(ls,dt,:EX_SSP_3_0_3)
cache = nothing
uf, tf, cache = solve_step!(uf,odesol,op,u0,t0,cache)
@test tf==t0+dt
@test all( (uf.- u0*1.105166) .< 1e-3 )
@test all( (uf.- u0*exp(dt)) .< 1e-3 )
@test test_ode_solver(odesol,op,u0,t0,tf)

# Forward Euler test
odesol = ForwardEuler(ls,dt)
cache = nothing
uf, tf, cache = solve_step!(uf,odesol,op,u0,t0,cache)
@test tf==t0+dt
@test all( (uf.- u0*1.1) .< 1e-3 )
@test all( (uf.- u0*exp(dt)) .< 1e-3 )
@test test_ode_solver(odesol,op,u0,t0,tf)

# Newmark test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ uh0 = interpolate_everywhere(u(0.0),U0)

ls = LUSolver()
using Gridap.Algebra: NewtonRaphsonSolver
nls = NLSolver(ls;show_trace=true,method=:newton) #linesearch=BackTracking())
nls = NLSolver(ls;show_trace=false,method=:newton) #linesearch=BackTracking())
ode_solver = ThetaMethod(ls,dt,θ)

sol_t = solve(ode_solver,op,uh0,t0,tF)
Expand Down
2 changes: 1 addition & 1 deletion test/ODEsTests/TransientFEsTests/HeatEquationTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ uh0 = interpolate_everywhere(u(0.0),U0)

ls = LUSolver()
using Gridap.Algebra: NewtonRaphsonSolver
nls = NLSolver(ls;show_trace=true,method=:newton) #linesearch=BackTracking())
nls = NLSolver(ls;show_trace=false,method=:newton) #linesearch=BackTracking())
ode_solver = ThetaMethod(ls,dt,θ)

sol_t = solve(ode_solver,op,uh0,t0,tF)
Expand Down
2 changes: 1 addition & 1 deletion test/ODEsTests/TransientFEsTests/TransientFETests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ ls = LUSolver()
tol = 1.0
maxiters = 20
using Gridap.Algebra: NewtonRaphsonSolver
nls = NLSolver(ls;show_trace=true,method=:newton) #linesearch=BackTracking())
nls = NLSolver(ls;show_trace=false,method=:newton) #linesearch=BackTracking())
ode_solver = ThetaMethod(nls,dt,1.0)
@test test_transient_fe_solver(ode_solver,op,uh0,t0,tF)

Expand Down

0 comments on commit 99b40e1

Please sign in to comment.