From 1cce321fa76baf0bf25cbd50a0de81bf56639d89 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Wed, 29 May 2024 14:52:58 +0200 Subject: [PATCH 1/7] Add TrixiParticles WCSPH benchmark --- benchmarks/benchmarks.jl | 1 + benchmarks/smoothed_particle_hydrodynamics.jl | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 benchmarks/smoothed_particle_hydrodynamics.jl diff --git a/benchmarks/benchmarks.jl b/benchmarks/benchmarks.jl index 59e0bd2d..64d52519 100644 --- a/benchmarks/benchmarks.jl +++ b/benchmarks/benchmarks.jl @@ -1,4 +1,5 @@ include("count_neighbors.jl") include("n_body.jl") +include("smoothed_particle_hydrodynamics.jl") include("plot.jl") diff --git a/benchmarks/smoothed_particle_hydrodynamics.jl b/benchmarks/smoothed_particle_hydrodynamics.jl new file mode 100644 index 00000000..0def4555 --- /dev/null +++ b/benchmarks/smoothed_particle_hydrodynamics.jl @@ -0,0 +1,41 @@ +using PointNeighbors +using TrixiParticles +using BenchmarkTools + +const TrivialNeighborhoodSearch = PointNeighbors.TrivialNeighborhoodSearch +const GridNeighborhoodSearch = PointNeighbors.GridNeighborhoodSearch + +""" + benchmark_wcsph(neighborhood_search, coordinates; parallel = true) + +A benchmark of the right-hand side of a full real-life Weakly Compressible +Smoothed Particle Hydrodynamics (WCSPH) simulation with TrixiParticles.jl. +""" +function benchmark_wcsph(neighborhood_search, coordinates; parallel = true) + density = 1000.0 + fluid = InitialCondition(; coordinates, density, mass = 0.1) + + # Compact support == smoothing length for the Wendland kernel + smoothing_length = neighborhood_search.search_radius + smoothing_kernel = WendlandC2Kernel{ndims(neighborhood_search)}() + + sound_speed = 10.0 + state_equation = StateEquationCole(; sound_speed, reference_density = density, + exponent = 1) + + fluid_density_calculator = ContinuityDensity() + viscosity = ArtificialViscosityMonaghan(alpha = 0.02, beta = 0.0) + density_diffusion = DensityDiffusionMolteniColagrossi(delta = 0.1) + + fluid_system = WeaklyCompressibleSPHSystem(fluid, fluid_density_calculator, + state_equation, smoothing_kernel, + smoothing_length, viscosity = viscosity, + density_diffusion = density_diffusion) + + v = vcat(fluid.velocity, fluid.density') + u = copy(fluid.coordinates) + dv = zero(v) + + return @belapsed TrixiParticles.interact!($dv, $v, $u, $v, $u, $neighborhood_search, + $fluid_system, $fluid_system) +end From 28f5ddc84dfc6aa99fee8be9b6548c9ab627dac9 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Thu, 20 Jun 2024 14:08:00 +0200 Subject: [PATCH 2/7] Add TLSPH benchmark --- benchmarks/smoothed_particle_hydrodynamics.jl | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/benchmarks/smoothed_particle_hydrodynamics.jl b/benchmarks/smoothed_particle_hydrodynamics.jl index 0def4555..ebf51b19 100644 --- a/benchmarks/smoothed_particle_hydrodynamics.jl +++ b/benchmarks/smoothed_particle_hydrodynamics.jl @@ -4,19 +4,25 @@ using BenchmarkTools const TrivialNeighborhoodSearch = PointNeighbors.TrivialNeighborhoodSearch const GridNeighborhoodSearch = PointNeighbors.GridNeighborhoodSearch +const PrecomputedNeighborhoodSearch = PointNeighbors.PrecomputedNeighborhoodSearch """ benchmark_wcsph(neighborhood_search, coordinates; parallel = true) A benchmark of the right-hand side of a full real-life Weakly Compressible Smoothed Particle Hydrodynamics (WCSPH) simulation with TrixiParticles.jl. +This method is used to simulate an incompressible fluid. """ function benchmark_wcsph(neighborhood_search, coordinates; parallel = true) density = 1000.0 fluid = InitialCondition(; coordinates, density, mass = 0.1) # Compact support == smoothing length for the Wendland kernel - smoothing_length = neighborhood_search.search_radius + if neighborhood_search isa PrecomputedNeighborhoodSearch + smoothing_length = neighborhood_search.neighborhood_search.search_radius + else + smoothing_length = neighborhood_search.search_radius + end smoothing_kernel = WendlandC2Kernel{ndims(neighborhood_search)}() sound_speed = 10.0 @@ -39,3 +45,33 @@ function benchmark_wcsph(neighborhood_search, coordinates; parallel = true) return @belapsed TrixiParticles.interact!($dv, $v, $u, $v, $u, $neighborhood_search, $fluid_system, $fluid_system) end + +""" + benchmark_tlsph(neighborhood_search, coordinates; parallel = true) + +A benchmark of the right-hand side of a full real-life Total Lagrangian +Smoothed Particle Hydrodynamics (TLSPH) simulation with TrixiParticles.jl. +This method is used to simulate an elastic structure. +""" +function benchmark_tlsph(neighborhood_search, coordinates; parallel = true) + material = (density = 1000.0, E = 1.4e6, nu = 0.4) + solid = InitialCondition(; coordinates, density = material.density, mass = 0.1) + + # Compact support == smoothing length for the Wendland kernel + if neighborhood_search isa PrecomputedNeighborhoodSearch + smoothing_length = neighborhood_search.neighborhood_search.search_radius + else + smoothing_length = neighborhood_search.search_radius + end + smoothing_kernel = WendlandC2Kernel{ndims(neighborhood_search)}() + + solid_system = TotalLagrangianSPHSystem(solid, smoothing_kernel, smoothing_length, + material.E, material.nu) + + v = copy(solid.velocity) + u = copy(solid.coordinates) + dv = zero(v) + + return @belapsed TrixiParticles.interact!($dv, $v, $u, $v, $u, $neighborhood_search, + $solid_system, $solid_system) +end From 94fe3488a5abf37d9a25aafc49d1f74275539d9f Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Thu, 20 Jun 2024 14:23:48 +0200 Subject: [PATCH 3/7] Add TrixiParticles to test dependencies --- test/Project.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/Project.toml b/test/Project.toml index a44e84ee..d6127cea 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -3,6 +3,10 @@ BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +TrixiParticles = "66699cd8-9c01-4e9d-a059-b96c86d16b3a" [compat] +BenchmarkTools = "1.5" +Plots = "1.40" Test = "1" +TrixiParticles = "0.1" From b196986c5e6fd7c9a45c5e01ba7249470c3387fb Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Wed, 26 Jun 2024 14:43:54 +0200 Subject: [PATCH 4/7] Add new benchmarks to tests --- test/benchmarks.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/benchmarks.jl b/test/benchmarks.jl index 15469a4d..cfc04e38 100644 --- a/test/benchmarks.jl +++ b/test/benchmarks.jl @@ -13,5 +13,13 @@ @testset verbose=true "`benchmark_n_body`" begin @test_nowarn_mod plot_benchmarks(benchmark_n_body, size, 2) end + + @testset verbose=true "`benchmark_wcsph`" begin + @test_nowarn_mod plot_benchmarks(benchmark_wcsph, size, 2) + end + + @testset verbose=true "`benchmark_tlsph`" begin + @test_nowarn_mod plot_benchmarks(benchmark_tlsph, size, 2) + end end end; From 5b7b521fa11816df8a55ef35560091c5e7dade74 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Thu, 27 Jun 2024 13:44:21 +0200 Subject: [PATCH 5/7] Use 0.2 release of TrixiParticles --- test/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Project.toml b/test/Project.toml index 8b647153..c826e5bc 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -9,4 +9,4 @@ TrixiParticles = "66699cd8-9c01-4e9d-a059-b96c86d16b3a" BenchmarkTools = "1" Plots = "1" Test = "1" -TrixiParticles = "0.1" +TrixiParticles = "0.2" From e5166045ff164cdad4bbd8cb649f9b73e917abe6 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Thu, 18 Jul 2024 10:18:23 +0200 Subject: [PATCH 6/7] Initialize the systems --- benchmarks/smoothed_particle_hydrodynamics.jl | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/benchmarks/smoothed_particle_hydrodynamics.jl b/benchmarks/smoothed_particle_hydrodynamics.jl index ebf51b19..ed7fca18 100644 --- a/benchmarks/smoothed_particle_hydrodynamics.jl +++ b/benchmarks/smoothed_particle_hydrodynamics.jl @@ -2,10 +2,6 @@ using PointNeighbors using TrixiParticles using BenchmarkTools -const TrivialNeighborhoodSearch = PointNeighbors.TrivialNeighborhoodSearch -const GridNeighborhoodSearch = PointNeighbors.GridNeighborhoodSearch -const PrecomputedNeighborhoodSearch = PointNeighbors.PrecomputedNeighborhoodSearch - """ benchmark_wcsph(neighborhood_search, coordinates; parallel = true) @@ -18,11 +14,7 @@ function benchmark_wcsph(neighborhood_search, coordinates; parallel = true) fluid = InitialCondition(; coordinates, density, mass = 0.1) # Compact support == smoothing length for the Wendland kernel - if neighborhood_search isa PrecomputedNeighborhoodSearch - smoothing_length = neighborhood_search.neighborhood_search.search_radius - else - smoothing_length = neighborhood_search.search_radius - end + smoothing_length = PointNeighbors.search_radius(neighborhood_search) smoothing_kernel = WendlandC2Kernel{ndims(neighborhood_search)}() sound_speed = 10.0 @@ -42,6 +34,10 @@ function benchmark_wcsph(neighborhood_search, coordinates; parallel = true) u = copy(fluid.coordinates) dv = zero(v) + # Initialize the system + TrixiParticles.initialize!(fluid_system, neighborhood_search) + TrixiParticles.compute_pressure!(fluid_system, v) + return @belapsed TrixiParticles.interact!($dv, $v, $u, $v, $u, $neighborhood_search, $fluid_system, $fluid_system) end @@ -58,11 +54,7 @@ function benchmark_tlsph(neighborhood_search, coordinates; parallel = true) solid = InitialCondition(; coordinates, density = material.density, mass = 0.1) # Compact support == smoothing length for the Wendland kernel - if neighborhood_search isa PrecomputedNeighborhoodSearch - smoothing_length = neighborhood_search.neighborhood_search.search_radius - else - smoothing_length = neighborhood_search.search_radius - end + smoothing_length = PointNeighbors.search_radius(neighborhood_search) smoothing_kernel = WendlandC2Kernel{ndims(neighborhood_search)}() solid_system = TotalLagrangianSPHSystem(solid, smoothing_kernel, smoothing_length, @@ -72,6 +64,9 @@ function benchmark_tlsph(neighborhood_search, coordinates; parallel = true) u = copy(solid.coordinates) dv = zero(v) + # Initialize the system + TrixiParticles.initialize!(solid_system, neighborhood_search) + return @belapsed TrixiParticles.interact!($dv, $v, $u, $v, $u, $neighborhood_search, $solid_system, $solid_system) end From 93201f2b76fb2fabc58f64d126b9a66cffc95382 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Wed, 7 Aug 2024 09:53:45 +0200 Subject: [PATCH 7/7] Fix 1D benchmarks --- benchmarks/smoothed_particle_hydrodynamics.jl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/benchmarks/smoothed_particle_hydrodynamics.jl b/benchmarks/smoothed_particle_hydrodynamics.jl index ed7fca18..bb90c5ac 100644 --- a/benchmarks/smoothed_particle_hydrodynamics.jl +++ b/benchmarks/smoothed_particle_hydrodynamics.jl @@ -15,7 +15,11 @@ function benchmark_wcsph(neighborhood_search, coordinates; parallel = true) # Compact support == smoothing length for the Wendland kernel smoothing_length = PointNeighbors.search_radius(neighborhood_search) - smoothing_kernel = WendlandC2Kernel{ndims(neighborhood_search)}() + if ndims(neighborhood_search) == 1 + smoothing_kernel = SchoenbergCubicSplineKernel{1}() + else + smoothing_kernel = WendlandC2Kernel{ndims(neighborhood_search)}() + end sound_speed = 10.0 state_equation = StateEquationCole(; sound_speed, reference_density = density, @@ -55,7 +59,11 @@ function benchmark_tlsph(neighborhood_search, coordinates; parallel = true) # Compact support == smoothing length for the Wendland kernel smoothing_length = PointNeighbors.search_radius(neighborhood_search) - smoothing_kernel = WendlandC2Kernel{ndims(neighborhood_search)}() + if ndims(neighborhood_search) == 1 + smoothing_kernel = SchoenbergCubicSplineKernel{1}() + else + smoothing_kernel = WendlandC2Kernel{ndims(neighborhood_search)}() + end solid_system = TotalLagrangianSPHSystem(solid, smoothing_kernel, smoothing_length, material.E, material.nu)