forked from trixi-framework/Trixi.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request trixi-framework#353 from trixi-framework/fix_calc_ch
Fix calc ch
- Loading branch information
Showing
22 changed files
with
205 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
""" | ||
GlmSpeedCallback(; glm_scale=0.5, cfl) | ||
Update the divergence cleaning wave speed `c_h` according to the time step | ||
computed in [`StepsizeCallback`](@ref) for the ideal GLM-MHD equations. | ||
The `cfl` number should be set to the same value as for the time step size calculation. The | ||
`glm_scale` ensures that the GLM wave speed is lower than the fastest physical waves in the MHD | ||
solution and should thus be set to a value within the interval [0,1]. Note that `glm_scale` = 0 | ||
deactivates the divergence cleaning. | ||
""" | ||
struct GlmSpeedCallback{RealT<:Real} | ||
glm_scale::RealT | ||
cfl::RealT | ||
end | ||
|
||
|
||
function Base.show(io::IO, cb::DiscreteCallback{Condition,Affect!}) where {Condition, Affect!<:GlmSpeedCallback} | ||
glm_speed_callback = cb.affect! | ||
@unpack glm_scale, cfl = glm_speed_callback | ||
print(io, "GlmSpeedCallback(glm_scale=", glm_scale, ", cfl=", cfl, ")") | ||
end | ||
|
||
|
||
function Base.show(io::IO, ::MIME"text/plain", cb::DiscreteCallback{Condition,Affect!}) where {Condition, Affect!<:GlmSpeedCallback} | ||
if get(io, :compact, false) | ||
show(io, cb) | ||
else | ||
glm_speed_callback = cb.affect! | ||
|
||
setup = [ | ||
"GLM wave speed scaling" => glm_speed_callback.glm_scale, | ||
"Expected CFL number" => glm_speed_callback.cfl, | ||
] | ||
summary_box(io, "GlmSpeedCallback", setup) | ||
end | ||
end | ||
|
||
|
||
function GlmSpeedCallback(; glm_scale=0.5, cfl) | ||
# when is the callback activated | ||
condition = (u, t, integrator) -> true | ||
|
||
@assert 0 <= glm_scale <= 1 "glm_scale must be between 0 and 1" | ||
|
||
glm_speed_callback = GlmSpeedCallback(glm_scale, cfl) | ||
|
||
DiscreteCallback(condition, glm_speed_callback, | ||
save_positions=(false,false), | ||
initialize=initialize!) | ||
end | ||
|
||
|
||
function initialize!(cb::DiscreteCallback{Condition,Affect!}, u, t, integrator) where {Condition, Affect!<:GlmSpeedCallback} | ||
cb.affect!(integrator) | ||
end | ||
|
||
|
||
# This method is called as callback after the StepsizeCallback during the time integration. | ||
@inline function (glm_speed_callback::GlmSpeedCallback)(integrator) | ||
|
||
dt = get_proposed_dt(integrator) | ||
semi = integrator.p | ||
mesh, equations, solver, cache = mesh_equations_solver_cache(semi) | ||
@unpack glm_scale, cfl = glm_speed_callback | ||
|
||
# compute time step for GLM linear advection equation with c_h=1 (redone due to the possible AMR) | ||
c_h_deltat = calc_dt_for_cleaning_speed(cfl, mesh, equations, solver, cache) | ||
|
||
# c_h is proportional to its own time step divided by the complete MHD time step | ||
equations.c_h = glm_scale * c_h_deltat / dt | ||
|
||
return nothing | ||
end | ||
|
||
include("glm_speed_dg.jl") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
function calc_dt_for_cleaning_speed(cfl::Real, mesh, | ||
equations::AbstractIdealGlmMhdEquations, dg::DG, cache) | ||
# compute time step for GLM linear advection equation with c_h=1 for the DG discretization on | ||
# Cartesian meshes | ||
max_scaled_speed_for_c_h = maximum(cache.elements.inverse_jacobian) * ndims(equations) | ||
# OBS! This depends on the implementation details of the StepsizeCallback and needs to be adapted | ||
# as well if that callback changes. | ||
return cfl * 2 / (nnodes(dg) * max_scaled_speed_for_c_h) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.