From 7c7a1f0e0992b3b1a7f60003cc060692c4183d41 Mon Sep 17 00:00:00 2001 From: Sven Berger Date: Wed, 4 Dec 2024 15:07:26 +0100 Subject: [PATCH 1/6] fix test --- test/schemes/fluid/surface_normal_sph.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/schemes/fluid/surface_normal_sph.jl b/test/schemes/fluid/surface_normal_sph.jl index c4905b6a7..c7bcc04c9 100644 --- a/test/schemes/fluid/surface_normal_sph.jl +++ b/test/schemes/fluid/surface_normal_sph.jl @@ -73,7 +73,7 @@ end system, semi, ode = create_fluid_system(coordinates, velocity, mass, density, particle_spacing, nothing; - buffer_size=0, NDIMS=NDIMS) + NDIMS=NDIMS) compute_and_test_surface_normals(system, semi, ode; NDIMS=NDIMS) end @@ -96,7 +96,7 @@ end # To get somewhat accurate normals we increase the smoothing length unrealistically system, semi, ode = create_fluid_system(coordinates, velocity, mass, density, particle_spacing, nothing; - buffer_size=0, NDIMS=NDIMS, + NDIMS=NDIMS, smoothing_length=3.0 * particle_spacing) compute_and_test_surface_normals(system, semi, ode; NDIMS=NDIMS) From 2223ee858dab49203f4dbbc13ae5d42704e5255f Mon Sep 17 00:00:00 2001 From: Sven Berger Date: Wed, 4 Dec 2024 17:06:46 +0100 Subject: [PATCH 2/6] update --- src/schemes/fluid/surface_normal_sph.jl | 1 + test/schemes/fluid/surface_normal_sph.jl | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/schemes/fluid/surface_normal_sph.jl b/src/schemes/fluid/surface_normal_sph.jl index 5de816fd6..3721dd3f1 100644 --- a/src/schemes/fluid/surface_normal_sph.jl +++ b/src/schemes/fluid/surface_normal_sph.jl @@ -141,6 +141,7 @@ function remove_invalid_normals!(system::FluidSystem, for particle in each_moving_particle(system) # heuristic condition if there is no gas phase to find the free surface + # We remove normals for particles which have alot of support e.g. they are in the inside if ideal_density_threshold > 0 && ideal_density_threshold * ideal_neighbor_count < cache.neighbor_count[particle] cache.surface_normal[1:ndims(system), particle] .= 0 diff --git a/test/schemes/fluid/surface_normal_sph.jl b/test/schemes/fluid/surface_normal_sph.jl index c7bcc04c9..42b8c32c2 100644 --- a/test/schemes/fluid/surface_normal_sph.jl +++ b/test/schemes/fluid/surface_normal_sph.jl @@ -1,6 +1,6 @@ function create_fluid_system(coordinates, velocity, mass, density, particle_spacing, surface_tension; - NDIMS=2, smoothing_length=1.0) + surface_normal_method=ColorfieldSurfaceNormal(), NDIMS=2, smoothing_length=1.0) tspan = (0.0, 0.01) fluid = InitialCondition(coordinates=coordinates, velocity=velocity, mass=mass, @@ -13,7 +13,7 @@ function create_fluid_system(coordinates, velocity, mass, density, particle_spac system = WeaklyCompressibleSPHSystem(fluid, SummationDensity(), state_equation, SchoenbergCubicSplineKernel{NDIMS}(), smoothing_length; - surface_normal_method=ColorfieldSurfaceNormal(), + surface_normal_method=surface_normal_method, reference_particle_spacing=particle_spacing, surface_tension=surface_tension) @@ -25,6 +25,7 @@ function create_fluid_system(coordinates, velocity, mass, density, particle_spac return system, semi, ode end +# TODO: change to rect function compute_and_test_surface_normals(system, semi, ode; NDIMS=2) v0_ode, u0_ode = ode.u0.x v = TrixiParticles.wrap_v(v0_ode, system, semi) @@ -34,6 +35,8 @@ function compute_and_test_surface_normals(system, semi, ode; NDIMS=2) TrixiParticles.compute_surface_normal!(system, system.surface_normal_method, v, u, v0_ode, u0_ode, semi, 0.0) + TrixiParticles.remove_invalid_normals!(system, SurfaceTensionMorris(), system.surface_normal_method) + # After computation, check that surface normals have been computed and are not NaN or Inf @test all(isfinite.(system.cache.surface_normal)) @test all(isfinite.(system.cache.neighbor_count)) @@ -97,7 +100,8 @@ end system, semi, ode = create_fluid_system(coordinates, velocity, mass, density, particle_spacing, nothing; NDIMS=NDIMS, - smoothing_length=3.0 * particle_spacing) + smoothing_length=3.0 * particle_spacing, + surface_normal_method = ColorfieldSurfaceNormal(interface_threshold=0.1, ideal_density_threshold=0.9)) compute_and_test_surface_normals(system, semi, ode; NDIMS=NDIMS) @@ -130,8 +134,9 @@ end end end - # Compare computed normals to expected normals for surface particles - @test isapprox(computed_normals, expected_normals, atol=0.05) + for i in surface_particles + @test isapprox(computed_normals[:, i], expected_normals[:, i], atol=0.05) + end # Optionally, check that normals for interior particles are zero # for i in setdiff(1:nparticles, surface_particles) From 9ad052662796796c24a33d173b43f20f0821bc54 Mon Sep 17 00:00:00 2001 From: Sven Berger Date: Wed, 4 Dec 2024 23:34:39 +0100 Subject: [PATCH 3/6] format --- test/schemes/fluid/surface_normal_sph.jl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/schemes/fluid/surface_normal_sph.jl b/test/schemes/fluid/surface_normal_sph.jl index 42b8c32c2..2de3ba68d 100644 --- a/test/schemes/fluid/surface_normal_sph.jl +++ b/test/schemes/fluid/surface_normal_sph.jl @@ -1,6 +1,7 @@ function create_fluid_system(coordinates, velocity, mass, density, particle_spacing, surface_tension; - surface_normal_method=ColorfieldSurfaceNormal(), NDIMS=2, smoothing_length=1.0) + surface_normal_method=ColorfieldSurfaceNormal(), NDIMS=2, + smoothing_length=1.0) tspan = (0.0, 0.01) fluid = InitialCondition(coordinates=coordinates, velocity=velocity, mass=mass, @@ -35,7 +36,8 @@ function compute_and_test_surface_normals(system, semi, ode; NDIMS=2) TrixiParticles.compute_surface_normal!(system, system.surface_normal_method, v, u, v0_ode, u0_ode, semi, 0.0) - TrixiParticles.remove_invalid_normals!(system, SurfaceTensionMorris(), system.surface_normal_method) + TrixiParticles.remove_invalid_normals!(system, SurfaceTensionMorris(), + system.surface_normal_method) # After computation, check that surface normals have been computed and are not NaN or Inf @test all(isfinite.(system.cache.surface_normal)) @@ -101,7 +103,8 @@ end particle_spacing, nothing; NDIMS=NDIMS, smoothing_length=3.0 * particle_spacing, - surface_normal_method = ColorfieldSurfaceNormal(interface_threshold=0.1, ideal_density_threshold=0.9)) + surface_normal_method=ColorfieldSurfaceNormal(interface_threshold=0.1, + ideal_density_threshold=0.9)) compute_and_test_surface_normals(system, semi, ode; NDIMS=NDIMS) From 93630aa107ddb399f8a10563773f75ccf4eac1e7 Mon Sep 17 00:00:00 2001 From: Sven Berger Date: Wed, 4 Dec 2024 23:51:43 +0100 Subject: [PATCH 4/6] fix test --- test/schemes/fluid/surface_normal_sph.jl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/schemes/fluid/surface_normal_sph.jl b/test/schemes/fluid/surface_normal_sph.jl index ae4c19941..92d27d720 100644 --- a/test/schemes/fluid/surface_normal_sph.jl +++ b/test/schemes/fluid/surface_normal_sph.jl @@ -1,3 +1,4 @@ +include("../../test_util.jl") function create_fluid_system(coordinates, velocity, mass, density, particle_spacing; NDIMS=2, smoothing_length=1.0) tspan = (0.0, 0.01) @@ -72,7 +73,7 @@ end system, semi, ode = create_fluid_system(coordinates, velocity, mass, density, particle_spacing; - buffer_size=0, NDIMS=NDIMS) + NDIMS=NDIMS) compute_and_test_surface_normals(system, semi, ode; NDIMS=NDIMS) end @@ -95,7 +96,7 @@ end # To get somewhat accurate normals we increase the smoothing length unrealistically system, semi, ode = create_fluid_system(coordinates, velocity, mass, density, particle_spacing; - buffer_size=0, NDIMS=NDIMS, + NDIMS=NDIMS, smoothing_length=3.0 * particle_spacing) compute_and_test_surface_normals(system, semi, ode; NDIMS=NDIMS) @@ -130,8 +131,9 @@ end end # Compare computed normals to expected normals for surface particles - @test isapprox(computed_normals, expected_normals, atol=0.05) - + for i in surface_particles + @test isapprox(computed_normals[:, i], expected_normals[:, i], atol=0.04) + end # Optionally, check that normals for interior particles are zero # for i in setdiff(1:nparticles, surface_particles) # @test isapprox(norm(system.cache.surface_normal[:, i]), 0.0, atol=1e-4) From 2cc151c5af02519177241c4a015e41091da45bf1 Mon Sep 17 00:00:00 2001 From: Sven Berger Date: Wed, 4 Dec 2024 23:53:54 +0100 Subject: [PATCH 5/6] merge --- test/schemes/fluid/surface_normal_sph.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/schemes/fluid/surface_normal_sph.jl b/test/schemes/fluid/surface_normal_sph.jl index fc84cfce2..2c248d797 100644 --- a/test/schemes/fluid/surface_normal_sph.jl +++ b/test/schemes/fluid/surface_normal_sph.jl @@ -137,8 +137,9 @@ end end end - for i in surface_particles - @test isapprox(computed_normals[:, i][:, i], expected_normals[:, i][:, i], atol=0.04) + for i in surface_particles + @test isapprox(computed_normals[:, i][:, i], expected_normals[:, i][:, i], + atol=0.04) end # Optionally, check that normals for interior particles are zero From 9f758be50a380b1cb4ec8e7b655df1839adfab96 Mon Sep 17 00:00:00 2001 From: Sven Berger Date: Wed, 4 Dec 2024 23:54:13 +0100 Subject: [PATCH 6/6] typo --- test/schemes/fluid/surface_normal_sph.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/test/schemes/fluid/surface_normal_sph.jl b/test/schemes/fluid/surface_normal_sph.jl index 92d27d720..967a4e5fc 100644 --- a/test/schemes/fluid/surface_normal_sph.jl +++ b/test/schemes/fluid/surface_normal_sph.jl @@ -1,4 +1,3 @@ -include("../../test_util.jl") function create_fluid_system(coordinates, velocity, mass, density, particle_spacing; NDIMS=2, smoothing_length=1.0) tspan = (0.0, 0.01)