Skip to content
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

Implementation of embedded scheme of order 3 #16

Closed
wants to merge 180 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
da330cc
make NLsolve a weapdep
warisa-r May 25, 2024
a6789b3
fmt
warisa-r May 25, 2024
bcd4091
add NEWS.md but TBD on the ref pull request
warisa-r May 25, 2024
fd3d4ca
add comments and adjustment on solve_a_unknown
warisa-r May 25, 2024
c280292
modular implementation with init, step!, and solve_step!
warisa-r May 25, 2024
3ddf5c4
fmt
warisa-r May 25, 2024
b9b4243
add test
warisa-r May 26, 2024
a727a87
adda body of p3 constructor test
warisa-r May 28, 2024
cb98a3f
changes according to test and correct variable names
warisa-r May 29, 2024
d84daed
only check the values of a_matrix from second row to end
warisa-r May 31, 2024
1332c28
adjust the the constructor of path coefficient and its test
warisa-r May 31, 2024
777f28c
Merge branch 'DanielDoehring:main' into PERK_p3_single_ext
warisa-r Jun 3, 2024
7bf717a
adjust the test and add a seed to the randomized initial guess for re…
warisa-r Jun 4, 2024
05853cf
Merge branch 'PERK_p3_single_ext' of https://github.com/warisa-r/Trix…
warisa-r Jun 4, 2024
43cf02d
add NLsolve as a dependency for testing
warisa-r Jun 4, 2024
9ed5e2b
Update ext/TrixiNLsolveExt.jl
warisa-r Jun 6, 2024
a739350
Update ext/TrixiNLsolveExt.jl
warisa-r Jun 6, 2024
cf71784
Update ext/TrixiNLsolveExt.jl
warisa-r Jun 6, 2024
01a4343
Update ext/TrixiNLsolveExt.jl
warisa-r Jun 6, 2024
0deb7bc
Update ext/TrixiNLsolveExt.jl
warisa-r Jun 6, 2024
0708bc4
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK3.jl
warisa-r Jun 6, 2024
0a5ad48
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK3.jl
warisa-r Jun 6, 2024
0a3ab55
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK3.jl
warisa-r Jun 6, 2024
8c978e2
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK3.jl
warisa-r Jun 6, 2024
45324a2
optimize the loop for step! by moving the condition outside
warisa-r Jun 10, 2024
ca5951a
fmt
warisa-r Jun 10, 2024
76a7a6b
more type generic
warisa-r Jun 10, 2024
03fad1b
change some names
warisa-r Jun 10, 2024
78ae8da
update test
warisa-r Jun 10, 2024
c5c455f
Correcting steps!
warisa-r Jun 10, 2024
1bfb576
Apply suggestions from code review
warisa-r Jun 10, 2024
86a4daa
Update examples/structured_1d_dgsem/elixir_burgers_perk3.jl
warisa-r Jun 10, 2024
786de99
Update examples/structured_1d_dgsem/elixir_burgers_perk3.jl
warisa-r Jun 10, 2024
a3d6df5
add docstring about dt_opt
warisa-r Jun 10, 2024
f84d171
Merge branch 'main' into PERK_p3_single_ext
DanielDoehring Jun 11, 2024
4e35589
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK3.jl
warisa-r Jun 11, 2024
a4b3df6
merge k_higher in the last stage to a bigger loop
warisa-r Jun 12, 2024
6a03a3a
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK3.jl
warisa-r Jun 12, 2024
b5f227a
change solve_step! to solve!
warisa-r Jun 14, 2024
d029c21
Correct the logic of step!
warisa-r Jun 17, 2024
ff5c590
deprecation
DanielDoehring Jun 18, 2024
df7ec64
Optimize K_S1 away
DanielDoehring Jun 18, 2024
b9977c0
fmt
DanielDoehring Jun 18, 2024
34d0eb5
remove dt_opt as an attribute of PERK3
warisa-r Jun 20, 2024
13ac6dc
change the objective function to match the number of equations
warisa-r Jun 24, 2024
516e95f
fmt
warisa-r Jun 24, 2024
fdba17d
minor comment fix
warisa-r Jun 24, 2024
b78f39a
delete some stuff left from random
warisa-r Jun 24, 2024
000f117
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK3.jl
warisa-r Jun 25, 2024
3289faf
minor adjustments
warisa-r Jun 25, 2024
d73c377
minor change to the comment
warisa-r Jun 25, 2024
b22476e
add proper comment and bring seed back
warisa-r Jun 25, 2024
2ec41fa
update test values
warisa-r Jun 25, 2024
03fb32f
fmt
warisa-r Jun 25, 2024
cda3c84
change the keyword according to the error in the test pipeline and ed…
warisa-r Jun 25, 2024
84f6a6d
remove unused import
warisa-r Jun 25, 2024
144bfa1
fix test values in misc
warisa-r Jun 25, 2024
6e53ad2
add max iteration
warisa-r Jun 26, 2024
a34d412
Update ext/TrixiNLsolveExt.jl
warisa-r Jun 26, 2024
a65cdb8
Apply suggestions from code review
DanielDoehring Jul 5, 2024
6d2fc6d
remove the allocating part of is_sol_valid
warisa-r Jul 5, 2024
cd22981
Merge branch 'PERK_p3_single_ext' of https://github.com/warisa-r/Trix…
warisa-r Jul 5, 2024
e95fe97
removing dt_opt and update test values
warisa-r Jul 5, 2024
c61187c
Update NEWS.md
warisa-r Jul 5, 2024
2fc3085
update cfl number for the simulation
warisa-r Jul 5, 2024
ac055ab
Merge branch 'PERK_p3_single_ext' of https://github.com/warisa-r/Trix…
warisa-r Jul 5, 2024
bd55f1d
Update examples/structured_1d_dgsem/elixir_burgers_perk3.jl
warisa-r Jul 5, 2024
8d08b87
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK3.jl
warisa-r Jul 5, 2024
c5c00bc
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK3.jl
warisa-r Jul 5, 2024
6fa8647
change from a_stages_stages.txt to a_stages.txt
warisa-r Jul 5, 2024
532f483
Merge branch 'PERK_p3_single_ext' of https://github.com/warisa-r/Trix…
warisa-r Jul 5, 2024
88c92e2
fixed step size should work with save solution now
warisa-r Jul 8, 2024
71f2841
Update examples/structured_1d_dgsem/elixir_burgers_perk3.jl
warisa-r Jul 9, 2024
739b54b
add save solution to the example
warisa-r Jul 9, 2024
995107b
update test to be compatible with save_solution
warisa-r Jul 9, 2024
640c7f6
move comment regarding seed upwards
warisa-r Jul 9, 2024
e923305
Revert "Correct the logic of step!" only the part that meddles with m…
warisa-r Jul 9, 2024
f3f4e25
correct methods_PERK3
warisa-r Jul 9, 2024
a6addd7
move is_sol_valid closer to the for loop
warisa-r Jul 9, 2024
87c6cae
fmt
warisa-r Jul 9, 2024
0d642fb
Revert some random changes in other test unit
warisa-r Jul 9, 2024
d602a95
add tolerance to the test
warisa-r Jul 9, 2024
2669e76
Merge branch 'main' into PERK_p3_single_ext
warisa-r Jul 9, 2024
bc358e4
modify functions so that they are also compatible with PERK3
warisa-r Jul 9, 2024
10d7126
change function's name to be more descriptive
warisa-r Jul 9, 2024
75de088
change function's name to be more descriptive in all files
warisa-r Jul 9, 2024
58fabb7
Revert irrelevent change in TrixiConvexECOSExt.jl
warisa-r Jul 9, 2024
40dd610
add PR number to NEWS.md
warisa-r Jul 9, 2024
c104ff2
fmt
warisa-r Jul 9, 2024
76487b5
change from using Random to StableRNGs
warisa-r Jul 9, 2024
ecbb0ff
fix the value in unit test
warisa-r Jul 9, 2024
bcadd5a
remove prints
warisa-r Jul 9, 2024
47e52d0
minor comment correction
warisa-r Jul 10, 2024
9826457
attempt to fix the error at fixed time step
warisa-r Jul 10, 2024
d66b241
add the missing clause to test set
warisa-r Jul 10, 2024
d405551
adjust allocation values in test of perk3
warisa-r Jul 10, 2024
f070668
update test value
warisa-r Jul 10, 2024
5746b5f
move objective function to the extension
warisa-r Jul 11, 2024
b87592e
minor fix with compute_c_coeffs
warisa-r Jul 12, 2024
24cbde6
remove explicit import of solve_a_unknown from line 18
warisa-r Jul 12, 2024
a083ac0
Apply suggestions from code review
DanielDoehring Jul 15, 2024
fe26ef1
document why additional packages are loaded
warisa-r Jul 15, 2024
d7c1ce6
Merge branch 'PERK_p3_single_ext' of https://github.com/warisa-r/Trix…
warisa-r Jul 15, 2024
e42ecaf
Merge branch 'main' into PERK_p3_single_ext
warisa-r Jul 15, 2024
339eae2
correct docstring
warisa-r Jul 16, 2024
5e4676d
Merge branch 'PERK_p3_single_ext' of https://github.com/warisa-r/Trix…
warisa-r Jul 16, 2024
1a0bf58
use Float32
warisa-r Jul 16, 2024
6d95ec6
Update ext/TrixiNLsolveExt.jl
warisa-r Jul 17, 2024
485a2a7
Update ext/TrixiNLsolveExt.jl
warisa-r Jul 17, 2024
f8731c1
Update ext/TrixiNLsolveExt.jl
warisa-r Jul 17, 2024
3faf2cc
change some Flot32 back to the way they originally were
warisa-r Jul 17, 2024
339f43e
add line that get the type that a_unknown should be
warisa-r Jul 17, 2024
6ebf7c8
Merge branch 'main' into PERK_p3_single_ext
warisa-r Jul 17, 2024
ad47a2f
due to some the change of type, print out some values of a_matrix tha…
warisa-r Jul 17, 2024
2974301
update test values
warisa-r Jul 17, 2024
3023dc2
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK3.jl
warisa-r Jul 27, 2024
3071c48
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK3.jl
warisa-r Jul 27, 2024
5bff1d6
Merge branch 'main' into PERK_p3_single_ext
warisa-r Jul 27, 2024
6454c46
Apply suggestions from code review
warisa-r Jul 27, 2024
f325f99
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK3.jl
warisa-r Jul 27, 2024
8334c75
allocate c_eq once per solve_a_unknown is called
warisa-r Jul 27, 2024
b309ca5
Update ext/TrixiNLsolveExt.jl
warisa-r Jul 27, 2024
08733ba
Update ext/TrixiNLsolveExt.jl
warisa-r Jul 27, 2024
01bc757
Update ext/TrixiNLsolveExt.jl
warisa-r Jul 27, 2024
33bdcb8
minor fix regarding recent changes witjh c_eq
warisa-r Jul 27, 2024
ff7ec1a
adjust a constructor to get num stages from reading the files directly
warisa-r Jul 27, 2024
fd05aff
Revert "adjust a constructor to get num stages from reading the files…
warisa-r Jul 29, 2024
582dd87
Update TrixiNLsolveExt.jl to use forward autodiff in solve_a_butcher_…
warisa-r Jul 29, 2024
022eb9a
Merge branch 'main' into PERK_p3_single_ext
warisa-r Aug 10, 2024
859bf37
Apply suggestions from code review
DanielDoehring Aug 13, 2024
5541844
Slight modifications a values
DanielDoehring Aug 14, 2024
fd46502
Merge branch 'main' into PERK_p3_single_ext
warisa-r Sep 1, 2024
0d626b7
Merge branch 'main' into PERK_p3_single_ext
DanielDoehring Sep 11, 2024
0b01fd5
Merge branch 'main' into PERK_p3_single_ext
DanielDoehring Sep 16, 2024
877c562
Merge branch 'main' into PERK_p3_single_ext
warisa-r Oct 10, 2024
a50a4e0
add cfl number calculation for PERK3
warisa-r Oct 10, 2024
0d9e664
update CI values
warisa-r Oct 10, 2024
b18688a
Merge branch 'main' into PERK_p3_single_ext
warisa-r Oct 12, 2024
71cf293
remove the example without cfl calculation
warisa-r Oct 12, 2024
2a0f18e
Merge branch 'PERK_p3_single_ext' of https://github.com/warisa-r/Trix…
warisa-r Oct 12, 2024
995e228
Apply suggestions from code review
warisa-r Oct 12, 2024
109bad9
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK3.jl
warisa-r Oct 12, 2024
5b6edb0
add DOI to a reference in TrixiNLsolveExt
warisa-r Oct 12, 2024
325b2bc
add a copy of PERK3 to work on with testing values of b
warisa-r Oct 12, 2024
ce321ac
some first edits for the embedded scheme
warisa-r Oct 12, 2024
38d98a5
add weak dep stuff
warisa-r Oct 12, 2024
7fb103a
add a couple of TODOs
warisa-r Oct 12, 2024
9953bc2
move the code of b solver from OptRungeKutta to Trixi
warisa-r Oct 13, 2024
f30d533
small comment and minor format fix
warisa-r Oct 13, 2024
23a838c
we do not have to store e-2 k when we increment k for every stage tha…
warisa-r Oct 13, 2024
e7a6ee1
- add an extra argument to solve_a_butcher_coeffs_unknown! so that e …
warisa-r Oct 13, 2024
d7d7146
fmt
warisa-r Oct 13, 2024
da60e88
add an example and fix solve_b_butcher coeffs unknown
warisa-r Oct 13, 2024
22bfc6c
minor bug fix that makes everything runs without error.
warisa-r Oct 13, 2024
96a7bf8
obvious bug fix
warisa-r Oct 14, 2024
6a526f0
fix obvious bug further
warisa-r Oct 14, 2024
0c0d532
minor change
warisa-r Oct 14, 2024
5208689
minor change and also print out the result
warisa-r Oct 14, 2024
e08f3e9
change cfl number and now result is fine yayy
warisa-r Oct 14, 2024
7fd60c7
change cfl number
warisa-r Oct 14, 2024
9d56c93
change dt_opt to be that of b_opt and add a new example
warisa-r Oct 14, 2024
0bce052
fix the logic of the integrator found from bound error when lower eva…
warisa-r Oct 14, 2024
44ea471
add some comments
warisa-r Oct 14, 2024
810a0a1
fmt
warisa-r Oct 14, 2024
7cce9b6
change back to silent instead of silent_solver
warisa-r Oct 14, 2024
e21e199
try some other s and e for euler's case
warisa-r Oct 14, 2024
c0e0ded
correct some spelling
warisa-r Oct 15, 2024
280ddf1
include normalization
warisa-r Oct 17, 2024
bd94969
fix some bug with normalized_powered_eigvals allocation and loop
warisa-r Oct 17, 2024
3b02868
since now dt_opt doesnt exist. Just use cfl of constant as a makeshif…
warisa-r Oct 17, 2024
92a1f84
change up the approach to the problem
warisa-r Oct 21, 2024
2ef2e0a
something wrong with b values... will have to reconstruct that part a…
warisa-r Oct 21, 2024
753531e
got negative b but equations are set up now
warisa-r Oct 24, 2024
b2358e5
Finally some positive b
warisa-r Oct 25, 2024
2af55dd
change with the integrator
warisa-r Oct 25, 2024
6360b8d
remove some comments and unneeded file
warisa-r Oct 25, 2024
aee9697
some changes. Set constraint to b positive
warisa-r Oct 29, 2024
8e2db4e
Merge branch 'embedded_PERK3' of https://github.com/warisa-r/Trixi.jl…
warisa-r Oct 29, 2024
3e8b981
seeing whether e-2 produce a substantial time step
warisa-r Nov 1, 2024
d19ce67
revert this to original intention
warisa-r Nov 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ for human readability.
- New time integrator `PairedExplicitRK2`, implementing the second-order paired explicit Runge-Kutta
method with [Convex.jl](https://github.com/jump-dev/Convex.jl) and [ECOS.jl](https://github.com/jump-dev/ECOS.jl) ([#1908])
- Add subcell limiting support for `StructuredMesh` ([#1946]).
- New time integrator `PairedExplicitRK3`, implementing the third-order paired explicit Runge-Kutta
method with [Convex.jl](https://github.com/jump-dev/Convex.jl), [ECOS.jl](https://github.com/jump-dev/ECOS.jl),
and [NLsolve.jl](https://github.com/JuliaNLSolvers/NLsolve.jl) ([#2008])

## Changes when updating to v0.7 from v0.6.x

Expand Down
10 changes: 10 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Requires = "ae029012-a4dd-5104-9daa-d747884805df"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
SimpleUnPack = "ce78b400-467f-4804-87d8-8f486da07d0a"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
StartUpDG = "472ebc20-7c99-4d4b-9470-8fde4e9faa0f"
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
StaticArrayInterface = "0d7ed370-da01-4f52-bd93-41d350b8b718"
Expand All @@ -52,16 +53,21 @@ TrixiBase = "9a0f1c46-06d5-4909-a5a3-ce25d3fa3284"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[weakdeps]
Clarabel = "61c947e1-3e6d-4ee4-985a-eec8c727bd6e"
Convex = "f65535da-76fb-5f13-bab9-19810c17039a"
ECOS = "e2685f51-7e38-5353-a97d-a921fd2c8199"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"

[extensions]
TrixiConvexClarabelExt = ["Convex", "Clarabel"]
TrixiConvexECOSExt = ["Convex", "ECOS"]
TrixiMakieExt = "Makie"
TrixiNLsolveExt = "NLsolve"

[compat]
Accessors = "0.1.12"
Clarabel = "0.9.0"
CodeTracking = "1.0.5"
ConstructionBase = "1.3"
Convex = "0.16"
Expand All @@ -82,6 +88,7 @@ LoopVectorization = "0.12.151"
MPI = "0.20"
Makie = "0.19, 0.20"
MuladdMacro = "0.2.2"
NLsolve = "4.5.1"
Octavian = "0.3.21"
OffsetArrays = "1.12"
P4est = "0.4.9"
Expand All @@ -96,6 +103,7 @@ Requires = "1.1"
SciMLBase = "1.90, 2"
SimpleUnPack = "1.1"
SparseArrays = "1"
StableRNGs = "1.0.2"
StartUpDG = "0.17.7, 1.1.5"
Static = "0.8.7"
StaticArrayInterface = "1.4"
Expand All @@ -113,6 +121,8 @@ UUIDs = "1.6"
julia = "1.8"

[extras]
Clarabel = "61c947e1-3e6d-4ee4-985a-eec8c727bd6e"
Convex = "f65535da-76fb-5f13-bab9-19810c17039a"
ECOS = "e2685f51-7e38-5353-a97d-a921fd2c8199"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
69 changes: 69 additions & 0 deletions examples/structured_1d_dgsem/elixir_burgers_perk3.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Convex and ECOS are imported because they are used for finding the optimal time step and optimal
# monomial coefficients in the stability polynomial of P-ERK time integrators.
using Convex, ECOS

# NLsolve is imported to solve the system of nonlinear equations to find a coefficients
# in the Butcher tableau in the third order P-ERK time integrator.
using NLsolve

using OrdinaryDiffEq
using Trixi

###############################################################################
# semidiscretization of the (inviscid) Burgers equation

equations = InviscidBurgersEquation1D()

initial_condition = initial_condition_convergence_test

# Create DG solver with polynomial degree = 4 and (local) Lax-Friedrichs/Rusanov flux as surface flux
solver = DGSEM(polydeg = 4, surface_flux = flux_lax_friedrichs)

coordinates_min = (0.0,) # minimum coordinate
coordinates_max = (1.0,) # maximum coordinate
cells_per_dimension = (64,)

mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max)

semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
source_terms = source_terms_convergence_test)

###############################################################################
# ODE solvers, callbacks etc.

tspan = (0.0, 2.0)
ode = semidiscretize(semi, tspan)

summary_callback = SummaryCallback()

analysis_interval = 200
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)

alive_callback = AliveCallback(analysis_interval = analysis_interval)

save_solution = SaveSolutionCallback(dt = 0.1,
save_initial_solution = true,
save_final_solution = true,
solution_variables = cons2prim)

# Construct second order paired explicit Runge-Kutta method with 8 stages for given simulation setup.
# Pass `tspan` to calculate maximum time step allowed for the bisection algorithm used
# in calculating the polynomial coefficients in the ODE algorithm.
ode_algorithm = Trixi.PairedExplicitRK3(8, tspan, semi)

cfl_number = Trixi.calculate_cfl(ode_algorithm, ode)
# For non-linear problems, the CFL number should be reduced by a safety factor
stepsize_callback = StepsizeCallback(cfl = 0.85 * cfl_number)

callbacks = CallbackSet(summary_callback,
analysis_callback, alive_callback, save_solution,
stepsize_callback)

###############################################################################
# run the simulation
sol = Trixi.solve(ode, ode_algorithm,
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);

# Print the timer summary
summary_callback()
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# The same setup as tree_1d_dgsem/elixir_euler_source_terms.jl
# to verify the StructuredMesh implementation against TreeMesh
using Convex, ECOS, Clarabel
using OrdinaryDiffEq
using Trixi

###############################################################################
# semidiscretization of the compressible Euler equations

equations = CompressibleEulerEquations1D(1.4)

initial_condition = initial_condition_convergence_test

# Note that the expected EOC of 5 is not reached with this flux.
# Using flux_hll instead yields the expected EOC.
solver = DGSEM(polydeg = 4, surface_flux = flux_lax_friedrichs)

coordinates_min = (0.0,)
coordinates_max = (2.0,)
cells_per_dimension = (16,)

mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max)

semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
source_terms = source_terms_convergence_test)

