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

Generalize surface normal calc #539

Open
wants to merge 250 commits into
base: main
Choose a base branch
from

Conversation

svchb
Copy link
Collaborator

@svchb svchb commented May 29, 2024

Depends on #599
extracted from #584

test/schemes/fluid/surface_normal_sph.jl Outdated Show resolved Hide resolved
test/schemes/fluid/surface_normal_sph.jl Outdated Show resolved Hide resolved
Project.toml Outdated Show resolved Hide resolved
src/schemes/fluid/surface_normal_sph.jl Outdated Show resolved Hide resolved
src/schemes/fluid/surface_normal_sph.jl Show resolved Hide resolved
test/schemes/fluid/surface_normal_sph.jl Outdated Show resolved Hide resolved
test/schemes/fluid/surface_normal_sph.jl Outdated Show resolved Hide resolved
src/schemes/fluid/fluid.jl Outdated Show resolved Hide resolved
Comment on lines +411 to +426
function initialize_colorfield!(system, ::BoundaryModelDummyParticles, neighborhood_search)
system_coords = system.coordinates
(; smoothing_kernel, smoothing_length) = system.boundary_model

foreach_point_neighbor(system, system,
system_coords, system_coords,
neighborhood_search,
points=eachparticle(system)) do particle, neighbor, pos_diff,
distance
system.boundary_model.cache.colorfield_bnd[particle] += kernel(smoothing_kernel,
distance,
smoothing_length)
system.boundary_model.cache.neighbor_count[particle] += 1
end
return system
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a test but this test will change in all subsequent PRs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is better than reducing coverage here and potentially forgetting about it.

Copy link
Collaborator Author

@svchb svchb Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am currently working on #680 and #681. There are only merge errors accumulating in the rest of the chain...

return floor(Int, pi * compact_support^2 / particle_spacing^2)
end

@inline @fastpow function ideal_neighbor_count(::Val{3}, particle_spacing, compact_support)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the codecov report. This is not covered, but the 2D version is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test for this exists in #584

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add it here or does it require other code from #584?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its indirectly tested since it is used in a tested function.

# Section 2.2 in Akinci et al. 2013 "Versatile Surface Tension and Adhesion for SPH Fluids"
# Note: This is the simplest form of normal approximation commonly used in SPH and comes
# with serious deficits in accuracy especially at corners, small neighborhoods and boundaries
function calc_normal_akinci!(system, neighbor_system::BoundarySystem, u_system, v,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check Codecov report. This is missing tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing this doesn't make much sense. Since there is no analytical value. And it will change in all subsequent PRs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me restate that there is a analytical value but the results will not be close. Just closer than without it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be some useful way to test this. Maybe with a high resolution and very large smoothing length?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be noted that I am currently only working on a much different code. So I am completely confused.
Anyway this function is renamed in a future version since it is merged with the other normal method and then split because it became too long. The condition that is used here is also changed.

What I mean here is that the results close to the wall in all versions are not reliable anyway. So the test would break down to testing that a nonzero value exists in this version.

@svchb svchb requested a review from efaulhaber January 21, 2025 17:56
Copy link
Member

@efaulhaber efaulhaber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bunch of small remarks, otherwise this is ready to merge from my side.

Comment on lines 142 to +144
"Systems" => [
"Discrete Element Method (Solid)" => joinpath("systems",
"dem.md"),
"Fluid Models" => joinpath("systems", "fluid.md"),
"Discrete Element Method (Solid)" => joinpath("systems", "dem.md"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense to make it like this:

  • Systems
    • Fluid Models
      • Overview (with the new content that you added in "fluid.md")
      • WCSPH
      • EDAC
    • DEM

Now we have "Fluid Models" on the same level as "WCSPH" and "EDAC", which is confusing to me, as these are fluid models.

The classical model is composed of the curvature minimization and cohesion force.

#### Cohesion force
The model calculates the cohesion force based on the distance between particles and the support radius ``h_c``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The model calculates the cohesion force based on the distance between particles and the support radius ``h_c``.
The model calculates the cohesion force based on the support radius ``h_c`` and the distance between particles.

I read this as "distance between (particles and support radius)".

The model calculates the cohesion force based on the distance between particles and the support radius ``h_c``.
This force is determined using two distinct regimes within the support radius:
- For particles closer than half the support radius,
a repulsive force is calculated to prevent particle clustering too tightly,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
a repulsive force is calculated to prevent particle clustering too tightly,
a repulsive force is calculated to prevent particles from clustering too tightly,

Comment on lines +33 to +34
gravity=gravity, tspan=tspan, density_diffusion=nothing,
sound_speed=sound_speed, prefix="")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused. Why is the tspan needed when sol = nothing?

@@ -40,7 +40,7 @@ sphere2 = SphereShape(fluid_particle_spacing, sphere_radius, sphere2_center,

# ==========================================================================================
# ==== Fluid
fluid_smoothing_length = 1.0 * fluid_particle_spacing
fluid_smoothing_length = 1.0 * fluid_particle_spacing - eps()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? It shouldn't be necessary, that would be confusing. Is this trixi-framework/PointNeighbors.jl#19?

Comment on lines +189 to +191
@test isapprox(computed_normals[:, surface_particles],
expected_normals[:, surface_particles], norm=x -> norm(x, Inf),
atol=0.05)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@test isapprox(computed_normals[:, surface_particles],
expected_normals[:, surface_particles], norm=x -> norm(x, Inf),
atol=0.05)
@test isapprox.(computed_normals[:, surface_particles],
expected_normals[:, surface_particles], atol=0.05)

My earlier suggestions were stupid.

# end
end

@testset "Sphere Surface Normals with wall" begin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@testset "Sphere Surface Normals with wall" begin
@testset "Sphere Surface Normals with Wall" begin


# Boundary system
bnd_color = bnd_system.boundary_model.cache.colorfield_bnd
# this is only true since it assumed that the color is 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# this is only true since it assumed that the color is 1
# This is only true since it assumed that the color is 1

Comment on lines +261 to +263
@test isapprox(computed_normals[:, surface_particles],
expected_normals[:, surface_particles], norm=x -> norm(x, Inf),
atol=0.5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@test isapprox(computed_normals[:, surface_particles],
expected_normals[:, surface_particles], norm=x -> norm(x, Inf),
atol=0.5)
@test isapprox.(computed_normals[:, surface_particles],
expected_normals[:, surface_particles], atol=0.5)

Comment on lines +148 to +151
# 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)
# end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment then, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants