Skip to content

Commit

Permalink
Add tests for alpha analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
bennibolm committed Oct 17, 2024
1 parent efeaca8 commit ea55b68
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,14 @@ save_solution = SaveSolutionCallback(interval = 300,

stepsize_callback = StepsizeCallback(cfl = 0.5)

limiting_analysis_callback = LimitingAnalysisCallback(output_directory = "out",
interval = 1)

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

###############################################################################
Expand Down
4 changes: 4 additions & 0 deletions examples/structured_2d_dgsem/elixir_euler_double_mach.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,13 @@ save_solution = SaveSolutionCallback(interval = 1000,

stepsize_callback = StepsizeCallback(cfl = 0.9)

limiting_analysis_callback = LimitingAnalysisCallback(output_directory = "out",
interval = 1)

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

###############################################################################
Expand Down
4 changes: 4 additions & 0 deletions examples/structured_2d_dgsem/elixir_euler_double_mach_MCL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,13 @@ save_solution = SaveSolutionCallback(interval = 1000,

stepsize_callback = StepsizeCallback(cfl = 0.9)

limiting_analysis_callback = LimitingAnalysisCallback(output_directory = "out",
interval = 1)

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

###############################################################################
Expand Down
4 changes: 4 additions & 0 deletions examples/tree_2d_dgsem/elixir_euler_blast_wave_MCL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ save_solution = SaveSolutionCallback(interval = 500,

stepsize_callback = StepsizeCallback(cfl = 0.9)

limiting_analysis_callback = LimitingAnalysisCallback(output_directory = "out",
interval = 1)

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

###############################################################################
Expand Down
8 changes: 5 additions & 3 deletions src/callbacks_step/limiting_analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ end
@unpack output_directory = limiting_analysis_callback
@unpack alpha = limiter.cache.subcell_limiter_coefficients

alpha_avg = analyze_coefficient_IDP(mesh, equations, dg, cache, limiter)
alpha_avg = analyze_coefficient(mesh, equations, dg, cache, limiter)

open("$output_directory/alphas.txt", "a") do f
println(f, iter, ", ", time, ", ", maximum(alpha), ", ", alpha_avg)
Expand All @@ -156,15 +156,17 @@ end
dg, cache,
limiter::SubcellLimiterMCL,
time, iter)
@assert limiter.Plotting "Parameter `Plotting` needs to be activated for analysis of limiting factor with `LimitingAnalysisCallback`"

@unpack output_directory = limiting_analysis_callback
@unpack weights = dg.basis
@unpack alpha, alpha_pressure, alpha_entropy,
alpha_mean, alpha_mean_pressure, alpha_mean_entropy = limiter.cache.subcell_limiter_coefficients

n_vars = nvariables(equations)

alpha_min_avg, alpha_mean_avg = analyze_coefficient_MCL(mesh, equations, dg, cache,
limiter)
alpha_min_avg, alpha_mean_avg = analyze_coefficient(mesh, equations, dg, cache,
limiter)

open("$output_directory/alphas_min.txt", "a") do f
print(f, iter, ", ", time)
Expand Down
15 changes: 10 additions & 5 deletions src/callbacks_step/limiting_analysis_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
@muladd begin
#! format: noindent

function analyze_coefficient_IDP(mesh::TreeMesh2D, equations, dg, cache, limiter)
function analyze_coefficient(mesh::TreeMesh2D, equations, dg, cache,
limiter::SubcellLimiterIDP)
@unpack weights = dg.basis
@unpack alpha = limiter.cache.subcell_limiter_coefficients

Expand All @@ -22,7 +23,9 @@ function analyze_coefficient_IDP(mesh::TreeMesh2D, equations, dg, cache, limiter
return alpha_avg / total_volume
end

function analyze_coefficient_IDP(mesh::StructuredMesh{2}, equations, dg, cache, limiter)
function analyze_coefficient(mesh::Union{StructuredMesh{2}, P4estMesh{2}},
equations, dg, cache,
limiter::SubcellLimiterIDP)
@unpack weights = dg.basis
@unpack alpha = limiter.cache.subcell_limiter_coefficients

Expand All @@ -39,7 +42,8 @@ function analyze_coefficient_IDP(mesh::StructuredMesh{2}, equations, dg, cache,
return alpha_avg / total_volume
end

function analyze_coefficient_MCL(mesh::TreeMesh2D, equations, dg, cache, limiter)
function analyze_coefficient(mesh::TreeMesh2D, equations, dg, cache,
limiter::SubcellLimiterMCL)
@unpack weights = dg.basis
@unpack alpha, alpha_mean, alpha_pressure,
alpha_mean_pressure, alpha_entropy, alpha_mean_entropy = limiter.cache.subcell_limiter_coefficients
Expand Down Expand Up @@ -83,8 +87,9 @@ function analyze_coefficient_MCL(mesh::TreeMesh2D, equations, dg, cache, limiter
return alpha_avg ./ total_volume, alpha_mean_avg ./ total_volume
end

function analyze_coefficient_MCL(mesh::StructuredMesh{2}, equations, dg, cache,
limiter)
function analyze_coefficient(mesh::Union{StructuredMesh{2}, P4estMesh{2}},
equations, dg, cache,
limiter::SubcellLimiterMCL)
@unpack weights = dg.basis
@unpack alpha, alpha_mean, alpha_pressure,
alpha_mean_pressure, alpha_entropy, alpha_mean_entropy = limiter.cache.subcell_limiter_coefficients
Expand Down
15 changes: 15 additions & 0 deletions test/test_p4est_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ end
end

@trixi_testset "elixir_euler_sedov_blast_wave_sc_subcell.jl" begin
rm(joinpath("out", "alphas.txt"), force = true)
@test_trixi_include(joinpath(EXAMPLES_DIR,
"elixir_euler_sedov_blast_wave_sc_subcell.jl"),
l2=[
Expand All @@ -350,6 +351,20 @@ end
6.268843623142863
],
tspan=(0.0, 0.3))
lines = readlines(joinpath("out", "alphas.txt"))
@test lines[1] ==
"# iter, simu_time, alpha_max, alpha_avg"
cmd = string(Base.julia_cmd())
coverage = occursin("--code-coverage", cmd) &&
!occursin("--code-coverage=none", cmd)
if coverage
# Run with coverage takes 6 time steps.
@test startswith(lines[end], "6, 0.005")
@test occursin(r"1.0, 0.968", lines[end])
else
# Run without coverage takes 128 time steps.
@test startswith(lines[end], "128, 0.1, 1.0, 0.902")
end
# Ensure that we do not have excessive memory allocations
# (e.g., from type instabilities)
let
Expand Down
43 changes: 43 additions & 0 deletions test/test_structured_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ end
end

@trixi_testset "elixir_euler_double_mach.jl" begin
rm(joinpath("out", "alphas.txt"), force = true)
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_double_mach.jl"),
l2=[
0.87417841433288,
Expand All @@ -734,6 +735,20 @@ end
],
initial_refinement_level=2,
tspan=(0.0, 0.05))
lines = readlines(joinpath("out", "alphas.txt"))
@test lines[1] ==
"# iter, simu_time, alpha_max, alpha_avg"
cmd = string(Base.julia_cmd())
coverage = occursin("--code-coverage", cmd) &&
!occursin("--code-coverage=none", cmd)
if coverage
# Run with coverage takes 1 time steps.
@test startswith(lines[end], "1, 0.0002")
@test occursin(r"1.0, 0.9809", lines[end])
else
# Run without coverage takes 193 time steps.
@test startswith(lines[end], "193, 0.05, 1.0, 0.3160")
end
# Ensure that we do not have excessive memory allocations
# (e.g., from type instabilities)
let
Expand All @@ -749,6 +764,8 @@ end
end

@trixi_testset "elixir_euler_double_mach_MCL.jl" begin
rm(joinpath("out", "alphas_mean.txt"), force = true)
rm(joinpath("out", "alphas_min.txt"), force = true)
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_double_mach_MCL.jl"),
l2=[
0.8887316108902574,
Expand All @@ -764,6 +781,32 @@ end
],
initial_refinement_level=2,
tspan=(0.0, 0.05))
lines = readlines(joinpath("out", "alphas_mean.txt"))
@test lines[1] ==
"# iter, simu_time, alpha_min_rho, alpha_avg_rho, alpha_min_rho_v1, alpha_avg_rho_v1, alpha_min_rho_v2, alpha_avg_rho_v2, alpha_min_rho_e, alpha_avg_rho_e"
cmd = string(Base.julia_cmd())
coverage = occursin("--code-coverage", cmd) &&
!occursin("--code-coverage=none", cmd)
if coverage
# Run with coverage takes 1 time steps.
@test startswith(lines[end], "1, 0.0002")
else
# Run without coverage takes 191 time steps.
@test startswith(lines[end], "191, 0.05, 3.7017")
end
lines = readlines(joinpath("out", "alphas_min.txt"))
@test lines[1] ==
"# iter, simu_time, alpha_min_rho, alpha_avg_rho, alpha_min_rho_v1, alpha_avg_rho_v1, alpha_min_rho_v2, alpha_avg_rho_v2, alpha_min_rho_e, alpha_avg_rho_e"
cmd = string(Base.julia_cmd())
coverage = occursin("--code-coverage", cmd) &&
!occursin("--code-coverage=none", cmd)
if coverage
# Run with coverage takes 1 time steps.
@test startswith(lines[end], "1, 0.0002") # TODO
else
# Run without coverage takes 191 time steps.
@test startswith(lines[end], "191, 0.05, -0.0, 0.7216")
end
# Ensure that we do not have excessive memory allocations
# (e.g., from type instabilities)
let
Expand Down
43 changes: 43 additions & 0 deletions test/test_tree_2d_euler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ end

@trixi_testset "elixir_euler_sedov_blast_wave_sc_subcell.jl" begin
rm(joinpath("out", "deviations.txt"), force = true)
rm(joinpath("out", "alphas.txt"), force = true)
@test_trixi_include(joinpath(EXAMPLES_DIR,
"elixir_euler_sedov_blast_wave_sc_subcell.jl"),
l2=[
Expand Down Expand Up @@ -563,6 +564,20 @@ end
# Run without coverage takes 381 time steps.
@test startswith(lines[end], "381")
end
lines = readlines(joinpath("out", "alphas.txt"))
@test lines[1] ==
"# iter, simu_time, alpha_max, alpha_avg"
cmd = string(Base.julia_cmd())
coverage = occursin("--code-coverage", cmd) &&
!occursin("--code-coverage=none", cmd)
if coverage
# Run with coverage takes 6 time steps.
@test startswith(lines[end], "6, 0.014")
@test occursin(r"1.0, 0.953", lines[end])
else
# Run without coverage takes 381 time steps.
@test startswith(lines[end], "381, 1.0, 1.0, 0.544")
end
# Ensure that we do not have excessive memory allocations
# (e.g., from type instabilities)
let
Expand All @@ -579,6 +594,8 @@ end

@trixi_testset "elixir_euler_sedov_blast_wave_MCL.jl" begin
rm(joinpath("out", "deviations.txt"), force = true)
rm(joinpath("out", "alphas_mean.txt"), force = true)
rm(joinpath("out", "alphas_min.txt"), force = true)
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_sedov_blast_wave_MCL.jl"),
l2=[
0.4740321851943766,
Expand Down Expand Up @@ -609,6 +626,32 @@ end
# Run without coverage takes 349 time steps.
@test startswith(lines[end], "349")
end
lines = readlines(joinpath("out", "alphas_mean.txt"))
@test lines[1] ==
"# iter, simu_time, alpha_min_rho, alpha_avg_rho, alpha_min_rho_v1, alpha_avg_rho_v1, alpha_min_rho_v2, alpha_avg_rho_v2, alpha_min_rho_e, alpha_avg_rho_e, alpha_min_pressure, alpha_avg_pressure, alpha_min_entropy, alpha_avg_entropy"
cmd = string(Base.julia_cmd())
coverage = occursin("--code-coverage", cmd) &&
!occursin("--code-coverage=none", cmd)
if coverage
# Run with coverage takes 6 time steps.
@test startswith(lines[end], "6, 0.014")
else
# Run without coverage takes 349 time steps.
@test startswith(lines[end], "349, 1.0, 0.0002")
end
lines = readlines(joinpath("out", "alphas_min.txt"))
@test lines[1] ==
"# iter, simu_time, alpha_min_rho, alpha_avg_rho, alpha_min_rho_v1, alpha_avg_rho_v1, alpha_min_rho_v2, alpha_avg_rho_v2, alpha_min_rho_e, alpha_avg_rho_e, alpha_min_pressure, alpha_avg_pressure, alpha_min_entropy, alpha_avg_entropy"
cmd = string(Base.julia_cmd())
coverage = occursin("--code-coverage", cmd) &&
!occursin("--code-coverage=none", cmd)
if coverage
# Run with coverage takes 6 time steps.
@test startswith(lines[end], "6, 0.014")
else
# Run without coverage takes 349 time steps.
@test startswith(lines[end], "349, 1.0, -0.0, 0.773")
end
# Ensure that we do not have excessive memory allocations
# (e.g., from type instabilities)
let
Expand Down

0 comments on commit ea55b68

Please sign in to comment.