Skip to content

Commit 7578733

Browse files
committed
Optimize kernel gradient
1 parent 663afdd commit 7578733

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

src/general/corrections.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ end
3535
# `rho_mean` is the mean density of the fluid, which is used to determine correction values near the free surface.
3636
# Return a tuple `(viscosity_correction, pressure_correction, surface_tension_correction)` representing the correction terms.
3737
@inline function free_surface_correction(correction::AkinciFreeSurfaceCorrection,
38-
particle_system, rho_mean)
38+
particle_system, rho_a, rho_b)
3939
# Equation 4 in ref
40+
rho_mean = (rho_a + rho_b) / 2
4041
k = correction.rho0 / rho_mean
4142

4243
# Viscosity, pressure, surface_tension
4344
return k, 1, k
4445
end
4546

46-
@inline function free_surface_correction(correction, particle_system, rho_mean)
47+
@inline function free_surface_correction(correction, particle_system, rho_a, rho_b)
4748
return 1, 1, 1
4849
end
4950

src/schemes/fluid/weakly_compressible_sph/rhs.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ function interact!(dv, v_particle_system, u_particle_system,
3232

3333
# In 3D, this function can combine velocity and density load into one wide load,
3434
# which gives a significant speedup on GPUs.
35-
v_a, rho_a = @inbounds velocity_and_density(v_particle_system, particle_system,
36-
particle)
35+
v_a,
36+
rho_a = @inbounds velocity_and_density(v_particle_system, particle_system,
37+
particle)
3738

3839
# Accumulate the RHS contributions over all neighbors before writing to `dv`,
3940
# to reduce the number of memory writes.
@@ -58,9 +59,9 @@ function interact!(dv, v_particle_system, u_particle_system,
5859

5960
# `foreach_neighbor` makes sure that `neighbor` is in bounds of `neighbor_system`
6061
m_b = @inbounds hydrodynamic_mass(neighbor_system, neighbor)
61-
v_b, rho_b = @inbounds velocity_and_density(v_neighbor_system, neighbor_system,
62-
neighbor)
63-
rho_mean = (rho_a + rho_b) / 2
62+
v_b,
63+
rho_b = @inbounds velocity_and_density(v_neighbor_system, neighbor_system,
64+
neighbor)
6465
vdiff = v_a - v_b
6566

6667
# The following call is equivalent to

0 commit comments

Comments
 (0)