-
Notifications
You must be signed in to change notification settings - Fork 10
Implementing CSRK code in BSeries.jl #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7853dcb
aaf5940
afe7373
e4d79cc
823684d
0df736b
09d4629
335265f
8c4e0b1
7ad5325
5d82c87
c0a724d
c45de1c
6616b9c
1227e1a
3691f69
68cecb0
5d30865
7387ffc
53fd493
d6a23d6
c0ba86f
b5813d2
691507f
02acff4
fd1a23e
0c29499
c8113e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2058,4 +2058,117 @@ using Aqua: Aqua | |
| Aqua.test_project_toml_formatting(BSeries) | ||
| end | ||
| end | ||
|
|
||
| @testset "Continuous Stage Runge-Kutta Method" begin | ||
| @testset "(Inverse) 4x4-Hilbert Matrix" begin | ||
| # References | ||
| # - Yuto Miyatake and John C. Butcher. | ||
| # "A characterization of energy-preserving methods and the construction of | ||
| # parallel integrators for Hamiltonian systems." | ||
| # SIAM Journal on Numerical Analysis 54, no. 3 (2016): | ||
| # [DOI: 10.1137/15M1020861](https://doi.org/10.1137/15M1020861) | ||
|
|
||
| # This is the matrix obtained by inverting the 4x4-Hilbert matrix | ||
| M = [-6//5 72//5 -36//1 24//1; | ||
| 72//5 -144//5 -48//1 72//1; | ||
| -36//1 -48//1 720//1 -720//1; | ||
| 24//1 72//1 -720//1 720//1] | ||
| csrk = ContinuousStageRungeKuttaMethod(M) | ||
| # Generate the bseries up to order 4 | ||
| order = 4 | ||
| series = bseries(csrk, order) | ||
| expected_coefficients = [1//1 ,1//1, 1//2, 1//6, 1//3, 1//24, 1//12, 1//8, 1//4] | ||
| @test collect(values(series)) == expected_coefficients | ||
| end | ||
|
|
||
| @testset "Floating-points coefficients" begin | ||
| # Define variables | ||
| # Values from current research for CSRK Methods. | ||
|
|
||
| # References | ||
| # - Yuto Miyatake and John C. Butcher. | ||
| # "A characterization of energy-preserving methods and the construction of | ||
| # parallel integrators for Hamiltonian systems." | ||
| # SIAM Journal on Numerical Analysis 54, no. 3 (2016): | ||
| # [DOI: 10.1137/15M1020861](https://doi.org/10.1137/15M1020861) | ||
| a = -0.37069987 | ||
| b = 0.74139974 | ||
| c = 2.51720052 | ||
|
|
||
| # Create the 4x4 matrix | ||
| Minv = [a 1//2 b 1//6; | ||
| 1//2 1//4 1//6 1//8; | ||
| b 1//6 c 1//10; | ||
| 1//6 1//8 1//10 1//12] | ||
|
|
||
| # Calculate inverse of the matrix | ||
| M = inv(Minv) | ||
| csrk = ContinuousStageRungeKuttaMethod(M) | ||
| # Generate the bseries up to order 4 | ||
| order = 4 | ||
| series = bseries(csrk, order) | ||
| expected_coefficients = [1.0 ,1.0, 0.5000000000000002, 0.16666666666666666, 0.3333333333333336, 0.04166666666666661, 0.0833333333333332, 0.12500000000000003, 0.2500000000000003] | ||
| @test collect(values(series)) == expected_coefficients | ||
|
Comment on lines
+2107
to
+2111
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment about the order, energy-preserving property etc. as above
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you test it? |
||
| end | ||
| @testset "Symbolic coefficients using SymPy.jl" begin | ||
| # Define variables | ||
| x = SymPy.symbols("x") | ||
| y = SymPy.symbols("y") | ||
| # Create symbolic matrix | ||
| M = [x y; | ||
| y x] | ||
| csrk = ContinuousStageRungeKuttaMethod(M) | ||
| # Generate the bseries up to order 3 | ||
| order = 3 | ||
| series = bseries(csrk, order) | ||
| expected_coefficients = [1,1, 25*x^2/32 + 5*x*y/4 + y^2/2, 1105*x^3/2304 + 671*x^2*y/576 + 545*x*y^2/576 + 37*y^3/144, 125*x^3/192 + 25*x^2*y/16 + 5*x*y^2/4 + y^3/3] | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you compute this by hand? How did you arrive at these coefficients?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I just copied from the output of the working code
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... So it is just a regression test - assuming that the current implementation is correct. Could you please also add real tests using examples with known behavior? IIRC, Miyatake & Butcher (2015) have some examples with free coefficients in their paper. You could express these free coefficients as symbolic variables and check whether the resulting B-series of the CSRK method
|
||
| @test collect(values(series)) == expected_coefficients | ||
| end | ||
| @testset "Symbolic coefficients using SymEngine.jl" begin | ||
| # Define variables | ||
| x,y = SymEngine.symbols("x y") | ||
| # Create symbolic matrix | ||
| M = [x y; | ||
| y x] | ||
| csrk = ContinuousStageRungeKuttaMethod(M) | ||
| # Generate the bseries up to order 3 | ||
| order = 3 | ||
| series = bseries(csrk, order) | ||
| expected_coefficients = [1,1, 25*x^2/32 + 5*x*y/4 + y^2/2, 1105*x^3/2304 + 671*x^2*y/576 + 545*x*y^2/576 + 37*y^3/144, 125*x^3/192 + 25*x^2*y/16 + 5*x*y^2/4 + y^3/3] | ||
| @test collect(values(series)) == expected_coefficients | ||
| end | ||
| @testset "Symbolic coefficients using Symbolics.jl" begin | ||
| # Define variables | ||
| @Symbolics.variables x y | ||
| # Create symbolic matrix | ||
| M = [x y; | ||
| y x] | ||
| csrk = ContinuousStageRungeKuttaMethod(M) | ||
| # Generate the bseries up to order 3 | ||
| order = 3 | ||
| series = bseries(csrk, order) | ||
| expected_coefficients = [1,1, 25*x^2/32 + 5*x*y/4 + y^2/2, 1105*x^3/2304 + 671*x^2*y/576 + 545*x*y^2/576 + 37*y^3/144, 125*x^3/192 + 25*x^2*y/16 + 5*x*y^2/4 + y^3/3] | ||
| @test collect(values(series)) == expected_coefficients | ||
| end | ||
| @testset "Energy-Preserving CSRK" begin | ||
| # References | ||
| # - Yuto Miyatake and John C. Butcher. | ||
| # "A characterization of energy-preserving methods and the construction of | ||
| # parallel integrators for Hamiltonian systems." | ||
| # SIAM Journal on Numerical Analysis 54, no. 3 (2016): | ||
| # [DOI: 10.1137/15M1020861](https://doi.org/10.1137/15M1020861) | ||
|
|
||
| # This is the matrix obtained by inverting the 4x4-Hilbert matrix | ||
| M = [-6//5 72//5 -36//1 24//1; | ||
| 72//5 -144//5 -48//1 72//1; | ||
| -36//1 -48//1 720//1 -720//1; | ||
| 24//1 72//1 -720//1 720//1] | ||
| csrk = ContinuousStageRungeKuttaMethod(M) | ||
| # Generate the bseries up to order 5 | ||
| order = 5 | ||
| series = bseries(csrk, order) | ||
| #check if it is energy-preserving | ||
| @test is_energy_preserving(series) == true | ||
| end | ||
| end | ||
| end # @testset "BSeries" | ||
Uh oh!
There was an error while loading. Please reload this page.