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

Perk p2 single ext #1908

Merged
merged 170 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 166 commits
Commits
Show all changes
170 commits
Select commit Hold shift + click to select a range
befd590
Templates for PERK p2, p3
DanielDoehring Jan 29, 2024
0b378f7
example
DanielDoehring Jan 29, 2024
42c74d1
constructor changed
warisa-r Feb 2, 2024
04784df
Modified so that both of the constructor stay
warisa-r Feb 2, 2024
3fcad2a
Merge pull request #20 from warisa-r/PERK_p2p3_Single
DanielDoehring Feb 2, 2024
55f4165
bring back eps
DanielDoehring Feb 8, 2024
6a31a0b
correct val
DanielDoehring Feb 8, 2024
87399dc
add constructor of PERK3
warisa-r Feb 14, 2024
e518386
minor fixes
warisa-r Feb 14, 2024
a1222d7
function and variable name adjustments
warisa-r Feb 15, 2024
483015b
spelling fix
warisa-r Feb 15, 2024
de86860
Merge branch 'PERK_p2p3_Single' into PERK_p2p3_Single
DanielDoehring Feb 16, 2024
6436708
Merge pull request #21 from warisa-r/PERK_p2p3_Single
DanielDoehring Feb 18, 2024
03f0af1
Change names and spacing according to style guide
warisa-r Mar 3, 2024
5a13446
Merge branch 'PERK_p2p3_Single' of github.com:warisa-r/Trixi.jl into …
warisa-r Mar 3, 2024
e182a89
spelling correction
warisa-r Mar 3, 2024
08b70d6
Apply suggestions from code review
warisa-r Mar 4, 2024
9881351
Merge pull request #24 from warisa-r/PERK_p2p3_Single
DanielDoehring Mar 5, 2024
bdb2db5
snake case
DanielDoehring Mar 5, 2024
19a1653
Merge branch 'PERK_p2p3_Single' of github.com:DanielDoehring/Trixi.jl…
DanielDoehring Mar 5, 2024
df4733d
revisit perk single p2 p3
DanielDoehring Mar 5, 2024
ee9e569
fmt
DanielDoehring Mar 5, 2024
32cbb1e
fmt
DanielDoehring Mar 5, 2024
be8ea21
Merge branch 'main' into PERK_p2p3_Single
DanielDoehring Mar 5, 2024
e3ec50c
semantic ordering
DanielDoehring Mar 5, 2024
fbcd6e3
add literature
DanielDoehring Mar 6, 2024
b1b6d7c
Strip code of p = 3
warisa-r Mar 6, 2024
33bb8da
Add the line to show the error of the elixir
warisa-r Mar 7, 2024
5f763bb
Make adjustments to a test file and delete example of PERK3
warisa-r Mar 8, 2024
9149b7b
Update Project.toml
warisa-r Mar 8, 2024
6c04331
Update examples/tree_1d_dgsem/elixir_advection_PERK2.jl
warisa-r Mar 8, 2024
0bafb7f
Add comments in an example of PERK2
warisa-r Mar 8, 2024
64926fb
Update src/Trixi.jl
warisa-r Mar 8, 2024
6ce99e6
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK2.jl
warisa-r Mar 8, 2024
50cf650
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK2.jl
warisa-r Mar 8, 2024
f48cf85
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK2.jl
warisa-r Mar 8, 2024
e7060e5
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK2.jl
warisa-r Mar 8, 2024
88e8168
add tspan as a parameter and adjust the elixir accordingly
warisa-r Mar 8, 2024
bb938d9
add an additional constructor and modify the function compute_PERK2_b…
warisa-r Mar 8, 2024
38f4fcb
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK2.jl
warisa-r Mar 11, 2024
7619b2a
update filter function in polynomial optimizer, add literature, and c…
warisa-r Mar 12, 2024
98bfe13
Merge branch 'PERK_p2_Single' of github.com:warisa-r/Trixi.jl into PE…
warisa-r Mar 12, 2024
f2d9fa8
Apply suggestions from code review
warisa-r Mar 12, 2024
ccf4260
change tspan to have (,) instead of[,]. filter_eigenvalues minor adju…
warisa-r Mar 12, 2024
11e487c
Merge branch 'main' into PERK_p2_Single
DanielDoehring Mar 14, 2024
6cb0572
Apply suggestions from code review
warisa-r Mar 14, 2024
1f4e9d0
Update src/time_integration/paired_explicit_runge_kutta/polynomial_op…
DanielDoehring Mar 14, 2024
61da622
Apply suggestions from code review
DanielDoehring Mar 15, 2024
16ac4d5
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK2.jl
DanielDoehring Mar 15, 2024
b3c12ee
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK2.jl
DanielDoehring Mar 15, 2024
cb0ef29
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK2.jl
DanielDoehring Mar 15, 2024
a1506a0
Apply suggestions from code review
DanielDoehring Mar 15, 2024
6fc11d5
use readdlm instead of read_file
warisa-r Mar 15, 2024
ef1f508
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK2.jl
DanielDoehring Mar 15, 2024
5bb554a
add DelimFIles
DanielDoehring Mar 15, 2024
60cd20e
fmt
DanielDoehring Mar 15, 2024
8e850eb
Unit tests
DanielDoehring Mar 15, 2024
93f2ce5
Merge branch 'main' into PERK_p2_Single
DanielDoehring Mar 15, 2024
08faa0a
compat
DanielDoehring Mar 15, 2024
e17f7ad
ecos compat
DanielDoehring Mar 15, 2024
f3220e7
compat
DanielDoehring Mar 15, 2024
17096fe
compat
DanielDoehring Mar 15, 2024
01d04f2
compat
DanielDoehring Mar 15, 2024
44f413a
compat
DanielDoehring Mar 15, 2024
4ae2574
Merge branch 'main' into PERK_p2_Single
DanielDoehring Mar 15, 2024
3280fc1
callbacks
DanielDoehring Mar 15, 2024
4a3deda
increase allowed allocs
DanielDoehring Mar 17, 2024
a1da64e
fmt
DanielDoehring Mar 18, 2024
e804a63
timer for step callbacks
DanielDoehring Mar 18, 2024
214fa6a
deps compat
DanielDoehring Mar 18, 2024
443a162
remove del files compat
DanielDoehring Mar 18, 2024
247946b
skip delimitedfiles in downgrade compat
DanielDoehring Mar 18, 2024
1b3d4f6
v1
DanielDoehring Mar 18, 2024
1b94f83
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK2.jl
DanielDoehring Mar 20, 2024
2ecb50f
Merge branch 'main' into PERK_p2_Single
DanielDoehring Mar 25, 2024
0d410e4
modular imp of the integrator
warisa-r Apr 12, 2024
9c55c75
modularized PolynamialOptimizer
warisa-r Apr 15, 2024
9a5d8f6
PolynomialOpt modularized
warisa-r Apr 15, 2024
8dd65bf
use "fake" extension
warisa-r Apr 15, 2024
99c1f93
make ECOS weakdep
warisa-r Apr 16, 2024
f6332fb
fix name
warisa-r Apr 16, 2024
c5fa58b
comment + fmt
warisa-r Apr 16, 2024
f7264c7
Merge branch 'main' into PERK_p2_Single_ext
DanielDoehring Apr 18, 2024
8317412
Apply suggestions from code review
warisa-r Apr 19, 2024
a4036d5
comment, fix, and make threshold optional
warisa-r Apr 22, 2024
9d9a31b
Apply suggestions from code review
warisa-r Apr 23, 2024
2e60b69
edit tspan and alive_interval
warisa-r Apr 23, 2024
1af9900
Merge branch 'main' into PERK_p2_Single_ext
DanielDoehring Apr 23, 2024
98bb965
Apply suggestions from code review
warisa-r Apr 24, 2024
e76eaec
fmt
warisa-r Apr 24, 2024
8bec402
fix fmr in test unit
warisa-r Apr 24, 2024
3330450
fix fmt in test_unit.jl
warisa-r Apr 24, 2024
247301d
Merge branch 'PERK_p2_Single_ext' of github.com:warisa-r/Trixi.jl int…
warisa-r Apr 24, 2024
deb02a1
some fixes according to code review
warisa-r Apr 29, 2024
9aea224
add ECOS as a part of enabling TrixiConvexECOSExt.jl compiles
warisa-r Apr 29, 2024
8b1587b
state functions and classes from Convex package used in polynomial op…
warisa-r Apr 29, 2024
30beab8
fmt
warisa-r Apr 29, 2024
9c9540c
remove unconditional output in bisection
warisa-r Apr 29, 2024
f740c38
Apply suggestions from code review
warisa-r Apr 29, 2024
5dffcd6
apply suggestion from code review
warisa-r Apr 29, 2024
4a6bf89
minor fix
warisa-r Apr 29, 2024
6a78615
Apply suggestions from code review
warisa-r Apr 29, 2024
b79a83a
add verbose as an optional argument for printing out some outputs dur…
warisa-r Apr 29, 2024
ffb0a35
remove the file with upper case
warisa-r Apr 29, 2024
dc03ed2
add the file with corrected name
warisa-r Apr 29, 2024
a650ba6
Merge branch 'main' into PERK_p2_Single_ext
warisa-r Apr 30, 2024
402211c
minor fix
warisa-r Apr 30, 2024
fd336dd
Merge branch 'PERK_p2_Single_ext' of github.com:warisa-r/Trixi.jl int…
warisa-r Apr 30, 2024
47ce648
move constructors outside of struct
warisa-r Apr 30, 2024
e15896a
Apply suggestions from code review
warisa-r Apr 30, 2024
f46995e
alter some names from being abbreviated and some fixes
warisa-r Apr 30, 2024
4e0b19a
add comments for some functions and move all polynomial optimizaton r…
warisa-r Apr 30, 2024
b85e68d
add comments to functions computing butcher tableau
warisa-r Apr 30, 2024
1b52104
fmt
warisa-r Apr 30, 2024
54c74b8
apply suggestions + fmt
warisa-r Apr 30, 2024
1bfbf8c
apply suggestion according to code review
warisa-r Apr 30, 2024
1b83911
Apply suggestions from code review
warisa-r May 2, 2024
27b6033
fix PERK2's name
warisa-r May 2, 2024
e6560da
add short comment regarding PERK's abbreviation
warisa-r May 2, 2024
c8201a5
fix export
warisa-r May 3, 2024
c204c99
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK2.jl
warisa-r May 3, 2024
1284c0b
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK2.jl
warisa-r May 3, 2024
43ca527
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK2.jl
warisa-r May 3, 2024
e8b5605
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK2.jl
warisa-r May 3, 2024
de85230
minor corrections
warisa-r May 3, 2024
65a015a
remove exported of PERK functions in extension
warisa-r May 3, 2024
0849ba7
set verbose's default value in kwarg
warisa-r May 3, 2024
e59df79
Merge branch 'main' into PERK_p2_Single_ext
DanielDoehring May 4, 2024
16f2001
fix path_monomial_coeffs
warisa-r May 4, 2024
e164a5b
Merge branch 'PERK_p2_Single_ext' of github.com:warisa-r/Trixi.jl int…
warisa-r May 4, 2024
e6e8e33
fmt
warisa-r May 4, 2024
7dc3809
add ECOS as dependency in test/Project.toml
warisa-r May 4, 2024
8befaaf
bring back polynomial_optimizer so that user can call the constructor…
warisa-r May 4, 2024
28d2134
fix values for some tests and add use Convex and ECOS to load functio…
warisa-r May 4, 2024
f8e839b
fix error undefined b1
warisa-r May 4, 2024
2953ec8
attempt to fix error from test by specifying Trixi.entropy
warisa-r May 4, 2024
41b3c31
fmt
warisa-r May 4, 2024
1bea8a2
adjust the value of tests to allign with one in CI and add print comm…
warisa-r May 4, 2024
6dae59b
exclude convex warning
DanielDoehring May 5, 2024
7ffb056
update test vals
DanielDoehring May 5, 2024
5cfd3b0
more warning exclusions
DanielDoehring May 5, 2024
86a7ca8
Merge branch 'main' into PERK_p2_Single_ext
DanielDoehring May 6, 2024
4a4bb4e
Apply suggestions from code review
warisa-r May 7, 2024
c706836
Apply suggestions from code review
warisa-r May 7, 2024
c9ae47f
minor fix
warisa-r May 7, 2024
1ed747c
add what is used from ECOS
warisa-r May 7, 2024
06f64c5
spell check
warisa-r May 7, 2024
e293694
add information about this PR in NEWS.md
warisa-r May 7, 2024
a04be54
Update NEWS.md
warisa-r May 7, 2024
700adda
fix NEWS.md
warisa-r May 7, 2024
b49dbd7
change Trixi.entropy back to just entropy
warisa-r May 9, 2024
847f02a
Update NEWS.md
warisa-r May 9, 2024
ab3fae9
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK2.jl
warisa-r May 9, 2024
69a6e1f
Apply suggestions from code review
warisa-r May 9, 2024
3b4a4da
Merge branch 'main' into PERK_p2_Single_ext
DanielDoehring May 14, 2024
3b441a5
Apply suggestions from code review
DanielDoehring May 14, 2024
9c0ed66
Apply suggestions from code review
DanielDoehring May 14, 2024
a7162d1
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK2.jl
DanielDoehring May 14, 2024
43d4fad
Merge branch 'main' into PERK_p2_Single_ext
DanielDoehring May 14, 2024
685b393
add some explanations regarding the arguments of the constructors
warisa-r May 15, 2024
6833eb0
fmt
warisa-r May 15, 2024
b78387b
exchange "c_end" for "cS" for consistency
DanielDoehring May 17, 2024
ad8b384
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK2.jl
warisa-r May 17, 2024
6a8a085
add more explaination
warisa-r May 17, 2024
663252d
minor adjustment
warisa-r May 17, 2024
e4e397d
Merge branch 'main' into PERK_p2_Single_ext
JoshuaLampert May 17, 2024
248129f
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK2.jl
warisa-r May 17, 2024
6891aaa
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK2.jl
warisa-r May 17, 2024
339e355
Update src/time_integration/paired_explicit_runge_kutta/methods_PERK2.jl
warisa-r May 17, 2024
7bc1ca3
Merge branch 'main' into PERK_p2_Single_ext
sloede May 21, 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
2 changes: 1 addition & 1 deletion .github/workflows/Downgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-downgrade-compat@v1
with:
skip: LinearAlgebra,Printf,SparseArrays,UUIDs,DiffEqBase
skip: LinearAlgebra,Printf,SparseArrays,UUIDs,DiffEqBase,DelimitedFiles
projects: ., test
- uses: julia-actions/julia-buildpkg@v1
env:
Expand Down
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ for human readability.
## Changes in the v0.7 lifecycle

