Skip to content

Commit

Permalink
Merge pull request #2165 from cwittens/ROS2
Browse files Browse the repository at this point in the history
added ROS2 method and added ROS2, ROS23 and ROS34PW methods to iipvsoop_test.jl
  • Loading branch information
ChrisRackauckas authored Apr 21, 2024
2 parents c04c54b + ab4872f commit bbb3ee0
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/OrdinaryDiffEq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ export Rosenbrock23, Rosenbrock32, RosShamp4, Veldd4, Velds4, GRK4T, GRK4A,
Rodas5, Rodas5P,
RosenbrockW6S4OS, ROS34PW1a, ROS34PW1b, ROS34PW2, ROS34PW3, ROS34PRw, ROS3PRL,
ROS3PRL2,
ROS2PR, ROS2S, ROS3, ROS3PR, Scholz4_7
ROS2, ROS2PR, ROS2S, ROS3, ROS3PR, Scholz4_7

export LawsonEuler, NorsettEuler, ETD1, ETDRK2, ETDRK3, ETDRK4, HochOst4, Exp4, EPIRK4s3A,
EPIRK4s3B,
Expand Down
1 change: 1 addition & 0 deletions src/alg_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ alg_order(alg::Feagin12) = 12
alg_order(alg::Feagin14) = 14
alg_order(alg::PFRK87) = 8

