Skip to content

Commit

Permalink
Revise derivative function call; Add default derivative version
Browse files Browse the repository at this point in the history
  • Loading branch information
bennibolm committed Nov 16, 2023
1 parent 062568c commit 849b09e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/equations/compressible_euler_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,8 @@ end
end

# Transformation from conservative variables u to d(p)/d(u)
@inline function pressure(u, equations::CompressibleEulerEquations2D, derivative::True)
@inline function variable_derivative(::typeof(pressure),
u, equations::CompressibleEulerEquations2D)
rho, rho_v1, rho_v2, rho_e = u

v1 = rho_v1 / rho
Expand Down
6 changes: 6 additions & 0 deletions src/equations/equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ of the correct length `nvariables(equations)`.
"""
function energy_internal end

# Default implementation of derivation for `variable`. Used for subcell limiting.
# Implementing a derivative function for a specific function improves the performance.
@inline function variable_derivative(variable, u, equations)
return ForwardDiff.gradient(x -> variable(x, equations), u)
end

####################################################################################################
# Include files with actual implementations for different systems of equations.

Expand Down
3 changes: 2 additions & 1 deletion src/equations/ideal_glm_mhd_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,8 @@ end
end

# Transformation from conservative variables u to d(p)/d(u)
@inline function pressure(u, equations::IdealGlmMhdEquations2D, derivative::True)
@inline function variable_derivative(::typeof(pressure),
u, equations::IdealGlmMhdEquations2D)
rho, rho_v1, rho_v2, rho_v3, rho_e, B1, B2, B3, psi = u

v1 = rho_v1 / rho
Expand Down
2 changes: 1 addition & 1 deletion src/solvers/dgsem_tree/subcell_limiters_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ end
# Goal and d(Goal)d(u) function
@inline goal_function(variable, bound, u, equations) = bound - variable(u, equations)
@inline function dgoal_function(variable, u, dt, antidiffusive_flux, equations)
-dot(variable(u, equations, True()), dt * antidiffusive_flux)
-dot(variable_derivative(variable, u, equations), dt * antidiffusive_flux)
end

# Final checks
Expand Down

0 comments on commit 849b09e

Please sign in to comment.