#### Added
- Implementation of `TimeSeriesCallback` for curvilinear meshes on `UnstructuredMesh2D` and extension
to 1D and 3D on `TreeMesh` ([#1855], [#1873]).
- Implementation of `TimeSeriesCallback` for curvilinear meshes on `UnstructuredMesh2D` and extension to 1D and 3D on `TreeMesh` ([#1855], [#1873]).
- Implementation of 1D Linearized Euler Equations ([#1867]).
- New analysis callback for 2D `P4estMesh` to compute integrated quantities along a boundary surface, e.g., pressure lift and drag coefficients ([#1812]).
- Optional tuple parameter for `GlmSpeedCallback` called `semi_indices` to specify for which semidiscretization of a `SemidiscretizationCoupled` we need to update the GLM speed ([#1835]).
- Subcell local one-sided limiting support for nonlinear variables in 2D for `TreeMesh` ([#1792]).
- 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])

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

Expand Down
9 changes: 9 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ version = "0.7.14-pre"
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
DiffEqCallbacks = "459566f4-90b8-5000-8ac3-15dfb0a30def"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
Expand Down Expand Up @@ -50,17 +51,23 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[weakdeps]
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Convex = "f65535da-76fb-5f13-bab9-19810c17039a"
ECOS = "e2685f51-7e38-5353-a97d-a921fd2c8199"

[extensions]
TrixiMakieExt = "Makie"
TrixiConvexECOSExt = ["Convex", "ECOS"]

[compat]
CodeTracking = "1.0.5"
ConstructionBase = "1.3"
Convex = "0.15.4"
DataStructures = "0.18.15"
DelimitedFiles = "1"
DiffEqBase = "6 - 6.143"
DiffEqCallbacks = "2.25"
Downloads = "1.6"
ECOS = "1.1.2"
warisa-r marked this conversation as resolved.
Show resolved Hide resolved
EllipsisNotation = "1.0"
FillArrays = "0.13.2, 1"
ForwardDiff = "0.10.24"
Expand Down Expand Up @@ -103,3 +110,5 @@ julia = "1.8"

[extras]
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Convex = "f65535da-76fb-5f13-bab9-19810c17039a"
ECOS = "e2685f51-7e38-5353-a97d-a921fd2c8199"
66 changes: 66 additions & 0 deletions examples/tree_1d_dgsem/elixir_advection_perk2.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

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
stepsize_callback = StepsizeCallback(cfl = 2.5)

alive_callback = AliveCallback(alive_interval = analysis_interval)

# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
callbacks = CallbackSet(summary_callback,
alive_callback,
analysis_callback,
stepsize_callback)

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

# Construct second order paired explicit Runge-Kutta method with 6 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.PairedExplicitRK2(6, tspan, semi)

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()
158 changes: 158 additions & 0 deletions ext/TrixiConvexECOSExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# Package extension for adding Convex-based features to Trixi.jl
module TrixiConvexECOSExt

# Required for coefficient optimization in P-ERK scheme integrators
if isdefined(Base, :get_extension)
using Convex: MOI, solve!, Variable, minimize, evaluate
using ECOS: Optimizer
else
# Until Julia v1.9 is the minimum required version for Trixi.jl, we still support Requires.jl
using ..Convex: MOI, solve!, Variable, minimize, evaluate
using ..ECOS: Optimizer
end

# Use other necessary libraries
using LinearAlgebra: eigvals

# Use functions that are to be extended and additional symbols that are not exported
using Trixi: Trixi, undo_normalization!, bisect_stability_polynomial, @muladd

# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).
# Since these FMAs can increase the performance of many numerical algorithms,
# we need to opt-in explicitly.
# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details.
@muladd begin
#! format: noindent

# Undo normalization of stability polynomial coefficients by index factorial
# relative to consistency order.
function Trixi.undo_normalization!(gamma_opt, consistency_order, num_stage_evals)
for k in (consistency_order + 1):num_stage_evals
gamma_opt[k - consistency_order] = gamma_opt[k - consistency_order] /
factorial(k)
end
return gamma_opt
end

# Compute stability polynomials for paired explicit Runge-Kutta up to specified consistency
# order, including contributions from free coefficients for higher orders, and
# return the maximum absolute value
function stability_polynomials!(pnoms, consistency_order, num_stage_evals,
normalized_powered_eigvals_scaled,
gamma)
num_eig_vals = length(pnoms)

# Initialize with zero'th order (z^0) coefficient
for i in 1:num_eig_vals
pnoms[i] = 1.0
end
sloede marked this conversation as resolved.
Show resolved Hide resolved

# First `consistency_order` terms of the exponential
for k in 1:consistency_order
for i in 1:num_eig_vals
pnoms[i] += normalized_powered_eigvals_scaled[i, k]
end
end

# Contribution from free coefficients
for k in (consistency_order + 1):num_stage_evals
pnoms += gamma[k - consistency_order] * normalized_powered_eigvals_scaled[:, k]
end

# For optimization only the maximum is relevant
return maximum(abs(pnoms))
end

#=
The following structures and methods provide a simplified implementation to
discover optimal stability polynomial for a given set of `eig_vals`
These are designed for the one-step (i.e., Runge-Kutta methods) integration of initial value ordinary
and partial differential equations.

- Ketcheson and Ahmadia (2012).
Optimal stability polynomials for numerical integration of initial value problems
[DOI: 10.2140/camcos.2012.7.247](https://doi.org/10.2140/camcos.2012.7.247)
=#

# Perform bisection to optimize timestep for stability of the polynomial
function Trixi.bisect_stability_polynomial(consistency_order, num_eig_vals,
num_stage_evals,
dtmax, dteps, eig_vals;
verbose = false)
dtmin = 0.0
dt = -1.0
abs_p = -1.0

# Construct stability polynomial for each eigenvalue
pnoms = ones(Complex{Float64}, num_eig_vals, 1)

# Init datastructure for monomial coefficients
gamma = Variable(num_stage_evals - consistency_order)

normalized_powered_eigvals = zeros(Complex{Float64}, num_eig_vals, num_stage_evals)

for j in 1:num_stage_evals
fac_j = factorial(j)
for i in 1:num_eig_vals
normalized_powered_eigvals[i, j] = eig_vals[i]^j / fac_j
end
end

normalized_powered_eigvals_scaled = similar(normalized_powered_eigvals)

if verbose
println("Start optimization of stability polynomial \n")
end

# Bisection on timestep
while dtmax - dtmin > dteps
warisa-r marked this conversation as resolved.
Show resolved Hide resolved
warisa-r marked this conversation as resolved.
Show resolved Hide resolved
dt = 0.5 * (dtmax + dtmin)

# Compute stability polynomial for current timestep
for k in 1:num_stage_evals
dt_k = dt^k
for i in 1:num_eig_vals
normalized_powered_eigvals_scaled[i, k] = dt_k *
normalized_powered_eigvals[i,
k]
end
end

# Use last optimal values for gamma in (potentially) next iteration
problem = minimize(stability_polynomials!(pnoms, consistency_order,
num_stage_evals,
normalized_powered_eigvals_scaled,
gamma))

solve!(problem,
# Parameters taken from default values for EiCOS
MOI.OptimizerWithAttributes(Optimizer, "gamma" => 0.99,
"delta" => 2e-7,
"feastol" => 1e-9,
"abstol" => 1e-9,
"reltol" => 1e-9,
"feastol_inacc" => 1e-4,
"abstol_inacc" => 5e-5,
"reltol_inacc" => 5e-5,
"nitref" => 9,
"maxit" => 100,
"verbose" => 3); silent_solver = true)

abs_p = problem.optval

if abs_p < 1
dtmin = dt
else
dtmax = dt
end
end

if verbose
println("Concluded stability polynomial optimization \n")
end

return evaluate(gamma), dt
end
end # @muladd

end # module TrixiConvexECOSExt
8 changes: 8 additions & 0 deletions src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,14 @@ function __init__()
end
end

@static if !isdefined(Base, :get_extension)
warisa-r marked this conversation as resolved.
Show resolved Hide resolved
@require Convex="f65535da-76fb-5f13-bab9-19810c17039a" begin
@require ECOS="e2685f51-7e38-5353-a97d-a921fd2c8199" begin
include("../ext/TrixiConvexECOSExt.jl")
end
end
end

# FIXME upstream. This is a hacky workaround for
# https://github.com/trixi-framework/Trixi.jl/issues/628
# https://github.com/trixi-framework/Trixi.jl/issues/1185
Expand Down
Loading
Loading