From a56982474b4719adfc7a1bbbcf491ab9f57734ca Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Wed, 7 Feb 2024 18:28:12 +0100 Subject: [PATCH] Move dam break corrections to test (#376) * Move dam break corrections example to test * Add dam break corrections to tests --------- Co-authored-by: Niklas Neher <73897120+LasNikas@users.noreply.github.com> --- examples/fluid/dam_break_2d_corrections.jl | 94 --------------------- test/examples/dam_break_2d_corrections.jl | 98 ++++++++++++++++++++++ test/examples/examples.jl | 14 +--- 3 files changed, 102 insertions(+), 104 deletions(-) delete mode 100644 examples/fluid/dam_break_2d_corrections.jl create mode 100644 test/examples/dam_break_2d_corrections.jl diff --git a/examples/fluid/dam_break_2d_corrections.jl b/examples/fluid/dam_break_2d_corrections.jl deleted file mode 100644 index bd2b790af..000000000 --- a/examples/fluid/dam_break_2d_corrections.jl +++ /dev/null @@ -1,94 +0,0 @@ -using TrixiParticles - -fluid_density = 1000.0 - -particle_spacing = 0.05 - -tspan = (0.0, 5.7 / sqrt(9.81)) - -correction_dict = Dict( - "no_correction" => nothing, - "shepard_kernel_correction" => ShepardKernelCorrection(), - "akinci_free_surf_correction" => AkinciFreeSurfaceCorrection(fluid_density), - "kernel_gradient_summation_correction" => KernelCorrection(), - "kernel_gradient_continuity_correction" => KernelCorrection(), - "blended_gradient_summation_correction" => BlendedGradientCorrection(0.5), - "blended_gradient_continuity_correction" => BlendedGradientCorrection(0.2), - "gradient_summation_correction" => GradientCorrection(), - "mixed_kernel_gradient_summation_correction" => MixedKernelGradientCorrection(), - # "gradient_continuity_correction" => GradientCorrection(), - # "mixed_kernel_gradient_continuity_correction" => MixedKernelGradientCorrection(), -) - -smoothing_length_dict = Dict( - "no_correction" => 3.0 * particle_spacing, - "shepard_kernel_correction" => 3.0 * particle_spacing, - "akinci_free_surf_correction" => 3.0 * particle_spacing, - "kernel_gradient_summation_correction" => 4.0 * particle_spacing, - "kernel_gradient_continuity_correction" => 3.5 * particle_spacing, - "blended_gradient_summation_correction" => 3.0 * particle_spacing, - "blended_gradient_continuity_correction" => 4.0 * particle_spacing, - "gradient_summation_correction" => 3.5 * particle_spacing, - "mixed_kernel_gradient_summation_correction" => 3.5 * particle_spacing, - "gradient_continuity_correction" => 4.5 * particle_spacing, - "mixed_kernel_gradient_continuity_correction" => 4.0 * particle_spacing, -) - -density_calculator_dict = Dict( - "no_correction" => SummationDensity(), - "shepard_kernel_correction" => SummationDensity(), - "akinci_free_surf_correction" => SummationDensity(), - "kernel_gradient_summation_correction" => SummationDensity(), - "kernel_gradient_continuity_correction" => ContinuityDensity(), - "blended_gradient_summation_correction" => SummationDensity(), - "blended_gradient_continuity_correction" => ContinuityDensity(), - "gradient_summation_correction" => SummationDensity(), - "gradient_continuity_correction" => ContinuityDensity(), - "mixed_kernel_gradient_summation_correction" => SummationDensity(), - "mixed_kernel_gradient_continuity_correction" => ContinuityDensity(), -) - -smoothing_kernel_dict = Dict( - "no_correction" => WendlandC2Kernel{2}(), - "shepard_kernel_correction" => WendlandC2Kernel{2}(), - "akinci_free_surf_correction" => WendlandC2Kernel{2}(), - "kernel_gradient_summation_correction" => WendlandC6Kernel{2}(), - "kernel_gradient_continuity_correction" => WendlandC6Kernel{2}(), - "blended_gradient_summation_correction" => WendlandC2Kernel{2}(), - "blended_gradient_continuity_correction" => WendlandC6Kernel{2}(), - "gradient_summation_correction" => WendlandC6Kernel{2}(), - "gradient_continuity_correction" => WendlandC6Kernel{2}(), - "mixed_kernel_gradient_summation_correction" => WendlandC6Kernel{2}(), - "mixed_kernel_gradient_continuity_correction" => WendlandC6Kernel{2}(), -) - -trixi_include(@__MODULE__, joinpath(examples_dir(), "fluid", "dam_break_2d.jl"), - fluid_particle_spacing=particle_spacing, - smoothing_length=3.0 * particle_spacing, - boundary_density_calculator=ContinuityDensity(), - fluid_density_calculator=ContinuityDensity(), - correction=nothing, use_reinit=true, - prefix="continuity_reinit", tspan=tspan, - fluid_density=fluid_density, density_diffusion=nothing) - -for correction_name in keys(correction_dict) - local fluid_density_calculator = density_calculator_dict[correction_name] - local correction = correction_dict[correction_name] - local smoothing_kernel = smoothing_kernel_dict[correction_name] - local smoothing_length = smoothing_length_dict[correction_name] - - println("="^100) - println("fluid/dam_break_2d.jl with ", correction_name) - - trixi_include(@__MODULE__, joinpath(examples_dir(), "fluid", "dam_break_2d.jl"), - fluid_particle_spacing=particle_spacing, - smoothing_length=smoothing_length, - boundary_density_calculator=SummationDensity(), - fluid_density_calculator=fluid_density_calculator, - correction=correction, use_reinit=false, - clip_negative_pressure=(fluid_density_calculator isa SummationDensity), - smoothing_kernel=smoothing_kernel, - prefix="$(correction_name)", tspan=tspan, - fluid_density=fluid_density, density_diffusion=Nothing(), - boundary_layers=5) -end diff --git a/test/examples/dam_break_2d_corrections.jl b/test/examples/dam_break_2d_corrections.jl new file mode 100644 index 000000000..7f457fae1 --- /dev/null +++ b/test/examples/dam_break_2d_corrections.jl @@ -0,0 +1,98 @@ +@trixi_testset "dam_break_2d.jl with corrections" begin + fluid_density = 1000.0 + particle_spacing = 0.05 + tspan = (0.0, 0.1) + + correction_dict = Dict( + "no_correction" => nothing, + "shepard_kernel_correction" => ShepardKernelCorrection(), + "akinci_free_surf_correction" => AkinciFreeSurfaceCorrection(fluid_density), + "kernel_gradient_summation_correction" => KernelCorrection(), + "kernel_gradient_continuity_correction" => KernelCorrection(), + "blended_gradient_summation_correction" => BlendedGradientCorrection(0.5), + "blended_gradient_continuity_correction" => BlendedGradientCorrection(0.2), + "gradient_summation_correction" => GradientCorrection(), + "mixed_kernel_gradient_summation_correction" => MixedKernelGradientCorrection(), + # "gradient_continuity_correction" => GradientCorrection(), + # "mixed_kernel_gradient_continuity_correction" => MixedKernelGradientCorrection(), + ) + + smoothing_length_dict = Dict( + "no_correction" => 3.0 * particle_spacing, + "shepard_kernel_correction" => 3.0 * particle_spacing, + "akinci_free_surf_correction" => 3.0 * particle_spacing, + "kernel_gradient_summation_correction" => 4.0 * particle_spacing, + "kernel_gradient_continuity_correction" => 3.5 * particle_spacing, + "blended_gradient_summation_correction" => 3.0 * particle_spacing, + "blended_gradient_continuity_correction" => 4.0 * particle_spacing, + "gradient_summation_correction" => 3.5 * particle_spacing, + "mixed_kernel_gradient_summation_correction" => 3.5 * particle_spacing, + "gradient_continuity_correction" => 4.5 * particle_spacing, + "mixed_kernel_gradient_continuity_correction" => 4.0 * particle_spacing, + ) + + density_calculator_dict = Dict( + "no_correction" => SummationDensity(), + "shepard_kernel_correction" => SummationDensity(), + "akinci_free_surf_correction" => SummationDensity(), + "kernel_gradient_summation_correction" => SummationDensity(), + "kernel_gradient_continuity_correction" => ContinuityDensity(), + "blended_gradient_summation_correction" => SummationDensity(), + "blended_gradient_continuity_correction" => ContinuityDensity(), + "gradient_summation_correction" => SummationDensity(), + "gradient_continuity_correction" => ContinuityDensity(), + "mixed_kernel_gradient_summation_correction" => SummationDensity(), + "mixed_kernel_gradient_continuity_correction" => ContinuityDensity(), + ) + + smoothing_kernel_dict = Dict( + "no_correction" => WendlandC2Kernel{2}(), + "shepard_kernel_correction" => WendlandC2Kernel{2}(), + "akinci_free_surf_correction" => WendlandC2Kernel{2}(), + "kernel_gradient_summation_correction" => WendlandC6Kernel{2}(), + "kernel_gradient_continuity_correction" => WendlandC6Kernel{2}(), + "blended_gradient_summation_correction" => WendlandC2Kernel{2}(), + "blended_gradient_continuity_correction" => WendlandC6Kernel{2}(), + "gradient_summation_correction" => WendlandC6Kernel{2}(), + "gradient_continuity_correction" => WendlandC6Kernel{2}(), + "mixed_kernel_gradient_summation_correction" => WendlandC6Kernel{2}(), + "mixed_kernel_gradient_continuity_correction" => WendlandC6Kernel{2}(), + ) + + @testset "continuity_reinit" begin + trixi_include(@__MODULE__, joinpath(examples_dir(), "fluid", "dam_break_2d.jl"), + fluid_particle_spacing=particle_spacing, + smoothing_length=3.0 * particle_spacing, + boundary_density_calculator=ContinuityDensity(), + fluid_density_calculator=ContinuityDensity(), + correction=nothing, use_reinit=true, + prefix="continuity_reinit", tspan=tspan, + fluid_density=fluid_density, density_diffusion=nothing) + + @test sol.retcode == ReturnCode.Success + end + + @testset verbose=true "$correction_name" for correction_name in keys(correction_dict) + local fluid_density_calculator = density_calculator_dict[correction_name] + local correction = correction_dict[correction_name] + local smoothing_kernel = smoothing_kernel_dict[correction_name] + local smoothing_length = smoothing_length_dict[correction_name] + + println("="^100) + println("fluid/dam_break_2d.jl with ", correction_name) + + trixi_include(@__MODULE__, joinpath(examples_dir(), "fluid", "dam_break_2d.jl"), + fluid_particle_spacing=particle_spacing, + smoothing_length=smoothing_length, + boundary_density_calculator=SummationDensity(), + fluid_density_calculator=fluid_density_calculator, + correction=correction, use_reinit=false, + clip_negative_pressure=(fluid_density_calculator isa SummationDensity), + smoothing_kernel=smoothing_kernel, + prefix="$(correction_name)", tspan=tspan, + fluid_density=fluid_density, density_diffusion=nothing, + boundary_layers=5) + + @test sol.retcode == ReturnCode.Success + end +end diff --git a/test/examples/examples.jl b/test/examples/examples.jl index cf2301674..620664f8c 100644 --- a/test/examples/examples.jl +++ b/test/examples/examples.jl @@ -7,8 +7,8 @@ joinpath(examples_dir(), "fluid", "oscillating_drop_2d.jl")) @test sol.retcode == ReturnCode.Success - # This is the error on an Apple M2 Pro. We need this tolerance to make CI pass. - @test isapprox(error_A, 0.0001717690010767381, atol=1e-8) + # This error varies between serial and multithreaded runs + @test isapprox(error_A, 0.0001717690010767381, atol=5e-7) end @trixi_testset "fluid/rectangular_tank_2d.jl" begin @@ -63,14 +63,6 @@ @test sol.retcode == ReturnCode.Success end - @trixi_testset "fluid/dam_break_2d_corrections.jl" begin - @test_nowarn_mod trixi_include(@__MODULE__, - joinpath(examples_dir(), "fluid", - "dam_break_2d_corrections.jl"), - tspan=(0.0, 0.1)) - @test sol.retcode == ReturnCode.Success - end - @trixi_testset "fluid/dam_break_3d.jl" begin @test_nowarn_mod trixi_include(@__MODULE__, joinpath(examples_dir(), "fluid", @@ -94,6 +86,8 @@ tspan=(0.0, 0.4)) @test sol.retcode == ReturnCode.Success end + + include("dam_break_2d_corrections.jl") end @testset verbose=true "Solid" begin