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

Sc/compressible euler multicomponent 2d fluxes #1681

Merged
merged 43 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
bb07419
Added coupling converters.
SimonCan Jun 26, 2023
95892bf
Added generic converter_function for structured 2d meshes.
SimonCan Jun 29, 2023
e4f3a2b
Merge branch 'main' of github.com:trixi-framework/Trixi.jl
SimonCan Aug 8, 2023
b2ffe2c
Merge branch 'main' of github.com:trixi-framework/Trixi.jl
SimonCan Aug 10, 2023
53e38ad
Merge branch 'main' of github.com:trixi-framework/Trixi.jl
SimonCan Aug 16, 2023
36380cd
Merge branch 'main' of github.com:trixi-framework/Trixi.jl
SimonCan Sep 22, 2023
b754ea2
Merge branch 'main' of github.com:trixi-framework/Trixi.jl
SimonCan Oct 4, 2023
d3453db
Merge branch 'main' of github.com:trixi-framework/Trixi.jl
SimonCan Oct 19, 2023
a4e841a
Added fluxes to 2d compressible multicomponent Euler.
SimonCan Oct 20, 2023
2b31702
Removed backup file.
SimonCan Oct 20, 2023
7125ca0
Removed redundant project toml file.
SimonCan Oct 20, 2023
2180dde
Removed redundant Project toml file.
SimonCan Oct 20, 2023
8e185e7
Removed redundant project toml file.
SimonCan Oct 20, 2023
5adfed0
Removed redundant project toml files.
SimonCan Oct 20, 2023
2816700
Removed rdundant files.
SimonCan Nov 9, 2023
5a8c203
Removed p4est coupling test elixir.
SimonCan Nov 9, 2023
6e95dab
Removed coupling converter functions.
SimonCan Nov 9, 2023
368ca9a
Removed further coupling converter functions.
SimonCan Nov 9, 2023
9656d8b
Removed redundant swap file.
SimonCan Nov 9, 2023
134917d
Reverted coupling semidiscretization to the main branch's by hand.
SimonCan Nov 9, 2023
19dd867
Added example elixir for the multicomponent Euler equations on struct…
SimonCan Nov 10, 2023
f9228d8
Added test for structured 2d Euler multicomponent elixir.
SimonCan Nov 10, 2023
9554737
Reduced resolution of Euler multicomponent elixir to reduce compute t…
SimonCan Nov 10, 2023
60b86bd
Merge branch 'main' into sc/compressible_euler_multicomponent_2d_fluxes
SimonCan Nov 10, 2023
e95e8a4
Applied autoformatter on multicomponent Euler.
SimonCan Nov 13, 2023
0789d27
Merge branch 'main' into sc/compressible_euler_multicomponent_2d_fluxes
SimonCan Nov 13, 2023
54c0b82
Autoformatter on test.
SimonCan Nov 13, 2023
9b360e1
Merge branch 'sc/compressible_euler_multicomponent_2d_fluxes' of gith…
SimonCan Nov 13, 2023
0f4c1a9
Update src/equations/compressible_euler_multicomponent_2d.jl
SimonCan Nov 15, 2023
a8f555e
Added checks for type instability for the structured mesh multicompon…
SimonCan Nov 15, 2023
b39c0b4
Autoformatted structured 2d test.
SimonCan Nov 15, 2023
8f7fc0a
Added consistency check for new multicomponent Euler fluxes.
SimonCan Nov 16, 2023
3be8101
Added rotational invariance test for CompressibleEulerMulticomponentE…
SimonCan Nov 16, 2023
fb9692c
Added rotations.
SimonCan Nov 16, 2023
e2fcd35
Added rotated surface for fluxes with only one u-vector.
SimonCan Nov 16, 2023
16507a5
Corrected type instability in rotation.
SimonCan Nov 17, 2023
08637af
Applied autoformatter on 2d multicomponent Euler equations.
SimonCan Nov 20, 2023
717ca6e
Merge branch 'main' into sc/compressible_euler_multicomponent_2d_fluxes
SimonCan Nov 20, 2023
fa541fc
Removed redundant speed functions from multicomponent Euler equations.
SimonCan Nov 20, 2023
465f790
Merge branch 'sc/compressible_euler_multicomponent_2d_fluxes' of gith…
SimonCan Nov 20, 2023
907247b
Applied autoformatter on unit test.
SimonCan Nov 20, 2023
d4fcbd6
Merge branch 'main' into sc/compressible_euler_multicomponent_2d_fluxes
ranocha Nov 21, 2023
77a4c4b
Merge branch 'main' into sc/compressible_euler_multicomponent_2d_fluxes
SimonCan Nov 21, 2023
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
55 changes: 55 additions & 0 deletions examples/structured_2d_dgsem/elixir_eulermulti_convergence_ec.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