###############################################################################
# ODE solvers, callbacks etc.

tspan = (0.0, 2.0)
ode = semidiscretize(semi, tspan)

summary_callback = SummaryCallback()

analysis_interval = 100
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
extra_analysis_errors = (:l2_error_primitive,
:linf_error_primitive))

alive_callback = AliveCallback(analysis_interval = analysis_interval)

save_solution = SaveSolutionCallback(interval = 100,
save_initial_solution = true,
save_final_solution = true,
solution_variables = cons2prim)

# Construct embedded order paired explicit Runge-Kutta method with 10 stages and 6 evaluation stages for given simulation setup.
# Pass `tspan` to calculate maximum time step allowed for the bisection algorithm used
# in calculating the polynomial coefficients in the ODE algorithm.
ode_algorithm = Trixi.EmbeddedPairedRK3(10, 7, tspan, semi)
cfl_number = Trixi.calculate_cfl(ode_algorithm, ode)

stepsize_callback = StepsizeCallback(cfl = 0.5) # Warisa: This number is extremely small in contrast the other one from optimizing A
# I've tried using cfl of 0.5 and the error is very similar.

callbacks = CallbackSet(summary_callback,
alive_callback,
save_solution,
analysis_callback,
stepsize_callback)

###############################################################################
# run the simulation

