Skip to content

Commit

Permalink
Merge branch 'main' into msl/structuredmesh-view
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCan authored Nov 20, 2023
2 parents 548348c + 1635d31 commit 125ee34
Show file tree
Hide file tree
Showing 30 changed files with 639 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Trixi"
uuid = "a7f1ee26-1774-49b1-8366-f1abc58fbfcb"
authors = ["Michael Schlottke-Lakemper <[email protected]>", "Gregor Gassner <[email protected]>", "Hendrik Ranocha <[email protected]>", "Andrew R. Winters <[email protected]>", "Jesse Chan <[email protected]>"]
version = "0.6.1-pre"
version = "0.6.2-pre"

[deps]
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
Expand Down
2 changes: 1 addition & 1 deletion examples/p4est_2d_dgsem/elixir_advection_restart.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ save_solution.condition.save_initial_solution = false

integrator = init(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = dt, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
save_everystep = false, callback = callbacks, maxiters = 100_000);

# Get the last time index and work with that.
load_timestep!(integrator, restart_filename)
Expand Down
2 changes: 1 addition & 1 deletion examples/p4est_3d_dgsem/elixir_advection_restart.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ save_solution.condition.save_initial_solution = false

integrator = init(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = dt, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
save_everystep = false, callback = callbacks, maxiters = 100_000);

# Get the last time index and work with that.
load_timestep!(integrator, restart_filename)
Expand Down
2 changes: 1 addition & 1 deletion examples/structured_2d_dgsem/elixir_advection_restart.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ save_solution.condition.save_initial_solution = false

integrator = init(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = dt, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
save_everystep = false, callback = callbacks, maxiters = 100_000);

# Get the last time index and work with that.
load_timestep!(integrator, restart_filename)
Expand Down
2 changes: 1 addition & 1 deletion examples/structured_3d_dgsem/elixir_advection_restart.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ save_solution.condition.save_initial_solution = false

integrator = init(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = dt, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
save_everystep = false, callback = callbacks, maxiters = 100_000);

# Get the last time index and work with that.
load_timestep!(integrator, restart_filename)
Expand Down
2 changes: 1 addition & 1 deletion examples/tree_2d_dgsem/elixir_advection_restart.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ save_solution.condition.save_initial_solution = false

integrator = init(ode, alg,
dt = dt, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks; ode_default_options()...)
callback = callbacks, maxiters = 100_000; ode_default_options()...)

# Load saved context for adaptive time integrator
if integrator.opts.adaptive
Expand Down
63 changes: 63 additions & 0 deletions examples/tree_2d_dgsem/elixir_eulerpolytropic_convergence.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

using OrdinaryDiffEq
using Trixi

###############################################################################
# semidiscretization of the polytropic Euler equations

gamma = 1.4
kappa = 0.5 # Scaling factor for the pressure.
equations = PolytropicEulerEquations2D(gamma, kappa)

initial_condition = initial_condition_convergence_test

volume_flux = flux_winters_etal
solver = DGSEM(polydeg = 3, surface_flux = FluxHLL(min_max_speed_davis),
volume_integral = VolumeIntegralFluxDifferencing(volume_flux))

coordinates_min = (0.0, 0.0)
coordinates_max = (1.0, 1.0)

# Create a uniformly refined mesh with periodic boundaries
mesh = TreeMesh(coordinates_min, coordinates_max,
initial_refinement_level = 2,
periodicity = true,
n_cells_max = 30_000)

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

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

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

summary_callback = SummaryCallback()

analysis_interval = 100
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
extra_analysis_errors = (:l2_error_primitive,
:linf_error_primitive))

alive_callback = AliveCallback(analysis_interval = analysis_interval)

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

stepsize_callback = StepsizeCallback(cfl = 0.1)

callbacks = CallbackSet(summary_callback,
analysis_callback, alive_callback,
save_solution,
stepsize_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
2 changes: 1 addition & 1 deletion examples/tree_3d_dgsem/elixir_advection_restart.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ save_solution.condition.save_initial_solution = false

integrator = init(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = dt, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
save_everystep = false, callback = callbacks, maxiters = 100_000);

# Get the last time index and work with that.
load_timestep!(integrator, restart_filename)
Expand Down
2 changes: 1 addition & 1 deletion examples/unstructured_2d_dgsem/elixir_euler_restart.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ save_solution.condition.save_initial_solution = false

integrator = init(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = dt, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
save_everystep = false, callback = callbacks, maxiters = 100_000);

# Get the last time index and work with that.
load_timestep!(integrator, restart_filename)
Expand Down
47 changes: 37 additions & 10 deletions src/auxiliary/special_elixirs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ providing examples with sensible default values for users.
Before replacing assignments in `elixir`, the keyword argument `maxiters` is inserted
into calls to `solve` and `Trixi.solve` with it's default value used in the SciML ecosystem
for ODEs, see the "Miscellaneous" section of the
for ODEs, see the "Miscellaneous" section of the
[documentation](https://docs.sciml.ai/DiffEqDocs/stable/basics/common_solver_opts/).
# Examples
Expand All @@ -36,6 +36,16 @@ julia> redirect_stdout(devnull) do
```
"""
function trixi_include(mod::Module, elixir::AbstractString; kwargs...)
# Check that all kwargs exist as assignments
code = read(elixir, String)
expr = Meta.parse("begin \n$code \nend")
expr = insert_maxiters(expr)

for (key, val) in kwargs
# This will throw an error when `key` is not found
find_assignment(expr, key)
end

# Print information on potential wait time only in non-parallel case
if !mpi_isparallel()
@info "You just called `trixi_include`. Julia may now compile the code, please be patient."
Expand Down Expand Up @@ -243,19 +253,25 @@ end
function find_assignment(expr, destination)
# declare result to be able to assign to it in the closure
local result
found = false

# find explicit and keyword assignments
walkexpr(expr) do x
if x isa Expr
if (x.head === Symbol("=") || x.head === :kw) &&
x.args[1] === Symbol(destination)
result = x.args[2]
found = true
# dump(x)
end
end
return x
end

if !found
throw(ArgumentError("assignment `$destination` not found in expression"))
end

result
end

Expand All @@ -274,17 +290,28 @@ function extract_initial_resolution(elixir, kwargs)
return initial_refinement_level
end
catch e
if isa(e, UndefVarError)
# get cells_per_dimension from the elixir
cells_per_dimension = eval(find_assignment(expr, :cells_per_dimension))

if haskey(kwargs, :cells_per_dimension)
return kwargs[:cells_per_dimension]
else
return cells_per_dimension
# If `initial_refinement_level` is not found, we will get an `ArgumentError`
if isa(e, ArgumentError)
try
# get cells_per_dimension from the elixir
cells_per_dimension = eval(find_assignment(expr, :cells_per_dimension))

if haskey(kwargs, :cells_per_dimension)
return kwargs[:cells_per_dimension]
else
return cells_per_dimension
end
catch e2
# If `cells_per_dimension` is not found either
if isa(e2, ArgumentError)
throw(ArgumentError("`convergence_test` requires the elixir to define " *
"`initial_refinement_level` or `cells_per_dimension`"))
else
rethrow()
end
end
else
throw(e)
rethrow()
end
end
end
Expand Down
142 changes: 142 additions & 0 deletions src/equations/ideal_glm_mhd_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,148 @@ Hindenlang and Gassner (2019), extending [`flux_ranocha`](@ref) to the MHD equat
return SVector(f1, f2, f3, f4, f5, f6, f7, f8)
end

"""
flux_hllc(u_ll, u_rr, orientation, equations::IdealGlmMhdEquations1D)
- 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).
"""
function flux_hllc(u_ll, u_rr, orientation::Integer,
equations::IdealGlmMhdEquations1D)
# Unpack left and right states
rho_ll, v1_ll, v2_ll, v3_ll, p_ll, B1_ll, B2_ll, B3_ll = cons2prim(u_ll, equations)
rho_rr, v1_rr, v2_rr, v3_rr, p_rr, B1_rr, B2_rr, B3_rr = cons2prim(u_rr, equations)

# Conserved variables
rho_v1_ll = u_ll[2]
rho_v2_ll = u_ll[3]
rho_v3_ll = u_ll[4]

rho_v1_rr = u_rr[2]
rho_v2_rr = u_rr[3]
rho_v3_rr = u_rr[4]

# Obtain left and right fluxes
f_ll = flux(u_ll, orientation, equations)
f_rr = flux(u_rr, orientation, equations)

SsL, SsR = min_max_speed_naive(u_ll, u_rr, orientation, equations)
sMu_L = SsL - v1_ll
sMu_R = SsR - v1_rr
if SsL >= 0
f1 = f_ll[1]
f2 = f_ll[2]
f3 = f_ll[3]
f4 = f_ll[4]
f5 = f_ll[5]
f6 = f_ll[6]
f7 = f_ll[7]
f8 = f_ll[8]
elseif SsR <= 0
f1 = f_rr[1]
f2 = f_rr[2]
f3 = f_rr[3]
f4 = f_rr[4]
f5 = f_rr[5]
f6 = f_rr[6]
f7 = f_rr[7]
f8 = f_rr[8]
else
# Compute the "HLLC-speed", eq. (14) from paper mentioned above
#=
SStar = (rho_rr * v1_rr * sMu_R - rho_ll * v1_ll * sMu_L + p_ll - p_rr - B1_ll^2 + B1_rr^2 ) /
(rho_rr * sMu_R - rho_ll * sMu_L)
=#
# Simplification for 1D: B1 is constant
SStar = (rho_rr * v1_rr * sMu_R - rho_ll * v1_ll * sMu_L + p_ll - p_rr) /
(rho_rr * sMu_R - rho_ll * sMu_L)

Sdiff = SsR - SsL

# Compute HLL values for vStar, BStar
# These correspond to eq. (28) and (30) from the referenced paper
# and the classic HLL intermediate state given by (2)
rho_HLL = (SsR * rho_rr - SsL * rho_ll - (f_rr[1] - f_ll[1])) / Sdiff

v1Star = (SsR * rho_v1_rr - SsL * rho_v1_ll - (f_rr[2] - f_ll[2])) /
(Sdiff * rho_HLL)
v2Star = (SsR * rho_v2_rr - SsL * rho_v2_ll - (f_rr[3] - f_ll[3])) /
(Sdiff * rho_HLL)
v3Star = (SsR * rho_v3_rr - SsL * rho_v3_ll - (f_rr[4] - f_ll[4])) /
(Sdiff * rho_HLL)

#B1Star = (SsR * B1_rr - SsL * B1_ll - (f_rr[6] - f_ll[6])) / Sdiff
# 1D B1 = constant => B1_ll = B1_rr = B1Star
B1Star = B1_ll

B2Star = (SsR * B2_rr - SsL * B2_ll - (f_rr[7] - f_ll[7])) / Sdiff
B3Star = (SsR * B3_rr - SsL * B3_ll - (f_rr[8] - f_ll[8])) / Sdiff
if SsL <= SStar
SdiffStar = SsL - SStar

densStar = rho_ll * sMu_L / SdiffStar # (19)

mom_1_Star = densStar * SStar # (20)
mom_2_Star = densStar * v2_ll -
(B1Star * B2Star - B1_ll * B2_ll) / SdiffStar # (21)
mom_3_Star = densStar * v3_ll -
(B1Star * B3Star - B1_ll * B3_ll) / SdiffStar # (22)

#pstar = rho_ll * sMu_L * (SStar - v1_ll) + p_ll - B1_ll^2 + B1Star^2 # (17)
# 1D B1 = constant => B1_ll = B1_rr = B1Star
pstar = rho_ll * sMu_L * (SStar - v1_ll) + p_ll # (17)

enerStar = u_ll[5] * sMu_L / SdiffStar +
(pstar * SStar - p_ll * v1_ll - (B1Star *
(B1Star * v1Star + B2Star * v2Star + B3Star * v3Star) -
B1_ll * (B1_ll * v1_ll + B2_ll * v2_ll + B3_ll * v3_ll))) /
SdiffStar # (23)

# Classic HLLC update (32)
f1 = f_ll[1] + SsL * (densStar - u_ll[1])
f2 = f_ll[2] + SsL * (mom_1_Star - u_ll[2])
f3 = f_ll[3] + SsL * (mom_2_Star - u_ll[3])
f4 = f_ll[4] + SsL * (mom_3_Star - u_ll[4])
f5 = f_ll[5] + SsL * (enerStar - u_ll[5])
f6 = f_ll[6] + SsL * (B1Star - u_ll[6])
f7 = f_ll[7] + SsL * (B2Star - u_ll[7])
f8 = f_ll[8] + SsL * (B3Star - u_ll[8])
else # SStar <= Ssr
SdiffStar = SsR - SStar

densStar = rho_rr * sMu_R / SdiffStar # (19)

mom_1_Star = densStar * SStar # (20)
mom_2_Star = densStar * v2_rr -
(B1Star * B2Star - B1_rr * B2_rr) / SdiffStar # (21)
mom_3_Star = densStar * v3_rr -
(B1Star * B3Star - B1_rr * B3_rr) / SdiffStar # (22)

#pstar = rho_rr * sMu_R * (SStar - v1_rr) + p_rr - B1_rr^2 + B1Star^2 # (17)
# 1D B1 = constant => B1_ll = B1_rr = B1Star
pstar = rho_rr * sMu_R * (SStar - v1_rr) + p_rr # (17)

enerStar = u_rr[5] * sMu_R / SdiffStar +
(pstar * SStar - p_rr * v1_rr - (B1Star *
(B1Star * v1Star + B2Star * v2Star + B3Star * v3Star) -
B1_rr * (B1_rr * v1_rr + B2_rr * v2_rr + B3_rr * v3_rr))) /
SdiffStar # (23)

# Classic HLLC update (32)
f1 = f_rr[1] + SsR * (densStar - u_rr[1])
f2 = f_rr[2] + SsR * (mom_1_Star - u_rr[2])
f3 = f_rr[3] + SsR * (mom_2_Star - u_rr[3])
f4 = f_rr[4] + SsR * (mom_3_Star - u_rr[4])
f5 = f_rr[5] + SsR * (enerStar - u_rr[5])
f6 = f_rr[6] + SsR * (B1Star - u_rr[6])
f7 = f_rr[7] + SsR * (B2Star - u_rr[7])
f8 = f_rr[8] + SsR * (B3Star - u_rr[8])
end
end
return SVector(f1, f2, f3, f4, f5, f6, f7, f8)
end

# Calculate maximum wave speed for local Lax-Friedrichs-type dissipation
@inline function max_abs_speed_naive(u_ll, u_rr, orientation::Integer,
equations::IdealGlmMhdEquations1D)
Expand Down
Loading

0 comments on commit 125ee34

Please sign in to comment.