Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion src/callbacks/density_reinit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Callback to reinitialize the density field when using [`ContinuityDensity`](@ref
# Keywords
- `interval=0`: Reinitialize the density every `interval` time steps.
- `dt`: Reinitialize the density in regular intervals of `dt` in terms
of integration time.
of integration time. This callback does not add extra time
steps / `tstops`; instead, reinitialization is triggered at
the first solver step after each `dt` interval has elapsed.
- `reinit_initial_solution`: Reinitialize the initial solution (default=false)
"""
mutable struct DensityReinitializationCallback{I}
Expand Down Expand Up @@ -102,4 +104,6 @@ function (reinit_callback::DensityReinitializationCallback)(integrator)
@trixi_timeit timer() "reinit density" reinit_density!(vu_ode, semi)

reinit_callback.last_t = integrator.t

u_modified!(integrator, true)
end
4 changes: 3 additions & 1 deletion src/callbacks/solution_saving.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ function SolutionSavingCallback(; interval::Integer=0, dt=0.0,
-1, Ref("UnknownVersion"))

if length(save_times) > 0
return PresetTimeCallback(save_times, solution_callback)
return PresetTimeCallback(save_times, solution_callback,
save_positions=(false, false),
initialize=(initialize_save_cb!))
elseif dt > 0
Comment on lines 106 to 110
# Add a `tstop` every `dt`, and save the final solution
return PeriodicCallback(solution_callback, dt,
Expand Down
21 changes: 8 additions & 13 deletions src/callbacks/steady_state_reached.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,20 @@ function SteadyStateReachedCallback(; interval::Integer=0, dt=0.0,
end
end

# `affect!` (`PeriodicCallback`)
# `affect!` (`PeriodicCallback` and `DiscreteCallback`)
function (cb::SteadyStateReachedCallback)(integrator)
steady_state_condition!(cb, integrator) || return nothing
if steady_state_condition!(cb, integrator)
print_summary(integrator)

print_summary(integrator)

terminate!(integrator)
end

# `affect!` (`DiscreteCallback`)
function (cb::SteadyStateReachedCallback{Int})(integrator)
print_summary(integrator)

terminate!(integrator)
terminate!(integrator)
end
end

# `condition` (`DiscreteCallback`)
function (steady_state_callback::SteadyStateReachedCallback)(vu_ode, t, integrator)
return steady_state_condition!(steady_state_callback, integrator)
(; interval) = steady_state_callback

return condition_integrator_interval(integrator, interval)
end

@inline function steady_state_condition!(cb, integrator)
Expand Down
2 changes: 1 addition & 1 deletion src/general/initial_condition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ function InitialCondition(sol::ODESolution, system, semi; use_final_velocity=fal

v_ode, u_ode = sol.u[end].x

v = wrap_v(v_ode, system, semi)
u = wrap_u(u_ode, system, semi)
v = wrap_u(v_ode, system, semi)

# Check if particles come too close especially when the surface exhibits large curvature
too_close = find_too_close_particles(u, min_particle_distance)
Expand Down
10 changes: 6 additions & 4 deletions src/general/interpolation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,9 @@ end
ref_id = system_indices(ref_system, semi)
ref_smoothing_kernel = ref_system.smoothing_kernel

# If we don't cut at the boundary, we only need to iterate over the reference system
systems = cut_off_bnd ? semi : (ref_system,)
# If we don't cut at the boundary and don't need the wall velocity of the boundary,
# we only need to iterate over the reference system.
systems = (cut_off_bnd || include_wall_velocity) ? semi : (ref_system,)

foreach_system(systems) do neighbor_system
system_id = system_indices(neighbor_system, semi)
Expand Down Expand Up @@ -605,8 +606,9 @@ end
end

@threaded parallelization_backend for point in axes(point_coords, 2)
if other_density[point] > computed_density[point] ||
computed_density[point] < eps()
set_nan = computed_density[point] < eps() ||
(cut_off_bnd && other_density[point] > computed_density[point])
if set_nan
# Return NaN values that can be filtered out in ParaView
computed_density[point] = NaN
neighbor_count[point] = 0
Expand Down
12 changes: 12 additions & 0 deletions src/schemes/fluid/weakly_compressible_sph/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,13 @@ end

function reinit_density!(system::WeaklyCompressibleSPHSystem, v, u,
v_ode, u_ode, semi)
(; density_calculator) = system

reinit_density!(system, density_calculator, v, u, v_ode, u_ode, semi)
end

function reinit_density!(system::WeaklyCompressibleSPHSystem, ::ContinuityDensity, v, u,
v_ode, u_ode, semi)
# Compute density with `SummationDensity` and store the result in `v`,
# overwriting the previous integrated density.
summation_density!(system, semi, u, u_ode, v[end, :])
Expand All @@ -407,6 +414,11 @@ function reinit_density!(system::WeaklyCompressibleSPHSystem, v, u,
return system
end

function reinit_density!(system::WeaklyCompressibleSPHSystem, ::SummationDensity, v, u,
v_ode, u_ode, semi)
return system
end

function reinit_density!(system, v, u, v_ode, u_ode, semi)
return system
end
Expand Down
Loading