sol = Trixi.solve(ode, ode_algorithm,
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary

# Some function defined so that I can check if the second order condition is met. This will be removed later.
function construct_b_vector(b_unknown, num_stages_embedded, num_stage_evals_embedded)
# Construct the b vector
b = [
1 - sum(b_unknown),
zeros(Float64, num_stages_embedded - num_stage_evals_embedded)...,
b_unknown...,
0
]
return b
end

b = construct_b_vector(ode_algorithm.b, ode_algorithm.num_stages - 1,
ode_algorithm.num_stage_evals - 1)
println("dot(b, c) = ", dot(b, ode_algorithm.c))
println("sum(b) = ", sum(b))

println("cfl_number = ", cfl_number)
79 changes: 79 additions & 0 deletions examples/tree_1d_dgsem/elixir_advection_embedded_perk3.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@

# Convex and ECOS are imported because they are used for finding the optimal time step and optimal
# monomial coefficients in the stability polynomial of P-ERK time integrators.
using Convex, ECOS

using OrdinaryDiffEq
using Trixi

###############################################################################
# semidiscretization of the linear advection equation

advection_velocity = 1.0
equations = LinearScalarAdvectionEquation1D(advection_velocity)

# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)

coordinates_min = -1.0 # minimum coordinate
coordinates_max = 1.0 # maximum coordinate

# Create a uniformly refined mesh with periodic boundaries
mesh = TreeMesh(coordinates_min, coordinates_max,
initial_refinement_level = 4,
n_cells_max = 30_000) # set maximum capacity of tree data structure

# A semidiscretization collects data structures and functions for the spatial discretization
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,
solver)