using OrdinaryDiffEq
using Trixi

###############################################################################
# semidiscretization of the compressible Euler multicomponent equations
equations = CompressibleEulerMulticomponentEquations2D(gammas = (1.4, 1.4),
gas_constants = (0.4, 0.4))

initial_condition = initial_condition_convergence_test

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

cells_per_dimension = (16, 16)
coordinates_min = (-1.0, -1.0)
coordinates_max = (1.0, 1.0)
mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max)

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

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

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

summary_callback = SummaryCallback()

analysis_interval = 100
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)

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.5)

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
175 changes: 175 additions & 0 deletions src/equations/compressible_euler_multicomponent_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,29 @@ end
return vcat(f_other, f_rho)
end

# Calculate 1D flux for a single point
@inline function flux(u, normal_direction::AbstractVector,
equations::CompressibleEulerMulticomponentEquations2D)
rho_v1, rho_v2, rho_e = u

rho = density(u, equations)

v1 = rho_v1 / rho
v2 = rho_v2 / rho
v_normal = v1 * normal_direction[1] + v2 * normal_direction[2]
gamma = totalgamma(u, equations)
p = (gamma - 1) * (rho_e - 0.5 * rho * (v1^2 + v2^2))

f_rho = densities(u, v_normal, equations)
f1 = rho_v1 * v_normal + p * normal_direction[1]
f2 = rho_v2 * v_normal + p * normal_direction[2]
f3 = (rho_e + p) * v_normal

f_other = SVector{3, real(equations)}(f1, f2, f3)

return vcat(f_other, f_rho)
end

