@@ -338,8 +338,8 @@ function semidiscretize(semi, tspan; reset_threads=true)
338338 # Initialize this system
339339 initialize! (system, semi_new)
340340
341- # Only for systems requiring a mandatory callback
342- reset_callback_flag ! (system)
341+ # Only for systems requiring the use of the `UpdateCallback`
342+ set_callback_flag ! (system, false )
343343 end
344344
345345 return DynamicalODEProblem (kick!, drift!, v0_ode, u0_ode, tspan, semi_new)
@@ -373,8 +373,8 @@ function restart_with!(semi, sol; reset_threads=true)
373373
374374 restart_with! (system, v, u)
375375
376- # Only for systems requiring a mandatory callback
377- reset_callback_flag ! (system)
376+ # Only for systems requiring the use of the `UpdateCallback`
377+ set_callback_flag ! (system, false )
378378 end
379379
380380 return semi
@@ -464,17 +464,33 @@ function drift!(du_ode, v_ode, u_ode, semi, t)
464464end
465465
466466@inline function add_velocity! (du, v, particle, system)
467+ # Generic fallback for all systems that don't define this function
467468 for i in 1 : ndims (system)
468- du[i, particle] = v[i, particle]
469+ @inbounds du[i, particle] = v[i, particle]
469470 end
470471
471472 return du
472473end
473474
475+ # Solid wall boundary system doesn't integrate the particle positions
474476@inline add_velocity! (du, v, particle, system:: BoundarySPHSystem ) = du
475477
478+ @inline function add_velocity! (du, v, particle, system:: FluidSystem )
479+ # This is zero unless a transport velocity is used
480+ delta_v_ = delta_v (system, particle)
481+
482+ for i in 1 : ndims (system)
483+ @inbounds du[i, particle] = v[i, particle] + delta_v_[i]
484+ end
485+
486+ return du
487+ end
488+
476489function kick! (dv_ode, v_ode, u_ode, semi, t)
477490 @trixi_timeit timer () " kick!" begin
491+ # Check that the `UpdateCallback` is used if required
492+ check_update_callback (semi)
493+
478494 @trixi_timeit timer () " reset ∂v/∂t" set_zero! (dv_ode)
479495
480496 @trixi_timeit timer () " update systems and nhs" update_systems_and_nhs (v_ode, u_ode,
@@ -490,8 +506,9 @@ function kick!(dv_ode, v_ode, u_ode, semi, t)
490506 return dv_ode
491507end
492508
493- # Update the systems and neighborhood searches (NHS) for a simulation before calling `interact!` to compute forces
494- function update_systems_and_nhs (v_ode, u_ode, semi, t; update_from_callback= false )
509+ # Update the systems and neighborhood searches (NHS) for a simulation
510+ # before calling `interact!` to compute forces.
511+ function update_systems_and_nhs (v_ode, u_ode, semi, t)
495512 # First update step before updating the NHS
496513 # (for example for writing the current coordinates in the solid system)
497514 foreach_system (semi) do system
@@ -523,12 +540,21 @@ function update_systems_and_nhs(v_ode, u_ode, semi, t; update_from_callback=fals
523540 update_pressure! (system, v, u, v_ode, u_ode, semi, t)
524541 end
525542
543+ # This update depends on the computed quantities of the fluid system and therefore
544+ # needs to be after `update_quantities!`.
545+ foreach_system (semi) do system
546+ v = wrap_v (v_ode, system, semi)
547+ u = wrap_u (u_ode, system, semi)
548+
549+ update_boundary_interpolation! (system, v, u, v_ode, u_ode, semi, t)
550+ end
551+
526552 # Final update step for all remaining systems
527553 foreach_system (semi) do system
528554 v = wrap_v (v_ode, system, semi)
529555 u = wrap_u (u_ode, system, semi)
530556
531- update_final! (system, v, u, v_ode, u_ode, semi, t; update_from_callback )
557+ update_final! (system, v, u, v_ode, u_ode, semi, t)
532558 end
533559end
534560
@@ -858,6 +884,16 @@ function update!(neighborhood_search, x, y, semi; points_moving=(true, false),
858884 parallelization_backend= semi. parallelization_backend)
859885end
860886
887+ function check_update_callback (semi)
888+ foreach_system (semi) do system
889+ # This check will be optimized away if the system does not require the callback
890+ if requires_update_callback (system) && ! update_callback_used (system)
891+ system_name = system |> typeof |> nameof
892+ throw (ArgumentError (" `UpdateCallback` is required for `$system_name `" ))
893+ end
894+ end
895+ end
896+
861897function check_configuration (systems,
862898 nhs:: Union{Nothing, PointNeighbors.AbstractNeighborhoodSearch} )
863899 foreach_system (systems) do system
0 commit comments