Skip to content

Commit

Permalink
more Rosenbrock tests (#74)
Browse files Browse the repository at this point in the history
* 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 111df42.
  • Loading branch information
ranocha committed Aug 24, 2022
1 parent b6134aa commit d6cad01
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BSeries"
uuid = "ebb8d67c-85b4-416c-b05f-5f409e808f32"
authors = ["Hendrik Ranocha <[email protected]> and contributors"]
version = "0.1.31"
version = "0.1.32"

[deps]
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
96 changes: 75 additions & 21 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using BSeries

using BSeries.Latexify: latexify

using LinearAlgebra: I
using StaticArrays: @SArray, @SMatrix, @SVector

using SymEngine: SymEngine
Expand Down Expand Up @@ -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
Expand Down

2 comments on commit d6cad01

@ranocha
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/66921

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.32 -m "<description of version>" d6cad016076665b34228c93a1dac8c9a44bc4a96
git push origin v0.1.32

Please sign in to comment.