Skip to content

Fix current_velocity for EDAC #825

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

Merged
merged 5 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 6 additions & 2 deletions src/schemes/fluid/entropically_damped_sph/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ system_correction(system::EntropicallyDampedSPHSystem) = system.correction
return v[end, particle]
end

@inline function current_velocity(v, system::EntropicallyDampedSPHSystem)
return view(v, 1:ndims(system), each_moving_particle(system))
end

@inline system_state_equation(system::EntropicallyDampedSPHSystem) = nothing

# WARNING!
Expand Down Expand Up @@ -283,8 +287,8 @@ end
return view(v, size(v, 1) - 1, :)
end

@inline function current_pressure(v, ::EntropicallyDampedSPHSystem)
return view(v, size(v, 1), :)
@inline function current_pressure(v, system::EntropicallyDampedSPHSystem)
return view(v, size(v, 1), each_moving_particle(system))
end

function update_quantities!(system::EntropicallyDampedSPHSystem, v, u,
Expand Down
8 changes: 4 additions & 4 deletions src/schemes/fluid/weakly_compressible_sph/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ end
system::WeaklyCompressibleSPHSystem)
# When using `ContinuityDensity`, the velocity is stored
# in the first `ndims(system)` rows of `v`.
return view(v, 1:ndims(system), :)
return view(v, 1:ndims(system), each_moving_particle(system))
end

@inline function current_density(v, system::WeaklyCompressibleSPHSystem)
Expand All @@ -271,17 +271,17 @@ end
@inline function current_density(v, ::SummationDensity,
system::WeaklyCompressibleSPHSystem)
# When using `SummationDensity`, the density is stored in the cache
return system.cache.density
return view(system.cache.density, each_moving_particle(system))
end

@inline function current_density(v, ::ContinuityDensity,
system::WeaklyCompressibleSPHSystem)
# When using `ContinuityDensity`, the density is stored in the last row of `v`
return view(v, size(v, 1), :)
return view(v, size(v, 1), each_moving_particle(system))
end

@inline function current_pressure(v, system::WeaklyCompressibleSPHSystem)
return system.pressure
return view(system.pressure, each_moving_particle(system))
end

@inline system_sound_speed(system::WeaklyCompressibleSPHSystem) = system.state_equation.sound_speed
Expand Down
5 changes: 5 additions & 0 deletions test/systems/edac_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,12 @@
TrixiParticles.n_moving_particles(system))
TrixiParticles.write_v0!(v0, system)

system.cache.density .= density

@test v0 == vcat(velocity, pressure')
@test TrixiParticles.current_velocity(v0, system) == velocity
@test TrixiParticles.current_density(v0, system) == system.cache.density
@test TrixiParticles.current_pressure(v0, system) == pressure

initial_condition = InitialCondition(; coordinates, velocity, mass, density,
pressure=pressure_function)
Expand Down
6 changes: 6 additions & 0 deletions test/systems/wcsph_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,13 @@
TrixiParticles.n_moving_particles(system))
TrixiParticles.write_v0!(v0, system)

system.cache.density .= density
system.pressure .= zero(density)

@test v0 == velocity
@test TrixiParticles.current_velocity(v0, system) == velocity
@test TrixiParticles.current_density(v0, system) == system.cache.density
@test TrixiParticles.current_pressure(v0, system) == system.pressure

# ContinuityDensity
system = WeaklyCompressibleSPHSystem(initial_condition,
Expand Down
Loading