Skip to content

Commit

Permalink
Minor modification on PairedExplicitRK3 to reduce redundant computati…
Browse files Browse the repository at this point in the history
…on (#2152)

* remove the redundant recalculation of c in the objective function

* put verbose and max_iter on the same line as c

---------

Co-authored-by: Hendrik Ranocha <[email protected]>
Co-authored-by: Daniel Doehring <[email protected]>
  • Loading branch information
3 people authored Nov 8, 2024
1 parent a0c14d7 commit e1950ac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions ext/TrixiNLsolveExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ end
using StableRNGs: StableRNG, rand

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

# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).
# Since these FMAs can increase the performance of many numerical algorithms,
Expand All @@ -29,9 +29,8 @@ using Trixi: Trixi, compute_c_coeffs, @muladd
function PairedExplicitRK3_butcher_tableau_objective_function!(c_eq, a_unknown,
num_stages,
num_stage_evals,
monomial_coeffs,
cS2)
c_ts = compute_c_coeffs(num_stages, cS2) # ts = timestep
monomial_coeffs, c)
c_ts = c # ts = timestep
# For explicit methods, a_{1,1} = 0 and a_{2,1} = c_2 (Butcher's condition)
a_coeff = [0, c_ts[2], a_unknown...]
# Equality constraint array that ensures that the stability polynomial computed from
Expand Down Expand Up @@ -74,16 +73,15 @@ end
# For details, see Proposition 3.2, Equation (3.3) from
# Hairer, Wanner: Solving Ordinary Differential Equations 2
function Trixi.solve_a_butcher_coeffs_unknown!(a_unknown, num_stages, monomial_coeffs,
c_s2, c;
verbose, max_iter = 100000)
c; verbose, max_iter = 100000)

# Define the objective_function
function objective_function!(c_eq, x)
return PairedExplicitRK3_butcher_tableau_objective_function!(c_eq, x,
num_stages,
num_stages,
monomial_coeffs,
c_s2)
c)
end

# RealT is determined as the type of the first element in monomial_coeffs to ensure type consistency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function compute_PairedExplicitRK3_butcher_tableau(num_stages, tspan,
# Butcher array abscissae c to find Butcher matrix A
# This function is extended in TrixiNLsolveExt.jl
a_unknown = solve_a_butcher_coeffs_unknown!(a_unknown, num_stages,
monomial_coeffs, cS2, c;
monomial_coeffs, c;
verbose)
end
# Fill A-matrix in P-ERK style
Expand Down

0 comments on commit e1950ac

Please sign in to comment.