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

Hll 2 wave improvements #1545

Conversation

DanielDoehring
Copy link
Contributor

This addresses #1525 by providing implementations for the standard 2-wave HLL solver for SWE, MHD, CEE as well as the improved 2-wave HLL solver by Einfeldt using Roe averages for SWE.
For completeness, the naive 2-wave HLL solver is added also for MHD.

The motivation for this pull request is

  1. Increase consistency for SWE, MHD, CEE
  2. Provide the standard 2-Wave HLL as the default when calling flux_hll as one would expect

For illustration, the solution of the Sedov Blast wave is compared for the previously default min_max_speed_naive to the new default min_max_speed and flux_hllc.

min_max_speed_naive

min_max_speed_naive

min_max_speed

min_max_speed

flux_hllc

flux_hllc

@codecov
Copy link

codecov bot commented Jun 21, 2023

Codecov Report

Merging #1545 (f741306) into main (13b26a3) will decrease coverage by 0.03%.
The diff coverage is 93.75%.

@@            Coverage Diff             @@
##             main    #1545      +/-   ##
==========================================
- Coverage   96.04%   96.02%   -0.03%     
==========================================
  Files         368      369       +1     
  Lines       31049    31394     +345     
==========================================
+ Hits        29821    30144     +323     
- Misses       1228     1250      +22     
Flag Coverage Δ
unittests 96.02% <93.75%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
examples/dgmulti_2d/elixir_euler_bilinear.jl 100.00% <ø> (ø)
examples/dgmulti_2d/elixir_euler_curved.jl 100.00% <ø> (ø)
examples/dgmulti_2d/elixir_euler_weakform.jl 100.00% <ø> (ø)
examples/dgmulti_3d/elixir_euler_curved.jl 100.00% <ø> (ø)
examples/dgmulti_3d/elixir_euler_weakform.jl 100.00% <ø> (ø)
...t_3d_dgsem/elixir_mhd_alfven_wave_nonconforming.jl 100.00% <ø> (ø)
...ples/structured_3d_dgsem/elixir_mhd_alfven_wave.jl 100.00% <ø> (ø)
...ples/tree_1d_dgsem/elixir_mhd_briowu_shock_tube.jl 100.00% <ø> (ø)
...es/tree_1d_dgsem/elixir_mhd_ryujones_shock_tube.jl 100.00% <ø> (ø)
...s/tree_1d_dgsem/elixir_mhd_shu_osher_shock_tube.jl 100.00% <ø> (ø)
... and 12 more

@JoshuaLampert
Copy link
Member

JoshuaLampert commented Jun 21, 2023

I haven't thought this through, but I'm just curious. Would something like the following work? Since min_max_speed (and also max_abs_speeds ?) only depend on the eigenvalues of the flux-jacobian of the equations we could define a general function like

function min_max_speed(u_ll, u_rr, orientation::Integer, equations::AbstractEquations)
    λ_ll = eigenvalues(u_ll, orientation, equations)
    λ_rr = eigenvalues(u_rr, orientation, equations)
    λ_min = min(λ_ll)
    λ_max = max(λ_rr)
    return λ_min, λ_max
end

and define for each equation a function returning the eigenvalues, e.g.

function eigenvalues(u, orientation::Integer, equations::CompressibleEulerEquations1D)
    rho, v1, p = cons2prim(u, equations)

    c = sqrt(equations.gamma * p / rho)
    return v1 - c1, v1, v1 + c1
end

We probably need analogous definitions for min_max_speed(u_ll, u_rr, normal_direction::AbstractVector, equations::AbstractEquations) and eigenvalues(u, normal_direction::AbstractVector, equations::CompressibleEulerEquations1D).
For me, it would be more natural to provide the eigenvalues of a system than to provide a function min_max_speed when one wants to add a new equation since the eigenvalues are more equation-specific and, as far as I understand, at least for the "normal" equations like Euler or SWE, min_max_speed is generic. Maybe even some other functions that only depend on the eigenvalues could be defined generically? Or would this approach be too general and would not work for more sophisticated equations (IIRC @andrewwinters5000 mentioned that the eigenvalues are not known for the two-layer SWE for example)? For me, ideally, it should be necessary for the definition of an equation to provide the minimal set of functions conisting of flux, eigenvalues and maybe some conversion functions like prim2cons and cons2prim if needed. This should be enough to, at least have a working equation with the basic numerical fluxes like flux_lax_friedrichs or flux_hll, shouldn't it? If you have some more sophisticated estimates on the minimal and maximal speeds like Roe averages or if you have a more sophisticated definition for the HLL flux (like for SWE to avoid spurious oscillations in the bottom topography) you can of course provide them for the specific equation, but at least you have some general fallback.

@DanielDoehring
Copy link
Contributor Author

So for the classical HLL 2-Wave solver you would have