alg_order(alg::ROS2) = 2
alg_order(alg::ROS2PR) = 2
alg_order(alg::ROS2S) = 2
alg_order(alg::ROS3) = 3
Expand Down
6 changes: 6 additions & 0 deletions src/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2898,6 +2898,11 @@ end
- Shampine L.F. and Reichelt M., (1997) The MATLAB ODE Suite, SIAM Journal of
Scientific Computing, 18 (1), pp. 1-22.
#### ROS2
- J. G. Verwer et al. (1999): A second-order Rosenbrock method applied to photochemical dispersion problems
https://doi.org/10.1137/S1064827597326651
#### ROS3P
- Lang, J. & Verwer, ROS3P—An Accurate Third-Order Rosenbrock Solver Designed for
Expand Down Expand Up @@ -2967,6 +2972,7 @@ University of Geneva, Switzerland.
for Alg in [
:Rosenbrock23,
:Rosenbrock32,
:ROS2,
:ROS2PR,
:ROS2S,
:ROS3,
Expand Down
6 changes: 6 additions & 0 deletions src/caches/rosenbrock_caches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@ end

################################################################################

### ROS2 methods

@ROS2(:cache)

################################################################################

### ROS23 methods

@ROS23(:cache)
Expand Down
93 changes: 92 additions & 1 deletion src/generic_rosenbrock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ macro Rosenbrock4(part)
end
end

#ROS23 and ROS34PW methods (Rang and Angermann, 2005)
#ROS2, ROS23 and ROS34PW methods (Rang and Angermann, 2005)

"""
Ros34dummyTableau()
Expand Down Expand Up @@ -849,6 +849,25 @@ function Ros23dummyTableau()
RosenbrockAdaptiveTableau(a,C,b,btilde,gamma,d,c)
end

"""
Ros2dummyTableau()
Generate a dummy tableau for ROS2 methods. This type of methods has 2 steps.
"""
function Ros2dummyTableau()
a=[false false;
true false]
C=[false false;
true false]
b=[true,true]
btilde=[true,true]
gamma=true
c=[false,true]
d=[true,true]
RosenbrockAdaptiveTableau(a,C,b,btilde,gamma,d,c)
end


"""
_transformtab(Alpha,Gamma,B,Bhat)
Expand All @@ -872,6 +891,78 @@ end



# 2 step ROS Methods
"""
ROS2Tableau()
2nd order stiffly accurate Rosenbrock-Wanner method with 2 internal stages with (Rinf=0).
The embedded method is taken from Kinetic PreProcessor (KPP).
J. G. Verwer et al. (1999): A second-order Rosenbrock method applied to photochemical dispersion problems
https://doi.org/10.1137/S1064827597326651
"""
function ROS2Tableau() # 2nd order
gamma=1.7071067811865475 # 1+1/sqrt(2)
Alpha=[0 0;
1. 0]
Gamma=[gamma 0;
-3.414213562373095 gamma]
B=[0.5, 0.5]
Bhat=[1, 0]
a,C,b,btilde,d,c=_transformtab(Alpha,Gamma,B,Bhat)
RosenbrockAdaptiveTableau(a,C,b,btilde,gamma,d,c)
end

@doc """
ROS2()
2nd order stiffly accurate Rosenbrock-Wanner method with 2 internal stages with (Rinf=0).
The embedded method is taken from Kinetic PreProcessor (KPP).
J. G. Verwer et al. (1999): A second-order Rosenbrock method applied to photochemical dispersion problems
More Information at https://doi.org/10.1137/S1064827597326651
""" ROS2



"""
@ROS2(part)
Generate code for the 2 step ROS methods: ROS2
`part` should be one of `:tableau`, `:cache`, `:init`, `:performstep`.
`@ROS2(:tableau)` should be placed in `tableaus/rosenbrock_tableaus.jl`.
`@ROS2(:cache)` should be placed in `caches/rosenbrock_caches.jl`.
`@ROS2(:init)` and `@ROS2(:performstep)` should be placed in
`perform_step/rosenbrock_perform_step.jl`.
"""
macro ROS2(part)
tabmask=Ros2dummyTableau()
cachename=:ROS2Cache
constcachename=:ROS2ConstantCache
ROS2tabname=:ROS2Tableau
n_normalstep=length(tabmask.b)-1
if part.value==:tableau
tabstructexpr=gen_tableau_struct(tabmask,:Ros2Tableau)
tabexprs=Array{Expr,1}([tabstructexpr])
push!(tabexprs,gen_tableau(ROS2Tableau(),tabstructexpr,ROS2tabname))
return esc(quote $(tabexprs...) end)
elseif part.value==:cache
constcacheexpr,cacheexpr=gen_cache_struct(tabmask,cachename,constcachename)
cacheexprs=Array{Expr,1}([constcacheexpr,cacheexpr])
push!(cacheexprs,gen_algcache(cacheexpr,constcachename,:ROS2,ROS2tabname))
return esc(quote $(cacheexprs...) end)
elseif part.value==:init
return esc(gen_initialize(cachename,constcachename))
elseif part.value==:performstep
performstepexprs=Array{Expr,1}()
push!(performstepexprs,gen_constant_perform_step(tabmask,constcachename,n_normalstep))
push!(performstepexprs,gen_perform_step(tabmask,cachename,n_normalstep))
return esc(quote $(performstepexprs...) end)
else
throw(ArgumentError("Unknown parameter!"))
nothing
end
end



# 3 step ROS Methods
"""
ROS2PRTableau()
Expand Down
7 changes: 7 additions & 0 deletions src/perform_step/rosenbrock_perform_step.jl
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,13 @@ end

################################################################################

#### ROS2 type method

@ROS2(:init)
@ROS2(:performstep)

################################################################################

#### ROS23 type method

@ROS23(:init)
Expand Down
2 changes: 2 additions & 0 deletions src/tableaus/rosenbrock_tableaus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ function Rodas3PTableau(T, T2)
h21, h22, h23, h24, h25, h31, h32, h33, h34, h35, h2_21, h2_22, h2_23, h2_24, h2_25)
end

@ROS2(:tableau)

@ROS23(:tableau)

@ROS34PW(:tableau)
Expand Down
17 changes: 17 additions & 0 deletions test/algconvergence/ode_rosenbrock_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@ import LinearSolve
sol = solve(prob, Rodas3())
@test length(sol) < 20

### ROS2
prob = prob_ode_linear

sim = test_convergence(dts, prob, ROS2())
@test sim.𝒪est[:final]2 atol=testTol

sol = solve(prob, ROS2())
@test length(sol) < 61

prob = prob_ode_2Dlinear

sim = test_convergence(dts, prob, ROS2())
@test sim.𝒪est[:final]2 atol=testTol

sol = solve(prob, ROS2PR())
@test length(sol) < 60

### ROS2PR
prob = prob_ode_linear

Expand Down
1 change: 1 addition & 0 deletions test/interface/mass_matrix_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ dependent_M2 = MatrixOperator(ones(3, 3), update_func = update_func2,
@test _norm_dsol(Rosenbrock32(), prob, prob2)0 atol=1e-11
@test _norm_dsol(ROS3P(), prob, prob2)0 atol=1e-11
@test _norm_dsol(Rodas3(), prob, prob2)0 atol=1e-11
@test _norm_dsol(ROS2(), prob, prob2)0 atol=1e-11
@test _norm_dsol(ROS2PR(), prob, prob2)0 atol=1e-11
@test _norm_dsol(ROS2S(), prob, prob2)0 atol=1e-11
@test _norm_dsol(ROS3(), prob, prob2)0 atol=1e-11
Expand Down
5 changes: 4 additions & 1 deletion test/regression/iipvsoop_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ end

working_rosenbrock_algs = [Rosenbrock23(), ROS3P(), Rodas3(),
RosShamp4(), Veldd4(), Velds4(), GRK4T(), GRK4A(),
Ros4LStab(), Rodas4(), Rodas42(), Rodas4P(), Rodas5()]
Ros4LStab(), Rodas4(), Rodas42(), Rodas4P(), Rodas5(),
ROS2(), ROS2PR(), ROS2S(), ROS3(), ROS3PR(), Scholz4_7(),
ROS34PW1a(), ROS34PW1b(), ROS34PW2(), ROS34PW3(),
ROS34PRw(), ROS3PRL(), ROS3PRL2()]

rosenbrock_algs = [Rosenbrock32()
]
Expand Down

0 comments on commit bbb3ee0

Please sign in to comment.