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

Revise custom quantities #457

Merged
merged 5 commits into from
Mar 12, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 55 additions & 28 deletions src/general/custom_quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
Returns the total kinetic energy of all particles in a system.
"""
function kinetic_energy(v, u, t, system)
if n_moving_particles(system) == 0
return 0.0
end

return sum(each_moving_particle(system)) do particle
# If `each_moving_particle` is empty (no moving particles), return zero
return sum(each_moving_particle(system), init=0.0) do particle
velocity = current_velocity(v, system, particle)
return 0.5 * system.mass[particle] * dot(velocity, velocity)
end
Expand All @@ -20,77 +17,107 @@ end
Returns the total mass of all particles in a system.
"""
function total_mass(v, u, t, system)
return sum(each_moving_particle(system)) do particle
return sum(eachparticle(system)) do particle
return system.mass[particle]
end
end

function total_mass(v, u, t, system::BoundarySystem)
# It does not make sense to return a mass for boundary systems.
# The material density and therefore the physical mass of the boundary is not relevant
# when simulating a solid, stationary wall. The boundary always behaves as if it had
# infinite mass. There is no momentum transferred to the boundary on impact.
#
# When the dummy particles model is used, i.e., boundary particles behave like fliud
efaulhaber marked this conversation as resolved.
Show resolved Hide resolved
# particles when interacting with actual fluid particles, the boundary particles do have
# a "hydrodynamic mass", which corresponds to the fluid density, but this is only
# relevant for the fluid interaction, and it has no connection to the physical mass
# of the boundary. Returning the "hydrodynamic mass" here would thus be misleading.
return NaN
end

"""
max_pressure

Returns the maximum pressure over all particles in a system.
"""
function max_pressure(v, u, t, system)
function max_pressure(v, u, t, system::FluidSystem)
return maximum(particle -> particle_pressure(v, system, particle),
each_moving_particle(system))
eachparticle(system))
end

function max_pressure(v, u, t, system)
return NaN
end

"""
min_pressure

Returns the minimum pressure over all particles in a system.
"""
function min_pressure(v, u, t, system)
function min_pressure(v, u, t, system::FluidSystem)
return minimum(particle -> particle_pressure(v, system, particle),
each_moving_particle(system))
eachparticle(system))
end

function min_pressure(v, u, t, system)
return NaN
end

"""
avg_pressure

Returns the average pressure over all particles in a system.
"""
function avg_pressure(v, u, t, system)
if n_moving_particles(system) == 0
return 0.0
end

function avg_pressure(v, u, t, system::FluidSystem)
sum_ = sum(particle -> particle_pressure(v, system, particle),
each_moving_particle(system))
return sum_ / n_moving_particles(system)
eachparticle(system))
return sum_ / nparticles(system)
end

function avg_pressure(v, u, t, system)
return NaN
end

"""
max_density

Returns the maximum density over all particles in a system.
"""
function max_density(v, u, t, system)
function max_density(v, u, t, system::FluidSystem)
return maximum(particle -> particle_density(v, system, particle),
each_moving_particle(system))
eachparticle(system))
end

function max_density(v, u, t, system)
return NaN
end

"""
min_density

Returns the minimum density over all particles in a system.
"""
function min_density(v, u, t, system)
function min_density(v, u, t, system::FluidSystem)
return minimum(particle -> particle_density(v, system, particle),
each_moving_particle(system))
eachparticle(system))
end

function min_density(v, u, t, system)
return NaN
end

"""
avg_density

Returns the average_density over all particles in a system.
"""
function avg_density(v, u, t, system)
if n_moving_particles(system) == 0
return 0.0
end

function avg_density(v, u, t, system::FluidSystem)
sum_ = sum(particle -> particle_density(v, system, particle),
each_moving_particle(system))
return sum_ / n_moving_particles(system)
eachparticle(system))
return sum_ / nparticles(system)
end

function avg_density(v, u, t, system)
return NaN
end
Loading