function min_max_speed(u_ll, u_rr, orientation::Integer, equations::AbstractEquations)
    λ_ll = eigenvalues(u_ll, orientation, equations)
    λ_rr = eigenvalues(u_rr, orientation, equations)
    λ_min = min(min(λ_ll), min(λ_rr))
    λ_max = max(max(λ_ll), max((λ_rr))
    return λ_min, λ_max
end

which is probably more expensive than the current implementations.
While I can see the elegance in the proposed implementation (especially for SWE and CEE) it is questionable whether this is well suited for e.g. MHD which comes (even in the 1D case) with 8 eigenvalues of which you in principle need only 2.

@JoshuaLampert
Copy link
Member

JoshuaLampert commented Jun 21, 2023

So for the classical HLL 2-Wave solver you would have

Yes.

Performance-wise you are probably right. Of course, I am totally fine if we don't implement this because of performance issues. I was just mainly curious if this would work in general.

Copy link
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your effort! This is quite a lot of stuff. It is helpful to break big changes like this down to several smaller PRs to speed up the review process.

src/equations/compressible_euler_1d.jl Outdated Show resolved Hide resolved
src/equations/numerical_fluxes.jl Outdated Show resolved Hide resolved
src/equations/numerical_fluxes.jl Outdated Show resolved Hide resolved
Copy link
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot! This is already in a good shape. However, it contains some breaking changes along with other implementations that can be useful right now. Thus, I would like to ask you to split this into two PRs.

  1. One PR can implement the purely new functionality. This will be not breaking and already a nice addition.
  2. Another PR can implement the breaking changes of the behavior for MHD.

When I drafted the interface of FluxHLL originally in another package in 217 or so, my version of what we call min_max_speed_naive in Trixi.jl was basically what you understand as min_max_speed_davis. I agree with you that this is probably one of the first things people may expect since it easy and already quite good. Thus, I wonder whether we really need the sometimes unexpected version of min_max_speed_naive in Trixi.jl or whether we should replace it by minmax_speed_davis in the long run. Any thoughts about this, @trixi-framework/principal-developers?

src/equations/compressible_euler_2d.jl Show resolved Hide resolved
src/equations/compressible_euler_3d.jl Show resolved Hide resolved
Comment on lines 316 to 327
"""
min_max_speed_naive(u_ll, u_rr, orientation, equations::IdealGlmMhdEquations1D)
min_max_speed_einfeldt(u_ll, u_rr, orientation::Integer, equations::IdealGlmMhdEquations1D)

Calculate minimum and maximum wave speeds for HLL-type fluxes as in
- Li (2005)
An HLLC Riemann solver for magneto-hydrodynamics
[DOI: 10.1016/j.jcp.2004.08.020](https://doi.org/10.1016/j.jcp.2004.08.020)
[DOI: 10.1016/j.jcp.2004.08.020](https://doi.org/10.1016/j.jcp.2004.08.020).
"""
@inline function min_max_speed_naive(u_ll, u_rr, orientation::Integer,
equations::IdealGlmMhdEquations1D)
@inline function min_max_speed_einfeldt(u_ll, u_rr, orientation::Integer,
equations::IdealGlmMhdEquations1D)
rho_ll, rho_v1_ll, _ = u_ll
rho_rr, rho_v1_rr, _ = u_rr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the part that I consider to be breaking since it changes the behavior we have so far quite a bit.

Comment on lines +280 to +294
# Calculate estimates for minimum and maximum wave speeds for HLL-type fluxes
@inline function min_max_speed_naive(u_ll, u_rr, orientation::Integer,
equations::IdealGlmMhdEquations1D)
rho_ll, rho_v1_ll, _ = u_ll
rho_rr, rho_v1_rr, _ = u_rr

# Calculate primitive variables
v1_ll = rho_v1_ll / rho_ll
v1_rr = rho_v1_rr / rho_rr

λ_min = v1_ll - calc_fast_wavespeed(u_ll, orientation, equations)
λ_max = v1_rr + calc_fast_wavespeed(u_rr, orientation, equations)

return λ_min, λ_max
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether we really need this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reason I added this is to have flux_hll working out of the box also for MHD.
But in principle, I agree with you that the naive estimate has probably no real advantage over the Davis estimate.

Comment on lines +146 to +155
# Calculate estimate for minimum and maximum wave speeds for HLL-type fluxes
@inline function min_max_speed_naive(u_ll, u_rr, orientation::Integer,
equations::LinearizedEulerEquations2D)
min_max_speed_davis(u_ll, u_rr, orientation, equations)
end

@inline function min_max_speed_naive(u_ll, u_rr, normal_direction::AbstractVector,
equations::LinearizedEulerEquations2D)
min_max_speed_davis(u_ll, u_rr, normal_direction, equations)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I would consider as default, too. Thus, I wonder whether we really need the current version of min_max_speed_naive or whether we should basically deprecate it in favor of min_max_speed_davis.

src/equations/shallow_water_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_2d.jl Outdated Show resolved Hide resolved
test/test_structured_1d.jl Show resolved Hide resolved
@DanielDoehring
Copy link
Contributor Author

Thanks a lot! This is already in a good shape. However, it contains some breaking changes along with other implementations that can be useful right now. Thus, I would like to ask you to split this into two PRs.

1. One PR can implement the purely new functionality. This will be not breaking and already a nice addition.

2. Another PR can implement the breaking changes of the behavior for MHD.

When I drafted the interface of FluxHLL originally in another package in 217 or so, my version of what we call min_max_speed_naive in Trixi.jl was basically what you understand as min_max_speed_davis. I agree with you that this is probably one of the first things people may expect since it easy and already quite good. Thus, I wonder whether we really need the sometimes unexpected version of min_max_speed_naive in Trixi.jl or whether we should replace it by minmax_speed_davis in the long run. Any thoughts about this, @trixi-framework/principal-developers?

I extraced the (hopefully) non-breaking part into #1561 and converted this to draft until we decide how we settle the naive vs davis debate.

@sloede
Copy link
Member

sloede commented Nov 4, 2023

With the upcoming breaking release of v0.6 coming up, is this PR still considered to be merged?

@DanielDoehring
Copy link
Contributor Author

@sloede The main motivation is still there: The naming of wave-speeds is not consistent among equations, most notably for MHD things are different from SWE and CEE.

@sloede
Copy link
Member

sloede commented Nov 4, 2023

OK. But is this PR in a shape that can be made ready to merge within the next, say, week?

@DanielDoehring
Copy link
Contributor Author

DanielDoehring commented Nov 4, 2023

Probably its easier to start over from main branch, but this should be possible within the next week.

@sloede
Copy link
Member

sloede commented Nov 4, 2023

OK. I'm not saying it has to be done though. But now would be the time for breaking changes 😄

@ranocha
Copy link
Member

ranocha commented Nov 6, 2023

Yes, that would be nice 👍

@DanielDoehring
Copy link
Contributor Author

The new PR is #1708

@ranocha ranocha mentioned this pull request Nov 10, 2023
8 tasks
@DanielDoehring DanielDoehring deleted the HLL_2_Wave_Improvements branch November 10, 2023 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants