-
Couldn't load subscription status.
- Fork 131
Added abstract vector for max_abs_speed_naive and CompressibleEulerMulticomponentEquations2D. #2607
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
Open
SimonCan
wants to merge
27
commits into
main
Choose a base branch
from
sc/multi-euler-with-AbstractVector
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+178
−0
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
5d00548
Added n::AbstractVector version of max_abs_speed_naive for Compressib…
SimonCan 913558e
Renamed normal vector to be more consistent with the rest of the code.
SimonCan e7391f2
Merge branch 'main' into sc/multi-euler-with-AbstractVector
SimonCan 0695cdb
Added test for this PR.
SimonCan b4afe48
Added elixir for 2d multicomponent Euler using p4est meshes.
SimonCan b993bab
Update examples/p4est_2d_dgsem/elixir_eulermulti_convergence_ec.jl
SimonCan 36e35d3
Merge branch 'main' into sc/multi-euler-with-AbstractVector
SimonCan 60d7a8c
Changed the surface flux to flux_lax_friedrichs.
SimonCan c3c91a4
Merge branch 'main' into sc/multi-euler-with-AbstractVector
SimonCan 7da3ce3
Merge branch 'main' into sc/multi-euler-with-AbstractVector
SimonCan a76b0e9
Replaced example elixir with shock.
SimonCan 730956a
Replaced test for p4est euler multi.
SimonCan e606496
Update src/equations/compressible_euler_multicomponent_2d.jl
DanielDoehring 8e22d6b
Apply suggestions from code review
DanielDoehring 1793743
Update src/equations/compressible_euler_multicomponent_2d.jl
DanielDoehring 9b5a2e0
Apply suggestions from code review
DanielDoehring 756b340
Update src/equations/compressible_euler_multicomponent_2d.jl
DanielDoehring 86193b6
Update examples/p4est_2d_dgsem/elixir_eulermulti_shock.jl
SimonCan 932b393
Update examples/p4est_2d_dgsem/elixir_eulermulti_shock.jl
SimonCan 73973ec
Update examples/p4est_2d_dgsem/elixir_eulermulti_shock.jl
SimonCan 64715ff
Update examples/p4est_2d_dgsem/elixir_eulermulti_shock.jl
SimonCan f2316cf
Update examples/p4est_2d_dgsem/elixir_eulermulti_shock.jl
SimonCan 5a04141
Update examples/p4est_2d_dgsem/elixir_eulermulti_shock.jl
SimonCan 08ed1ae
Update examples/p4est_2d_dgsem/elixir_eulermulti_shock.jl
SimonCan f38d70d
Update examples/p4est_2d_dgsem/elixir_eulermulti_shock.jl
SimonCan 2e70745
Merge branch 'main' into sc/multi-euler-with-AbstractVector
SimonCan 1a1d7bc
More explicit types to avoid tpye instabilities.
SimonCan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,125 @@ | ||
| using OrdinaryDiffEqSSPRK, OrdinaryDiffEqLowStorageRK | ||
| using Trixi | ||
|
|
||
| # 1) Dry Air 2) SF_6 | ||
| equations = CompressibleEulerMulticomponentEquations2D(gammas = (1.4, 1.648), | ||
| gas_constants = (0.287, 1.578)) | ||
|
|
||
| """ | ||
| initial_condition_shock(coordinates, t, equations::CompressibleEulerEquations2D) | ||
|
|
||
| Shock traveling from left to right where it interacts with a Perturbed interface. | ||
| """ | ||
| @inline function initial_condition_shock(x, t, | ||
| equations::CompressibleEulerMulticomponentEquations2D) | ||
| rho_0 = 1.25 # kg/m^3 | ||
| p_0 = 101325 # Pa | ||
| T_0 = 293 # K | ||
| u_0 = 352 # m/s | ||
| d = 20 | ||
| w = 40 | ||
|
|
||
| if x[1] < 25 | ||
| # Shock region. | ||
| v1 = 0.35 | ||
| v2 = 0.0 | ||
| rho1 = 1.72 | ||
| rho2 = 0.03 | ||
| p = 1.57 | ||
| elseif (x[1] <= 30) || (x[1] <= 70 && abs(125 - x[2]) > w / 2) | ||
| # Intermediate region. | ||
| v1 = 0.0 | ||
| v2 = 0.0 | ||
| rho1 = 1.25 | ||
| rho2 = 0.03 | ||
| p = 1.0 | ||
| else | ||
| (x[1] <= 70 + d) | ||
| # SF_6 region. | ||
| v1 = 0.0 | ||
| v2 = 0.0 | ||
| rho1 = 0.03 | ||
| rho2 = 6.03 #SF_6 | ||
| p = 1.0 | ||
| end | ||
|
|
||
| return prim2cons(SVector(v1, v2, p, rho1, rho2), equations) | ||
| end | ||
|
|
||
| # Define the simulation. | ||
| initial_condition = initial_condition_shock | ||
|
|
||
| surface_flux = flux_lax_friedrichs | ||
| volume_flux = flux_ranocha | ||
| basis = LobattoLegendreBasis(3) | ||
|
|
||
| limiter_idp = SubcellLimiterIDP(equations, basis; | ||
| positivity_variables_cons = ["rho" * string(i) | ||
| for i in eachcomponent(equations)]) | ||
|
|
||
| volume_integral = VolumeIntegralSubcellLimiting(limiter_idp; | ||
| volume_flux_dg = volume_flux, | ||
| volume_flux_fv = surface_flux) | ||
|
|
||
| solver = DGSEM(basis, surface_flux, volume_integral) | ||
|
|
||
| coordinates_min = (0.0, 0.0) | ||
| coordinates_max = (250.0, 250.0) | ||
| mesh = P4estMesh((32, 32), polydeg = 3, coordinates_min = (0.0, 0.0), | ||
| coordinates_max = (250.0, 250.0), periodicity = (false, true), | ||
| initial_refinement_level = 0) | ||
|
|
||
| # Completely free outflow | ||
| function boundary_condition_outflow(u_inner, normal_direction::AbstractVector, | ||
| x, t, | ||
| surface_flux_function, | ||
| equations) | ||
| # Calculate the boundary flux entirely from the internal solution state | ||
| return flux(u_inner, normal_direction, equations) | ||
| end | ||
|
|
||
| boundary_conditions = Dict(:x_neg => BoundaryConditionDirichlet(initial_condition), | ||
| :x_pos => boundary_condition_outflow) | ||
|
|
||
| semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver, | ||
| boundary_conditions = boundary_conditions) | ||
|
|
||
| ############################################################################### | ||
| # ODE solvers, callbacks etc. | ||
|
|
||
| tspan = (0.0, 5.0) | ||
| ode = semidiscretize(semi, tspan) | ||
|
|
||
| summary_callback = SummaryCallback() | ||
|
|
||
| analysis_interval = 10 | ||
| analysis_callback = AnalysisCallback(semi, interval = analysis_interval, | ||
| save_analysis = true) | ||
|
|
||
| alive_callback = AliveCallback(analysis_interval = analysis_interval) | ||
|
|
||
| save_solution = SaveSolutionCallback(dt = 2.0, | ||
| save_initial_solution = true, | ||
| save_final_solution = true, | ||
| solution_variables = cons2prim) | ||
|
|
||
| stepsize_callback = StepsizeCallback(cfl = 0.2) | ||
|
|
||
| callbacks = CallbackSet(summary_callback, | ||
| analysis_callback, | ||
| alive_callback, | ||
| save_solution, | ||
| stepsize_callback) | ||
|
|
||
| ############################################################################### | ||
| # run the simulation | ||
|
|
||
| stage_callbacks = (SubcellLimiterIDPCorrection(), | ||
| BoundsCheckCallback(save_errors = false, interval = 100)) | ||
| # `interval` is used when calling this elixir in the tests with `save_errors=true`. | ||
|
|
||
| @time begin | ||
| sol = Trixi.solve(ode, Trixi.SimpleSSPRK33(stage_callbacks = stage_callbacks); | ||
| dt = 0.1, # solve needs some value here but it will be overwritten by the stepsize_callback | ||
| ode_default_options()..., callback = callbacks) | ||
| end | ||
This file contains hidden or 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 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -681,6 +681,38 @@ end | |||||||||||||||||||
| return max(abs(v_ll), abs(v_rr)) + max(c_ll, c_rr) | ||||||||||||||||||||
| end | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Calculate maximum wave speed for local Lax-Friedrichs-type dissipation | ||||||||||||||||||||
| @inline function max_abs_speed_naive(u_ll::SVector{N,T}, u_rr::SVector{N,T}, normal_direction::SVector{2,T}, | ||||||||||||||||||||
| equations::CompressibleEulerMulticomponentEquations2D) where {N, T<:AbstractFloat} | ||||||||||||||||||||
|
Comment on lines
+685
to
+686
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||
| # Unpack conservative variables | ||||||||||||||||||||
| rho_v1_ll, rho_v2_ll, rho_e_ll = u_ll | ||||||||||||||||||||
| rho_v1_rr, rho_v2_rr, rho_e_rr = u_rr | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Get densities and gammas | ||||||||||||||||||||
| rho_ll = T(density(u_ll, equations)) | ||||||||||||||||||||
| rho_rr = T(density(u_rr, equations)) | ||||||||||||||||||||
| gamma_ll = T(totalgamma(u_ll, equations)) | ||||||||||||||||||||
| gamma_rr = T(totalgamma(u_rr, equations)) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Velocity components | ||||||||||||||||||||
| v_ll_vec = SVector(rho_v1_ll / rho_ll, rho_v2_ll / rho_ll) | ||||||||||||||||||||
| v_rr_vec = SVector(rho_v1_rr / rho_rr, rho_v2_rr / rho_rr) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Project velocities onto the direction normal_direction. | ||||||||||||||||||||
| v_ll = dot(v_ll_vec, normal_direction) | ||||||||||||||||||||
| v_rr = dot(v_rr_vec, normal_direction) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Compute pressures | ||||||||||||||||||||
| p_ll = (gamma_ll - one(T)) * (rho_e_ll - T(0.5) * dot(v_ll_vec, v_ll_vec) * rho_ll) | ||||||||||||||||||||
| p_rr = (gamma_rr - one(T)) * (rho_e_rr - T(0.5) * dot(v_rr_vec, v_rr_vec) * rho_rr) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Sound speeds | ||||||||||||||||||||
| c_ll = sqrt(gamma_ll * p_ll / rho_ll) | ||||||||||||||||||||
| c_rr = sqrt(gamma_rr * p_rr / rho_rr) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return max(abs(v_ll), abs(v_rr)) + max(c_ll, c_rr) | ||||||||||||||||||||
| end | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Less "cautious", i.e., less overestimating `λ_max` compared to `max_abs_speed_naive` | ||||||||||||||||||||
| @inline function max_abs_speed(u_ll, u_rr, orientation::Integer, | ||||||||||||||||||||
| equations::CompressibleEulerMulticomponentEquations2D) | ||||||||||||||||||||
|
|
||||||||||||||||||||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you check this code for type instabilities? Do you get type instabilities with mainstream solvers like shock capturing Hennemann & Gassner?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 that is something you should check first
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would that not require a min_max_speed_davis? If so it might just shift the type instability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your new code looks reasonable. Thus, I guess the type instabilities come from this choice of solver. You can also profile it or use Cthulhu.jl to
@descendinto ourrhs!.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the type instability does not come from max_abs_speed_naive after all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strangely enough,
@btime Trixi.rhs!($du, $sol.u[1], $semi, 0.0)does not give me any extra memory allocations.