-
-
Save MSeeker1340/bc8afa8a65685930cbd86c91b8ea566a to your computer and use it in GitHub Desktop.
Testing lazy W operator for in-place ImplictEuler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using LinearAlgebra, Random, OrdinaryDiffEq, DiffEqOperators, Test | |
@testset "In-place ImplicitEuler" begin | |
A = [-1.0 0.0; 0.0 -0.5]; u0 = [1.0, 1.0]; tspan = (0.0,1.0) | |
srand(0); mm = [2.0 0.0; 0.0 1.0]; mmA = [-0.5 0.0; 0.0 -0.5] | |
fun = ODEFunction((du,u,p,t) -> mul!(du,A,u); | |
analytic=(u0,p,t) -> exp(mmA*t)*u0) | |
prob = ODEProblem(fun,u0,tspan; mass_matrix=mm) | |
sol = solve(prob, ImplicitEuler(); adaptive=false, dt=0.01) | |
err = norm(sol(1.0) - fun.analytic(u0,nothing,1.0)) | |
println("Dense W error = $err") | |
fun = ODEFunction((du,u,p,t) -> mul!(du,A,u); | |
jac_prototype=DiffEqArrayOperator(A), | |
analytic=(u0,p,t) -> exp(mmA*t)*u0) | |
prob = ODEProblem(fun,u0,tspan; mass_matrix=mm) | |
sol = solve(prob, ImplicitEuler(); adaptive=false, dt=0.01) | |
err = norm(sol(1.0) - fun.analytic(u0,nothing,1.0)) | |
println("Lazy W error = $err") | |
# Check that WOperator handling is correct | |
integrator = init(prob, ImplicitEuler(); adaptive=false, dt=0.01) | |
# Check cache initialization | |
@test isa(integrator.cache.J, DiffEqArrayOperator) | |
@test isa(integrator.cache.W, OrdinaryDiffEq.WOperator) | |
step!(integrator) | |
# Check that W is indeed updated | |
@test integrator.cache.W.mass_matrix == mm | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment