Skip to content

Commit 7fececa

Browse files
committed
Refactor neighborhood search and update functions for improved clarity and performance.
Reduce the branch to only the split-integration/update-system refactor that is still unique on top of upstream/main.
1 parent 9b9efbe commit 7fececa

File tree

2 files changed

+30
-46
lines changed

2 files changed

+30
-46
lines changed

src/callbacks/split_integration.jl

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -214,46 +214,14 @@ end
214214

215215
# Update the systems before calling `interact!` to compute forces
216216
function update_systems_split!(semi, v_ode, u_ode, t)
217-
# First update step before updating the NHS
218-
# (for example for writing the current coordinates in the solid system)
219-
foreach_system(semi) do system
220-
v = wrap_v(v_ode, system, semi)
221-
u = wrap_u(u_ode, system, semi)
222-
223-
update_positions!(system, v, u, v_ode, u_ode, semi, t)
224-
end
225-
226-
# Second update step.
227-
# This is used to calculate density and pressure of the fluid systems
228-
# before updating the boundary systems,
229-
# since the fluid pressure is needed by the Adami interpolation.
230-
foreach_system(semi) do system
231-
v = wrap_v(v_ode, system, semi)
232-
u = wrap_u(u_ode, system, semi)
233-
234-
update_quantities!(system, v, u, v_ode, u_ode, semi, t)
235-
end
236-
237-
# Perform correction and pressure calculation
238-
foreach_system(semi) do system
239-
v = wrap_v(v_ode, system, semi)
240-
u = wrap_u(u_ode, system, semi)
241-
242-
update_pressure!(system, v, u, v_ode, u_ode, semi, t)
243-
end
244-
245217
# No `update_boundary_interpolation!` for performance reasons, or we will lose
246218
# a lot of the speedup that we can gain with split integration.
247219
# We assume that the TLSPH particles move so little during the substeps
248220
# that the extrapolated pressure/density values can be treated as constant.
249-
250-
# Final update step for all remaining systems
251-
foreach_system(semi) do system
252-
v = wrap_v(v_ode, system, semi)
253-
u = wrap_u(u_ode, system, semi)
254-
255-
update_final!(system, v, u, v_ode, u_ode, semi, t)
256-
end
221+
return update_systems!(v_ode, u_ode, semi, t;
222+
update_nhs=false,
223+
update_implicit_sph=false,
224+
update_boundary_interpolation=false)
257225
end
258226

259227
function system_interaction_split!(dv_ode_split, v_ode, u_ode, semi,

src/general/semidiscretization.jl

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,11 @@ function kick!(dv_ode, v_ode, u_ode, semi, t)
469469
return dv_ode
470470
end
471471

472-
# Update the systems and neighborhood searches (NHS) for a simulation
473-
# before calling `interact!` to compute forces.
474-
function update_systems_and_nhs(v_ode, u_ode, semi, t)
472+
# Update the systems for a simulation before calling `interact!` to compute forces.
473+
function update_systems!(v_ode, u_ode, semi, t;
474+
update_nhs=true,
475+
update_implicit_sph=true,
476+
update_boundary_interpolation=true)
475477
# First update step before updating the NHS
476478
# (for example for writing the current coordinates in the TLSPH system)
477479
foreach_system(semi) do system
@@ -481,8 +483,9 @@ function update_systems_and_nhs(v_ode, u_ode, semi, t)
481483
update_positions!(system, v, u, v_ode, u_ode, semi, t)
482484
end
483485

484-
# Update NHS
485-
@trixi_timeit timer() "update nhs" update_nhs!(semi, u_ode)
486+
if update_nhs
487+
@trixi_timeit timer() "update nhs" update_nhs!(semi, u_ode)
488+
end
486489

487490
# Second update step.
488491
# This is used to calculate density and pressure of the fluid systems
@@ -495,7 +498,9 @@ function update_systems_and_nhs(v_ode, u_ode, semi, t)
495498
update_quantities!(system, v, u, v_ode, u_ode, semi, t)
496499
end
497500

498-
update_implicit_sph!(semi, v_ode, u_ode, t)
501+
if update_implicit_sph
502+
update_implicit_sph!(semi, v_ode, u_ode, t)
503+
end
499504

500505
# Perform correction and pressure calculation
501506
foreach_system(semi) do system
@@ -507,11 +512,13 @@ function update_systems_and_nhs(v_ode, u_ode, semi, t)
507512

508513
# This update depends on the computed quantities of the fluid system and therefore
509514
# needs to be after `update_quantities!`.
510-
foreach_system(semi) do system
511-
v = wrap_v(v_ode, system, semi)
512-
u = wrap_u(u_ode, system, semi)
515+
if update_boundary_interpolation
516+
foreach_system(semi) do system
517+
v = wrap_v(v_ode, system, semi)
518+
u = wrap_u(u_ode, system, semi)
513519

514-
update_boundary_interpolation!(system, v, u, v_ode, u_ode, semi, t)
520+
update_boundary_interpolation!(system, v, u, v_ode, u_ode, semi, t)
521+
end
515522
end
516523

517524
# Final update step for all remaining systems
@@ -523,6 +530,15 @@ function update_systems_and_nhs(v_ode, u_ode, semi, t)
523530
end
524531
end
525532

533+
# Update the systems and neighborhood searches (NHS) for a simulation
534+
# before calling `interact!` to compute forces.
535+
function update_systems_and_nhs(v_ode, u_ode, semi, t)
536+
return update_systems!(v_ode, u_ode, semi, t;
537+
update_nhs=true,
538+
update_implicit_sph=true,
539+
update_boundary_interpolation=true)
540+
end
541+
526542
# The `SplitIntegrationCallback` overwrites `semi_wrap` to use a different
527543
# semidiscretization for wrapping arrays.
528544
# TODO `semi` is not used yet, but will be used when the source terms API is modified

0 commit comments

Comments
 (0)