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

Add 2D multi-ion GLM-MHD equations for the TreeMesh solver #2196

Merged
merged 27 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fef17d2
Added 2D GLM-MHD equations, examples and tests
amrueda Dec 9, 2024
76eaaf8
Remove ES test
amrueda Dec 10, 2024
0b17871
Compatibility for single precision
amrueda Dec 10, 2024
42dbc96
Changed initial condition back to double precision
amrueda Dec 10, 2024
c6fd5f3
Merge branch 'main' into arr/multi-ion_mhd_2d
amrueda Dec 10, 2024
8919821
Update reference to Hennemann et al.
amrueda Dec 10, 2024
feac4b8
Replaced all occurrences of 2.0f0 and 4.0f0 with 2 and 4
amrueda Dec 10, 2024
2d8c833
Use a single elixir to test EC and EC+LLF
amrueda Dec 10, 2024
ffaf52f
Removed duplicated code in the outer constructor for @reset
amrueda Dec 10, 2024
7cc8dc9
Renamed AbstractIdealMhdMultiIonEquations to AbstractIdealGlmMhdMulti…
amrueda Dec 10, 2024
5f3d46c
GLM callback dispatches on AbstractIdealGlmMhdMultiIonEquations
amrueda Dec 10, 2024
5e7bed5
Moved routines that will be used by all AbstractIdealGlmMhdMultiIonEq…
amrueda Dec 10, 2024
be72d8d
Apply suggestions from code review
amrueda Dec 11, 2024
ad1509a
Apply suggestions from code review
amrueda Dec 11, 2024
6e68caf
Added appropriate formatting to admonitions in docstrings
amrueda Dec 11, 2024
f16b80f
Apply suggestions from code review
amrueda Dec 11, 2024
f3a3e7d
Make multi-ion GLM-MHD's initial condition initial_condition_weak_bla…
amrueda Dec 11, 2024
ee33ce1
Replaced divisions with multiplications
amrueda Dec 11, 2024
249ccf7
Merge branch 'main' into arr/multi-ion_mhd_2d
amrueda Dec 11, 2024
3411e3c
Changed code order...
amrueda Dec 11, 2024
2fbc1d7
Unexport get_component
amrueda Dec 11, 2024
373aab0
Replace division with multiplication
amrueda Dec 11, 2024
79b0e29
Added unit tests for type stability
amrueda Dec 11, 2024
b8e4a29
Added experimental admonitions
amrueda Dec 11, 2024
d31d5f9
Merge branch 'main' into arr/multi-ion_mhd_2d
ranocha Dec 11, 2024
5909d0f
Update src/equations/ideal_glm_mhd_multiion_2d.jl
ranocha Dec 11, 2024
d26713e
Apply suggestions from code review
sloede Dec 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions examples/tree_2d_dgsem/elixir_mhdmultiion_ec.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

using OrdinaryDiffEq
using Trixi

###############################################################################
# semidiscretization of the ideal multi-ion MHD equations
equations = IdealGlmMhdMultiIonEquations2D(gammas = (1.4, 1.667),
sloede marked this conversation as resolved.
Show resolved Hide resolved
charge_to_mass = (1.0, 2.0))

initial_condition = initial_condition_weak_blast_wave

volume_flux = (flux_ruedaramirez_etal, flux_nonconservative_ruedaramirez_etal)
surface_flux = (flux_ruedaramirez_etal, flux_nonconservative_ruedaramirez_etal)
solver = DGSEM(polydeg = 3, surface_flux = surface_flux,
volume_integral = VolumeIntegralFluxDifferencing(volume_flux))

coordinates_min = (-2.0, -2.0)
coordinates_max = (2.0, 2.0)
mesh = TreeMesh(coordinates_min, coordinates_max,
initial_refinement_level = 4,
n_cells_max = 10_000)

semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
source_terms = source_terms_lorentz)

###############################################################################
# ODE solvers, callbacks etc.

tspan = (0.0, 0.4)
ode = semidiscretize(semi, tspan)

summary_callback = SummaryCallback()

analysis_interval = 10
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
alive_callback = AliveCallback(analysis_interval = analysis_interval)

save_solution = SaveSolutionCallback(dt = 0.1, # interval=100,
save_initial_solution = true,
save_final_solution = true,
solution_variables = cons2prim)

cfl = 0.5

stepsize_callback = StepsizeCallback(cfl = cfl)

glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)

callbacks = CallbackSet(summary_callback,
analysis_callback, alive_callback,
save_solution,
stepsize_callback,
glm_speed_callback)

###############################################################################
# run the simulation

sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary
8 changes: 6 additions & 2 deletions src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export AcousticPerturbationEquations2D,
CompressibleEulerEquationsQuasi1D,
IdealGlmMhdEquations1D, IdealGlmMhdEquations2D, IdealGlmMhdEquations3D,
IdealGlmMhdMulticomponentEquations1D, IdealGlmMhdMulticomponentEquations2D,
IdealGlmMhdMultiIonEquations2D,
HyperbolicDiffusionEquations1D, HyperbolicDiffusionEquations2D,
HyperbolicDiffusionEquations3D,
LinearScalarAdvectionEquation1D, LinearScalarAdvectionEquation2D,
Expand All @@ -179,6 +180,8 @@ export flux, flux_central, flux_lax_friedrichs, flux_hll, flux_hllc, flux_hlle,
flux_godunov,
flux_chandrashekar, flux_ranocha, flux_derigs_etal, flux_hindenlang_gassner,
flux_nonconservative_powell, flux_nonconservative_powell_local_symmetric,
flux_ruedaramirez_etal, flux_nonconservative_ruedaramirez_etal,
flux_nonconservative_central,
flux_kennedy_gruber, flux_shima_etal, flux_ec,
flux_fjordholm_etal, flux_nonconservative_fjordholm_etal,
flux_wintermeyer_etal, flux_nonconservative_wintermeyer_etal,
Expand Down Expand Up @@ -212,7 +215,8 @@ export boundary_condition_do_nothing,
BoundaryConditionNavierStokesWall, NoSlip, Adiabatic, Isothermal,
BoundaryConditionCoupled

export initial_condition_convergence_test, source_terms_convergence_test
export initial_condition_convergence_test, source_terms_convergence_test,
source_terms_lorentz
export source_terms_harmonic
export initial_condition_poisson_nonperiodic, source_terms_poisson_nonperiodic,
boundary_condition_poisson_nonperiodic
Expand All @@ -225,7 +229,7 @@ export density, pressure, density_pressure, velocity, global_mean_vars,
equilibrium_distribution, waterheight_pressure
export entropy, energy_total, energy_kinetic, energy_internal, energy_magnetic,
cross_helicity,
enstrophy
enstrophy, magnetic_field, divergence_cleaning_field
export lake_at_rest_error
export ncomponents, eachcomponent

Expand Down
3 changes: 2 additions & 1 deletion src/callbacks_step/glm_speed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
GlmSpeedCallback(; glm_scale=0.5, cfl, semi_indices=())

Update the divergence cleaning wave speed `c_h` according to the time step
computed in [`StepsizeCallback`](@ref) for the ideal GLM-MHD equations.
computed in [`StepsizeCallback`](@ref) for the ideal GLM-MHD equations, the multi-component
GLM-MHD equations, and the multi-ion 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`
Expand Down
6 changes: 4 additions & 2 deletions src/callbacks_step/glm_speed_dg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

function calc_dt_for_cleaning_speed(cfl::Real, mesh,
equations::Union{AbstractIdealGlmMhdEquations,
AbstractIdealGlmMhdMulticomponentEquations},
AbstractIdealGlmMhdMulticomponentEquations,
AbstractIdealGlmMhdMultiIonEquations},
dg::DG, cache)
# compute time step for GLM linear advection equation with c_h=1 for the DG discretization on
# Cartesian meshes
Expand All @@ -28,7 +29,8 @@ end

function calc_dt_for_cleaning_speed(cfl::Real, mesh,
equations::Union{AbstractIdealGlmMhdEquations,
AbstractIdealGlmMhdMulticomponentEquations},
AbstractIdealGlmMhdMulticomponentEquations,
AbstractIdealGlmMhdMultiIonEquations},
dg::DGMulti, cache)
rd = dg.basis
md = mesh.md
Expand Down
27 changes: 27 additions & 0 deletions src/equations/equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,12 @@ abstract type AbstractIdealGlmMhdMulticomponentEquations{NDIMS, NVARS, NCOMP} <:
include("ideal_glm_mhd_multicomponent_1d.jl")
include("ideal_glm_mhd_multicomponent_2d.jl")

# IdealMhdMultiIonEquations
abstract type AbstractIdealGlmMhdMultiIonEquations{NDIMS, NVARS, NCOMP} <:
AbstractEquations{NDIMS, NVARS} end
include("ideal_glm_mhd_multiion.jl")
include("ideal_glm_mhd_multiion_2d.jl")

# Retrieve number of components from equation instance for the multicomponent case
@inline function ncomponents(::AbstractIdealGlmMhdMulticomponentEquations{NDIMS, NVARS,
NCOMP}) where {
Expand All @@ -511,6 +517,27 @@ In particular, not the components themselves are returned.
Base.OneTo(ncomponents(equations))
end

# Retrieve number of components from equation instance for the multi-ion case
@inline function ncomponents(::AbstractIdealGlmMhdMultiIonEquations{NDIMS, NVARS,
NCOMP}) where {
NDIMS,
NVARS,
NCOMP
}
NCOMP
end

"""
eachcomponent(equations::AbstractIdealGlmMhdMultiIonEquations)

Return an iterator over the indices that specify the location in relevant data structures
for the components in `AbstractIdealGlmMhdMultiIonEquations`.
In particular, not the components themselves are returned.
"""
@inline function eachcomponent(equations::AbstractIdealGlmMhdMultiIonEquations)
Base.OneTo(ncomponents(equations))
end

# Diffusion equation: first order hyperbolic system
abstract type AbstractHyperbolicDiffusionEquations{NDIMS, NVARS} <:
AbstractEquations{NDIMS, NVARS} end
Expand Down
Loading
Loading