"""
flux_chandrashekar(u_ll, u_rr, orientation, equations::CompressibleEulerMulticomponentEquations2D)

Expand Down Expand Up @@ -446,6 +469,76 @@ See also
return vcat(f_other, f_rho)
end

@inline function flux_ranocha(u_ll, u_rr, normal_direction::AbstractVector,
equations::CompressibleEulerMulticomponentEquations2D)
# Unpack left and right state
@unpack gammas, gas_constants, cv = equations
rho_v1_ll, rho_v2_ll, rho_e_ll = u_ll
rho_v1_rr, rho_v2_rr, rho_e_rr = u_rr
rhok_mean = SVector{ncomponents(equations), real(equations)}(ln_mean(u_ll[i + 3],
u_rr[i + 3])
for i in eachcomponent(equations))
rhok_avg = SVector{ncomponents(equations), real(equations)}(0.5 * (u_ll[i + 3] +
u_rr[i + 3])
for i in eachcomponent(equations))

# Iterating over all partial densities
rho_ll = density(u_ll, equations)
rho_rr = density(u_rr, equations)

# Calculating gamma
gamma = totalgamma(0.5 * (u_ll + u_rr), equations)
inv_gamma_minus_one = 1 / (gamma - 1)

# extract velocities
v1_ll = rho_v1_ll / rho_ll
v1_rr = rho_v1_rr / rho_rr
v1_avg = 0.5 * (v1_ll + v1_rr)
v2_ll = rho_v2_ll / rho_ll
v2_rr = rho_v2_rr / rho_rr
v2_avg = 0.5 * (v2_ll + v2_rr)
velocity_square_avg = 0.5 * (v1_ll * v1_rr + v2_ll * v2_rr)
v_dot_n_ll = v1_ll * normal_direction[1] + v2_ll * normal_direction[2]
v_dot_n_rr = v1_rr * normal_direction[1] + v2_rr * normal_direction[2]

# helpful variables
help1_ll = zero(v1_ll)
help1_rr = zero(v1_rr)
enth_ll = zero(v1_ll)
enth_rr = zero(v1_rr)
for i in eachcomponent(equations)
enth_ll += u_ll[i + 3] * gas_constants[i]
enth_rr += u_rr[i + 3] * gas_constants[i]
help1_ll += u_ll[i + 3] * cv[i]
help1_rr += u_rr[i + 3] * cv[i]
end

# temperature and pressure
T_ll = (rho_e_ll - 0.5 * rho_ll * (v1_ll^2 + v2_ll^2)) / help1_ll
T_rr = (rho_e_rr - 0.5 * rho_rr * (v1_rr^2 + v2_rr^2)) / help1_rr
p_ll = T_ll * enth_ll
p_rr = T_rr * enth_rr
p_avg = 0.5 * (p_ll + p_rr)
inv_rho_p_mean = p_ll * p_rr * inv_ln_mean(rho_ll * p_rr, rho_rr * p_ll)

f_rho_sum = zero(T_rr)
f_rho = SVector{ncomponents(equations), real(equations)}(rhok_mean[i] * 0.5 *
(v_dot_n_ll + v_dot_n_rr)
for i in eachcomponent(equations))
for i in eachcomponent(equations)
f_rho_sum += f_rho[i]
end
f1 = f_rho_sum * v1_avg + p_avg * normal_direction[1]
f2 = f_rho_sum * v2_avg + p_avg * normal_direction[2]
f3 = f_rho_sum * (velocity_square_avg + inv_rho_p_mean * inv_gamma_minus_one) +
0.5 * (p_ll * v_dot_n_rr + p_rr * v_dot_n_ll)

# momentum and energy flux
f_other = SVector{3, real(equations)}(f1, f2, f3)
SimonCan marked this conversation as resolved.
Show resolved Hide resolved

return vcat(f_other, f_rho)
end

# Calculate maximum wave speed for local Lax-Friedrichs-type dissipation
@inline function max_abs_speed_naive(u_ll, u_rr, orientation::Integer,
equations::CompressibleEulerMulticomponentEquations2D)
Expand Down Expand Up @@ -476,6 +569,32 @@ end
λ_max = max(abs(v_ll), abs(v_rr)) + max(c_ll, c_rr)
end

@inline function max_abs_speed_naive(u_ll, u_rr, normal_direction::AbstractVector,
equations::CompressibleEulerMulticomponentEquations2D)
rho_v1_ll, rho_v2_ll, rho_e_ll = u_ll
rho_v1_rr, rho_v2_rr, rho_e_rr = u_rr

# Get the density and gas gamma
rho_ll = density(u_ll, equations)
rho_rr = density(u_rr, equations)
gamma_ll = totalgamma(u_ll, equations)
gamma_rr = totalgamma(u_rr, equations)

# Get the velocities based on direction
v_ll = rho_v1_ll / rho_ll * normal_direction[1] +
rho_v1_ll / rho_ll * normal_direction[2]
v_rr = rho_v1_rr / rho_rr * normal_direction[1] +
rho_v1_rr / rho_rr * normal_direction[2]

# Compute the sound speeds on the left and right
p_ll = (gamma_ll - 1) * (rho_e_ll - 1 / 2 * (rho_v1_ll^2 + rho_v2_ll^2) / rho_ll)
c_ll = sqrt(gamma_ll * p_ll / rho_ll)
p_rr = (gamma_rr - 1) * (rho_e_rr - 1 / 2 * (rho_v1_rr^2 + rho_v2_rr^2) / rho_rr)
c_rr = sqrt(gamma_rr * p_rr / rho_rr)

λ_max = max(abs(v_ll), abs(v_rr)) + max(c_ll, c_rr)
end

@inline function max_abs_speeds(u,
equations::CompressibleEulerMulticomponentEquations2D)
rho_v1, rho_v2, rho_e = u
Expand All @@ -491,6 +610,62 @@ end
return (abs(v1) + c, abs(v2) + c)
end

@inline function min_max_speed_naive(u_ll, u_rr, orientation::Integer,
equations::CompressibleEulerMulticomponentEquations2D)
rho_v1_ll, rho_v2_ll, rho_e_ll = u_ll
rho_v1_rr, rho_v2_rr, rho_e_rr = u_rr

rho_ll = density(u_ll, equations)
rho_rr = density(u_rr, equations)

v1_ll = rho_v1_ll / rho_ll
v2_ll = rho_v2_ll / rho_ll
v1_rr = rho_v1_rr / rho_rr
v2_rr = rho_v2_rr / rho_rr

gamma = totalgamma(u_ll, equations)
p_ll = (gamma - 1) * (rho_e_ll - 1 / 2 * rho_ll * (v1_ll^2 + v2_ll^2))
p_rr = (gamma - 1) * (rho_e_rr - 1 / 2 * rho_rr * (v1_rr^2 + v2_rr^2))

if orientation == 1 # x-direction
λ_min = v1_ll - sqrt(gamma * p_ll / rho_ll)
λ_max = v1_rr + sqrt(gamma * p_rr / rho_rr)
else # y-direction
λ_min = v2_ll - sqrt(gamma * p_ll / rho_ll)
λ_max = v2_rr + sqrt(gamma * p_rr / rho_rr)
end

return λ_min, λ_max
end

@inline function min_max_speed_naive(u_ll, u_rr, normal_direction::AbstractVector,
equations::CompressibleEulerMulticomponentEquations2D)
rho_v1_ll, rho_v2_ll, rho_e_ll = u_ll
rho_v1_rr, rho_v2_rr, rho_e_rr = u_rr

rho_ll = density(u_ll, equations)
rho_rr = density(u_rr, equations)

v1_ll = rho_v1_ll / rho_ll
v2_ll = rho_v2_ll / rho_ll
v1_rr = rho_v1_rr / rho_rr
v2_rr = rho_v2_rr / rho_rr

gamma = totalgamma(u_ll, equations)
p_ll = (gamma - 1) * (rho_e_ll - 1 / 2 * rho_ll * (v1_ll^2 + v2_ll^2))
p_rr = (gamma - 1) * (rho_e_rr - 1 / 2 * rho_rr * (v1_rr^2 + v2_rr^2))

v_normal_ll = v1_ll * normal_direction[1] + v2_ll * normal_direction[2]
v_normal_rr = v1_rr * normal_direction[1] + v2_rr * normal_direction[2]

norm_ = norm(normal_direction)
# The v_normals are already scaled by the norm
λ_min = v_normal_ll - sqrt(gamma * p_ll / rho_ll) * norm_
λ_max = v_normal_rr + sqrt(gamma * p_rr / rho_rr) * norm_

return λ_min, λ_max
end

# Convert conservative variables to primitive
@inline function cons2prim(u, equations::CompressibleEulerMulticomponentEquations2D)
rho_v1, rho_v2, rho_e = u
Expand Down
18 changes: 18 additions & 0 deletions test/test_structured_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,24 @@ end
end
end

@trixi_testset "elixir_eulermulti_convergence_ec.jl" begin
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_eulermulti_convergence_ec.jl"),
l2=[
1.5123651627525257e-5,
1.51236516273878e-5,
2.4544918394022538e-5,
5.904791661362391e-6,
1.1809583322724782e-5,
],
linf=[
8.393471747591974e-5,
8.393471748258108e-5,
0.00015028562494778797,
3.504466610437795e-5,
7.00893322087559e-5,
])
SimonCan marked this conversation as resolved.
Show resolved Hide resolved
end

@trixi_testset "elixir_euler_source_terms.jl" begin
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_source_terms.jl"),
# Expected errors are exactly the same as with TreeMesh!
Expand Down