###############################################################################
# ODE solvers, callbacks etc.

# Create ODE problem with time span from 0.0 to 20.0
tspan = (0.0, 20.0)
ode = semidiscretize(semi, tspan);

# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
# and resets the timers
summary_callback = SummaryCallback()

# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
analysis_interval = 100
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)

# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step

alive_callback = AliveCallback(alive_interval = analysis_interval)

save_solution = SaveSolutionCallback(dt = 0.1,
save_initial_solution = true,
save_final_solution = true,
solution_variables = cons2prim)

# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver

# Construct embedded order paired explicit Runge-Kutta method with 10 stages and 7 evaluation stages for given simulation setup.
# Pass `tspan` to calculate maximum time step allowed for the bisection algorithm used
# in calculating the polynomial coefficients in the ODE algorithm.
ode_algorithm = Trixi.EmbeddedPairedRK3(16, 16, tspan, semi)

# Calculate the CFL number for the given ODE algorithm and ODE problem (cfl_number calculate from dt_opt of the optimization of
# b values in the Butcher tableau of the ODE algorithm).
#cfl_number = Trixi.calculate_cfl(ode_algorithm, ode)
stepsize_callback = StepsizeCallback()

callbacks = CallbackSet(summary_callback,
alive_callback,
save_solution,
analysis_callback,
stepsize_callback)

###############################################################################
# run the simulation
sol = Trixi.solve(ode, ode_algorithm,
dt = 1.0, # Manual time step value, will be overwritten by the stepsize_callback when it is specified.
save_everystep = false, callback = callbacks);

# Print the timer summary
summary_callback()
3 changes: 3 additions & 0 deletions examples/tree_1d_dgsem/elixir_advection_perk2.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

# Convex and ECOS are imported because they are used for finding the optimal time step and optimal
# monomial coefficients in the stability polynomial of P-ERK time integrators.
using Convex, ECOS

using OrdinaryDiffEq
using Trixi

Expand Down
Loading
Loading