Skip to content

Commit 3a5900a

Browse files
efaulhabersvchbLasNikas
authored
Make dv_shifting, surface_tension_force and adhesion_force inplace (#1124)
* Make `dv_shifting`, `surface_tension_force` and `adhesion_force` inplace * Move free surface correction into the function * Fix --------- Co-authored-by: Sven Berger <berger.sven@gmail.com> Co-authored-by: Niklas Neher <73897120+LasNikas@users.noreply.github.com>
1 parent 155f9f1 commit 3a5900a

File tree

7 files changed

+172
-138
lines changed

7 files changed

+172
-138
lines changed

src/io/write_vtk.jl

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -350,18 +350,13 @@ function write2vtk!(vtk, v, u, t, system::AbstractFluidSystem)
350350
rho_b = current_density(v, system, neighbor)
351351
grad_kernel = smoothing_kernel_grad(system, pos_diff, distance, particle)
352352

353-
surface_tension[1:ndims(system),
354-
particle] .+= surface_tension_force(surface_tension_a,
355-
surface_tension_b,
356-
system,
357-
system,
358-
particle,
359-
neighbor,
360-
pos_diff,
361-
distance,
362-
rho_a,
363-
rho_b,
364-
grad_kernel)
353+
dv_surface_tension = Ref(zero(pos_diff))
354+
surface_tension_force!(dv_surface_tension,
355+
surface_tension_a, surface_tension_b,
356+
system, system, particle, neighbor,
357+
pos_diff, distance, rho_a, rho_b, grad_kernel, 1)
358+
359+
surface_tension[1:ndims(system), particle] .+= dv_surface_tension[]
365360
end
366361
vtk["surface_tension"] = surface_tension
367362

src/schemes/fluid/entropically_damped_sph/rhs.jl

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,27 @@ function interact!(dv, v_particle_system, u_particle_system,
5252
sound_speed, m_a, m_b, rho_a, rho_b,
5353
grad_kernel)
5454

55-
# Extra terms in the momentum equation when using a shifting technique
56-
dv_tvf = @inbounds dv_shifting(shifting_technique(particle_system),
57-
particle_system, neighbor_system,
58-
v_particle_system, v_neighbor_system,
59-
particle, neighbor, m_a, m_b, rho_a, rho_b,
60-
pos_diff, distance, grad_kernel, correction)
61-
62-
dv_surface_tension = surface_tension_force(surface_tension_a, surface_tension_b,
63-
particle_system, neighbor_system,
64-
particle, neighbor, pos_diff, distance,
65-
rho_a, rho_b, grad_kernel)
55+
dv_particle = Ref(dv_pressure + dv_viscosity_)
6656

67-
dv_adhesion = adhesion_force(surface_tension_a, particle_system, neighbor_system,
68-
particle, neighbor, pos_diff, distance)
69-
70-
dv_particle = dv_pressure + dv_viscosity_ + dv_tvf + dv_surface_tension +
71-
dv_adhesion
57+
# Extra terms in the momentum equation when using a shifting technique
58+
@inbounds dv_shifting!(dv_particle, shifting_technique(particle_system),
59+
particle_system, neighbor_system,
60+
v_particle_system, v_neighbor_system,
61+
particle, neighbor, m_a, m_b, rho_a, rho_b,
62+
pos_diff, distance, grad_kernel, correction)
63+
64+
@inbounds surface_tension_force!(dv_particle, surface_tension_a,
65+
surface_tension_b,
66+
particle_system, neighbor_system,
67+
particle, neighbor, pos_diff, distance,
68+
rho_a, rho_b, grad_kernel, 1)
69+
70+
@inbounds adhesion_force!(dv_particle, surface_tension_a, particle_system,
71+
neighbor_system,
72+
particle, neighbor, pos_diff, distance)
7273

7374
for i in 1:ndims(particle_system)
74-
@inbounds dv[i, particle] += dv_particle[i]
75+
@inbounds dv[i, particle] += dv_particle[][i]
7576
end
7677

7778
v_diff = current_velocity(v_particle_system, particle_system, particle) -

src/schemes/fluid/shifting_techniques.jl

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ function update_shifting!(system, shifting, v, u, v_ode, u_ode, semi)
4141
end
4242

4343
# Additional term in the momentum equation due to the shifting technique
44-
@inline function dv_shifting(shifting, system, neighbor_system,
45-
v_system, v_neighbor_system, particle, neighbor,
46-
m_a, m_b, rho_a, rho_b, pos_diff, distance,
47-
grad_kernel, correction)
48-
return zero(grad_kernel)
44+
@inline function dv_shifting!(dv_particle, shifting, system, neighbor_system,
45+
v_system, v_neighbor_system, particle, neighbor,
46+
m_a, m_b, rho_a, rho_b, pos_diff, distance,
47+
grad_kernel, correction)
48+
return dv_particle
4949
end
5050

5151
# Additional term(s) in the continuity equation due to the shifting technique
@@ -324,31 +324,35 @@ See [`ParticleShiftingTechnique`](@ref).
324324
struct MomentumEquationTermSun2019 end
325325

326326
# Additional term in the momentum equation due to the shifting technique
327-
@propagate_inbounds function dv_shifting(shifting::ParticleShiftingTechnique, system,
328-
neighbor_system,
329-
v_system, v_neighbor_system, particle, neighbor,
330-
m_a, m_b, rho_a, rho_b, pos_diff, distance,
331-
grad_kernel, correction)
332-
return dv_shifting(shifting.momentum_equation_term, system, neighbor_system,
333-
v_system, v_neighbor_system, particle, neighbor,
334-
m_a, m_b, rho_a, rho_b, pos_diff, distance,
335-
grad_kernel, correction)
327+
@propagate_inbounds function dv_shifting!(dv_particle,
328+
shifting::ParticleShiftingTechnique,
329+
system, neighbor_system,
330+
v_system, v_neighbor_system, particle, neighbor,
331+
m_a, m_b, rho_a, rho_b, pos_diff, distance,
332+
grad_kernel, correction)
333+
return dv_shifting!(dv_particle, shifting.momentum_equation_term, system,
334+
neighbor_system, v_system, v_neighbor_system,
335+
particle, neighbor, m_a, m_b, rho_a, rho_b,
336+
pos_diff, distance, grad_kernel, correction)
336337
end
337338

338-
@propagate_inbounds function dv_shifting(::MomentumEquationTermSun2019,
339-
system, neighbor_system,
340-
v_system, v_neighbor_system,
341-
particle, neighbor, m_a, m_b, rho_a, rho_b,
342-
pos_diff, distance, grad_kernel, correction)
339+
@propagate_inbounds function dv_shifting!(dv_particle, ::MomentumEquationTermSun2019,
340+
system, neighbor_system,
341+
v_system, v_neighbor_system,
342+
particle, neighbor, m_a, m_b, rho_a, rho_b,
343+
pos_diff, distance, grad_kernel, correction)
343344
delta_v_a = delta_v(system, particle)
344345
delta_v_b = delta_v(neighbor_system, neighbor)
345346

346347
v_a = current_velocity(v_system, system, particle)
347348
v_b = current_velocity(v_neighbor_system, neighbor_system, neighbor)
348349

349350
tensor_product = v_a * delta_v_a' + v_b * delta_v_b'
350-
return m_b / rho_b *
351-
(tensor_product * grad_kernel + v_a * dot(delta_v_a - delta_v_b, grad_kernel))
351+
dv_particle[] += m_b / rho_b *
352+
(tensor_product * grad_kernel +
353+
v_a * dot(delta_v_a - delta_v_b, grad_kernel))
354+
355+
return dv_particle
352356
end
353357

354358
# `ParticleShiftingTechnique{<:Any, <:Any, true}` means `modify_continuity_equation=true`
@@ -568,10 +572,11 @@ struct TransportVelocityAdami{modify_continuity_equation, T <: Real} <:
568572
end
569573
end
570574

571-
@propagate_inbounds function dv_shifting(::TransportVelocityAdami, system, neighbor_system,
572-
v_system, v_neighbor_system, particle, neighbor,
573-
m_a, m_b, rho_a, rho_b, pos_diff, distance,
574-
grad_kernel, correction)
575+
@propagate_inbounds function dv_shifting!(dv_particle, ::TransportVelocityAdami,
576+
system, neighbor_system,
577+
v_system, v_neighbor_system, particle, neighbor,
578+
m_a, m_b, rho_a, rho_b, pos_diff, distance,
579+
grad_kernel, correction)
575580
v_a = current_velocity(v_system, system, particle)
576581
delta_v_a = delta_v(system, particle)
577582

@@ -588,9 +593,11 @@ end
588593
# m_b * (A_a + A_b) / (ρ_a * ρ_b) * ∇W_ab.
589594
# In order to obtain this, we pass `p_a = A_a` and `p_b = A_b` to the
590595
# `pressure_acceleration` function.
591-
return pressure_acceleration(system, neighbor_system, particle, neighbor,
592-
m_a, m_b, A_a, A_b, rho_a, rho_b, pos_diff,
593-
distance, grad_kernel, correction)
596+
dv_particle[] += pressure_acceleration(system, neighbor_system, particle, neighbor,
597+
m_a, m_b, A_a, A_b, rho_a, rho_b,
598+
pos_diff, distance, grad_kernel, correction)
599+
600+
return dv_particle
594601
end
595602

596603
# The function above misuses the pressure acceleration function by passing a Matrix as `p_a`.

0 commit comments

Comments
 (0)