From d6cad016076665b34228c93a1dac8c9a44bc4a96 Mon Sep 17 00:00:00 2001 From: Hendrik Ranocha Date: Wed, 24 Aug 2022 06:19:25 +0200 Subject: [PATCH] more Rosenbrock tests (#74) * more ROW tests * format * set version to 0.1.32 * try again to ref to stuff defined in RootedTrees See https://stackoverflow.com/questions/70137119/how-to-include-the-docstring-for-a-function-from-another-package-in-my-julia-doc * using LinearAlgebra: I * Revert "try again to ref to stuff defined in RootedTrees" This reverts commit 111df42540d888989caa4fc2f5d13ca2f92a568e. --- Project.toml | 2 +- test/Project.toml | 1 + test/runtests.jl | 96 ++++++++++++++++++++++++++++++++++++----------- 3 files changed, 77 insertions(+), 22 deletions(-) diff --git a/Project.toml b/Project.toml index 444df5e6..1596ac50 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "BSeries" uuid = "ebb8d67c-85b4-416c-b05f-5f409e808f32" authors = ["Hendrik Ranocha and contributors"] -version = "0.1.31" +version = "0.1.32" [deps] Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316" diff --git a/test/Project.toml b/test/Project.toml index 5cd7ce75..52a858bb 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,5 +1,6 @@ [deps] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" SymEngine = "123dc426-2d89-5057-bbad-38513e3affd8" SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6" diff --git a/test/runtests.jl b/test/runtests.jl index b83ae7ad..14201347 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,6 +3,7 @@ using BSeries using BSeries.Latexify: latexify +using LinearAlgebra: I using StaticArrays: @SArray, @SMatrix, @SVector using SymEngine: SymEngine @@ -1433,29 +1434,82 @@ using Aqua: Aqua end # @testset "additive Runge-Kutta methods interface" @testset "Rosenbrock methods interface" begin - # Kaps, Rentrop (1979) - # Generalized Runge-Kutta methods of order four with stepsize control - # for stiff ordinary differential equations - # https://doi.org/10.1007/BF01396495 - γ = [0.395 0 0 0; - -0.767672395484 0.395 0 0; - -0.851675323742 0.522967289188 0.395 0; - 0.288463109545 0.880214273381e-1 -0.337389840627 0.395] - A = [0 0 0 0; - 0.438 0 0 0; - 0.796920457938 0.730795420615e-1 0 0; - 0.796920457938 0.730795420615e-1 0 0] - b = [0.199293275701, 0.482645235674, 0.680614886256e-1, 0.25] - ros = @inferred RosenbrockMethod(γ, A, b) + @testset "Kaps, Rentrop (1979): GRK4A" begin + # Kaps, Rentrop (1979) + # Generalized Runge-Kutta methods of order four with stepsize control + # for stiff ordinary differential equations + # https://doi.org/10.1007/BF01396495 + Γ = [0.395 0 0 0; + -0.767672395484 0.395 0 0; + -0.851675323742 0.522967289188 0.395 0; + 0.288463109545 0.880214273381e-1 -0.337389840627 0.395] + A = [0 0 0 0; + 0.438 0 0 0; + 0.796920457938 0.730795420615e-1 0 0; + 0.796920457938 0.730795420615e-1 0 0] + b = [0.199293275701, 0.482645235674, 0.680614886256e-1, 0.25] + ros = @inferred RosenbrockMethod(Γ, A, b) - # fourth-order accurate - series_integrator = @inferred bseries(ros, 5) - @test @inferred(order_of_accuracy(series_integrator)) == 4 + # fourth-order accurate + series_integrator = @inferred bseries(ros, 5) + @test @inferred(order_of_accuracy(series_integrator)) == 4 - # not fifth-order accurate - series_exact = @inferred ExactSolution(series_integrator) - @test mapreduce(isapprox, &, values(series_integrator), values(series_exact)) == - false + # not fifth-order accurate + series_exact = @inferred ExactSolution(series_integrator) + @test mapreduce(isapprox, &, values(series_integrator), values(series_exact)) == + false + end + + @testset "van Veldhuizen (1984)" begin + # van Veldhuizen (1984) + # D-stability and Kaps-Rentrop methods + # https://doi.org/10.1007/BF02243574 + # Γ = [1//2 0 0 0; + # -4 1//2 0 0; + # -4 -1//2 1//2 0; + # 1//4 -1//4 1 1//2] + # A = [0 0 0 0; + # 1 0 0 0; + # 7//8 1//8 0 0; + # 7//8 1//8 0 0] + # b = [4//6, 2//6, -4//6, 4//6] + # ros = @inferred RosenbrockMethod(Γ, A, b) + # However, this does not work directly. Thus, we reverse-engineer + # the coefficients as follows. + # + # Hairer, Wanner + # Solving ODEs II + # Implementation of Rosenbrock-type methods in Section IV.7. + # The coefficients are transformed as + # - C = I / γ - inv(Γ) + # - A = A / Γ + # - b' = b' / Γ + # to yield the coefficients used in + # http://www.unige.ch/~hairer/prog/stiff/Oldies/ros4.f + C = [0 0 0 0; + -8 0 0 0; + -8 -1 0 0; + 1//2 -1//2 2 0] + γ = 1 // 2 + Γ = inv(I / γ - C) + A = [0 0 0 0; + 2 0 0 0; + 7//4 1//4 0 0; + 7//4 1//4 0 0] + A = A * Γ + b = [4 // 3, 2 // 3, -4 // 3, 4 // 3] + b = (b' * Γ)' + ros = @inferred RosenbrockMethod(Γ, A, b) + + # fourth-order accurate + series_integrator = @inferred bseries(ros, 5) + @test @inferred(order_of_accuracy(series_integrator)) == 4 + + # not fifth-order accurate + series_exact = @inferred ExactSolution(series_integrator) + @test mapreduce(isapprox, &, values(series_integrator), values(series_exact)) == + false + end end # @testset "Rosenbrock methods interface" @testset "multirate infinitesimal split methods interface" begin