Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixed kernel gradient #261

Merged
merged 106 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
57382e2
add gradient correction stuff
svchb Nov 1, 2023
81449fb
impl
svchb Nov 1, 2023
63f5ac9
up
svchb Nov 2, 2023
cfaf96c
finish impl
svchb Nov 2, 2023
4bf647e
update
svchb Nov 2, 2023
e937e15
fix testcases
svchb Nov 3, 2023
7c131db
fix
svchb Nov 3, 2023
1f53431
fix tests
svchb Nov 3, 2023
af8af78
format
svchb Nov 3, 2023
901d189
Merge branch 'main' into mixed-kernel-gradient
svchb Nov 3, 2023
182a872
working
svchb Nov 22, 2023
3cf34f4
format
svchb Nov 22, 2023
2e67efe
Merge branch 'main'
svchb Nov 22, 2023
027b1a4
format
svchb Nov 22, 2023
5f4a925
fix
svchb Nov 22, 2023
ad42394
working trixi_include
svchb Nov 24, 2023
8612c82
Merge branch 'main'
svchb Nov 24, 2023
09a1ea4
fix
svchb Nov 24, 2023
cadbbba
cleanup
svchb Nov 28, 2023
01a4173
format
svchb Nov 28, 2023
b506359
fix
svchb Nov 28, 2023
89cb149
fix tests
svchb Nov 28, 2023
f1537c4
Merge branch 'main'
svchb Nov 28, 2023
2cae13f
fix
svchb Nov 28, 2023
36ee614
Merge branch 'main' into mixed-kernel-gradient
svchb Nov 28, 2023
1cffc70
ups
svchb Nov 28, 2023
5d57d97
Merge branch 'mixed-kernel-gradient' of github.com:svchb/TrixiParticl…
svchb Nov 28, 2023
0e75ef2
typo
svchb Nov 28, 2023
2b03fe9
up
svchb Nov 29, 2023
1548433
fix
svchb Nov 30, 2023
ae78667
format
svchb Nov 30, 2023
54e7c16
update fix errors
svchb Dec 4, 2023
47ed721
fix
svchb Dec 5, 2023
57c55f1
update
svchb Dec 6, 2023
76aefea
up
svchb Dec 6, 2023
5c4d20d
fix tests
svchb Dec 6, 2023
c7976f9
fix tests
svchb Dec 6, 2023
aa66268
np
svchb Dec 6, 2023
369cbc9
remove comment
svchb Dec 6, 2023
7799f62
revert some changes
svchb Dec 6, 2023
d7932ca
up
svchb Dec 6, 2023
cc075f5
Merge branch 'main'
svchb Dec 6, 2023
e5e1ed9
up
svchb Dec 6, 2023
001668a
Merge branch 'main' into mixed-kernel-gradient
svchb Dec 6, 2023
40c567f
update
svchb Dec 7, 2023
95dcc62
format
svchb Dec 7, 2023
c8a67e7
Merge branch 'mixed-kernel-gradient' of github.com:svchb/TrixiParticl…
svchb Dec 7, 2023
30f7c32
cleanup
svchb Dec 7, 2023
ac76b86
revert
svchb Dec 7, 2023
67ea62d
revert
svchb Dec 7, 2023
ae6b3eb
implement correction on wall
svchb Dec 11, 2023
057adbe
fix tests
svchb Dec 11, 2023
bc9b87e
fix pressure_acceleration for summation
svchb Dec 12, 2023
21b83d5
format
svchb Dec 12, 2023
96b18c9
revert
svchb Dec 13, 2023
10d1a47
fix
svchb Dec 13, 2023
ca7f106
Merge branch 'main'
svchb Dec 13, 2023
7126cce
fixes
svchb Dec 13, 2023
f5469da
fix
svchb Dec 13, 2023
47f824d
fix pressure_acceleration dispatches
svchb Dec 14, 2023
3af1309
typo
svchb Dec 14, 2023
1b5d137
fix
svchb Dec 14, 2023
acafbe1
rename
svchb Dec 14, 2023
6ae8528
Merge branch 'main' into mixed-kernel-gradient
svchb Dec 22, 2023
1e47bc9
Merge branch 'main' into mixed-kernel-gradient
svchb Jan 2, 2024
d9d9562
some review fixes
svchb Jan 3, 2024
be802d4
review
svchb Jan 3, 2024
9278edb
more fixes
svchb Jan 3, 2024
f54c891
add solid system type
svchb Jan 3, 2024
3ed56be
review
svchb Jan 3, 2024
72d293f
fix tlsph call
svchb Jan 3, 2024
7b0c438
fix comment
svchb Jan 3, 2024
1a4803c
review
svchb Jan 3, 2024
3aea7ae
review
svchb Jan 3, 2024
2316101
format
svchb Jan 3, 2024
b4c3ad6
review
svchb Jan 3, 2024
2ab5853
move
svchb Jan 3, 2024
49b72f3
fix doc
svchb Jan 3, 2024
e2b9574
review fix
svchb Jan 3, 2024
148c0e9
more review
svchb Jan 3, 2024
2c86a03
review fix
svchb Jan 4, 2024
54b3fa0
format
svchb Jan 4, 2024
26e90b1
change parameter list
svchb Jan 4, 2024
824a054
reorder params
svchb Jan 4, 2024
76a5673
Merge branch 'main' into mixed-kernel-gradient
svchb Jan 4, 2024
390e0ed
format
svchb Jan 4, 2024
b3d3924
fix
svchb Jan 4, 2024
33ce59a
fix
svchb Jan 4, 2024
3346c63
Merge branch 'mixed-kernel-gradient' of github.com:svchb/TrixiParticl…
svchb Jan 4, 2024
22a6ff5
fix
svchb Jan 4, 2024
40805b5
remove dispatched functions
svchb Jan 4, 2024
ea17c79
format
svchb Jan 4, 2024
9e162ca
fix comments
svchb Jan 4, 2024
ae069d2
fix
svchb Jan 4, 2024
8fb3323
remove system
svchb Jan 4, 2024
c5803fd
format
svchb Jan 4, 2024
4f5223f
change parameter list
svchb Jan 4, 2024
111c53c
review
svchb Jan 4, 2024
be15f26
unused variable
svchb Jan 4, 2024
7886cf9
break
svchb Jan 4, 2024
2a332b9
edit todo
svchb Jan 4, 2024
240f1c8
remove breaks
svchb Jan 4, 2024
0b98a52
format
svchb Jan 4, 2024
2e6fcd7
Merge branch 'main' into mixed-kernel-gradient
svchb Jan 4, 2024
451f3d4
rename grad_kernel to W_a
svchb Jan 5, 2024
1c152c9
Merge branch 'mixed-kernel-gradient' of github.com:svchb/TrixiParticl…
svchb Jan 5, 2024
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
2 changes: 1 addition & 1 deletion examples/fluid/dam_break_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ smoothing_kernel = WendlandC2Kernel{2}()
fluid_density_calculator = ContinuityDensity()
viscosity = ArtificialViscosityMonaghan(alpha=0.02, beta=0.0)
density_diffusion = DensityDiffusionMolteniColagrossi(delta=0.1)
#density_diffusion = DensityDiffusionAntuono(tank.fluid, delta=0.1)
# density_diffusion = DensityDiffusionAntuono(tank.fluid, delta=0.1)

fluid_system = WeaklyCompressibleSPHSystem(tank.fluid, fluid_density_calculator,
state_equation, smoothing_kernel,
Expand Down
2 changes: 1 addition & 1 deletion examples/fluid/dam_break_2d_corrections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ particle_spacing = 0.05
tspan = (0.0, 5.7 / sqrt(9.81))

correction_dict = Dict(
"no_correction" => Nothing(),
"no_correction" => nothing,
"shepard_kernel_correction" => ShepardKernelCorrection(),
"akinci_free_surf_correction" => AkinciFreeSurfaceCorrection(fluid_density),
"kernel_gradient_summation_correction" => KernelCorrection(),
Expand Down
28 changes: 10 additions & 18 deletions src/general/corrections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ struct BlendedGradientCorrection{ELTYPE <: Real}
end
end

# called by DensityDiffusion and TLSPH
# Called only by DensityDiffusion and TLSPH
function compute_gradient_correction_matrix!(corr_matrix, neighborhood_search,
system, coordinates, density_fun)
(; mass) = system
Expand Down Expand Up @@ -393,7 +393,7 @@ function compute_gradient_correction_matrix!(corr_matrix, neighborhood_search,
end

function compute_gradient_correction_matrix!(corr_matrix::AbstractArray, system,
coordinates, u_ode, v_ode, semi,
coordinates, v_ode, u_ode, semi,
correction, smoothing_length, smoothing_kernel)
set_zero!(corr_matrix)

Expand Down Expand Up @@ -448,20 +448,6 @@ function compute_gradient_correction_matrix!(corr_matrix::AbstractArray, system,
end

function correction_matrix_inversion_step!(corr_matrix, system)
@inline function invert(inverse, A, particle, system)
A_inv = inv(A)
@inbounds for j in 1:ndims(system), i in 1:ndims(system)
inverse[i, j, particle] = A_inv[i, j]
end
end

@inline function pseudo_invert(inverse, A, particle, system)
A_inv = pinv(A)
@inbounds for j in 1:ndims(system), i in 1:ndims(system)
inverse[i, j, particle] = A_inv[i, j]
end
end

@threaded for particle in eachparticle(system)
L = extract_smatrix(corr_matrix, system, particle)
norm_ = norm(L)
Expand All @@ -481,9 +467,15 @@ function correction_matrix_inversion_step!(corr_matrix, system)

det_ = abs(det(L))
@fastmath if det_ < 1e-6 * norm_
pseudo_invert(corr_matrix, L, particle, system)
L_inv = pinv(L)
@inbounds for j in 1:ndims(system), i in 1:ndims(system)
corr_matrix[i, j, particle] = L_inv[i, j]
end
continue
end
svchb marked this conversation as resolved.
Show resolved Hide resolved
invert(corr_matrix, L, particle, system)
L_inv = inv(L)
@inbounds for j in 1:ndims(system), i in 1:ndims(system)
corr_matrix[i, j, particle] = L_inv[i, j]
end
end
end
3 changes: 0 additions & 3 deletions src/general/general.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
abstract type System{NDIMS} end

# WCSPH EDAC
abstract type FluidSystem{NDIMS} <: System{NDIMS} end

# TLSPH
abstract type SolidSystem{NDIMS} <: System{NDIMS} end

# all Boundary Condition Systems
abstract type BoundarySystem{NDIMS} <: System{NDIMS} end
svchb marked this conversation as resolved.
Show resolved Hide resolved

timer_name(::FluidSystem) = "fluid"
Expand Down
19 changes: 10 additions & 9 deletions src/schemes/boundary/dummy_particles/dummy_particles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,12 @@ end
GradientCorrection,
BlendedGradientCorrection,
MixedKernelGradientCorrection})
W_b = smoothing_kernel_grad(neighbor_system, -pos_diff, distance, neighbor)

# Use `p_a` as pressure for both particles with `PressureMirroring`
return pressure_acceleration_asymmetric(pressure_correction, m_b, p_a, p_a,
rho_a, rho_b, pos_diff, distance, grad_kernel,
svchb marked this conversation as resolved.
Show resolved Hide resolved
particle_system, neighbor, neighbor_system,
fluid_density_calculator)
W_b, fluid_density_calculator)
end

@inline function pressure_acceleration_bnd(pressure_correction, m_b, p_a, p_b,
Expand All @@ -326,10 +326,11 @@ end
GradientCorrection,
BlendedGradientCorrection,
MixedKernelGradientCorrection})
W_b = smoothing_kernel_grad(neighbor_system, -pos_diff, distance, neighbor)

return pressure_acceleration_asymmetric(pressure_correction, m_b, p_a, p_b,
rho_a, rho_b, pos_diff, distance, grad_kernel,
particle_system, neighbor, neighbor_system,
fluid_density_calculator)
W_b, fluid_density_calculator)
end

@inline function particle_density(v, model::BoundaryModelDummyParticles, system, particle)
Expand Down Expand Up @@ -375,8 +376,8 @@ end
compute_correction_values!(system,
correction, v, u, v_ode, u_ode, semi, density_calculator)

compute_gradient_correction_matrix!(correction, boundary_model, system, u, u_ode,
v_ode, semi)
compute_gradient_correction_matrix!(correction, boundary_model, system, u, v_ode, u_ode,
semi)

# `kernel_correct_density!` only performed for `SummationDensity`
kernel_correct_density!(boundary_model, v, u, v_ode, u_ode, semi, correction,
Expand All @@ -398,22 +399,22 @@ function kernel_correct_density!(boundary_model, v, u, v_ode, u_ode, semi,
end

function compute_gradient_correction_matrix!(correction, boundary_model, system, u,
u_ode, v_ode, semi)
v_ode, u_ode, semi)
return system
end

function compute_gradient_correction_matrix!(corr::Union{GradientCorrection,
BlendedGradientCorrection,
MixedKernelGradientCorrection},
boundary_model,
system, u, u_ode, v_ode, semi)
system, u, v_ode, u_ode, semi)
(; cache, correction, smoothing_kernel, smoothing_length) = boundary_model
(; correction_matrix) = cache

system_coords = current_coordinates(u, system)

compute_gradient_correction_matrix!(correction_matrix, system, system_coords,
u_ode, v_ode, semi, correction, smoothing_length,
v_ode, u_ode, semi, correction, smoothing_length,
smoothing_kernel)
end

Expand Down
38 changes: 20 additions & 18 deletions src/schemes/fluid/weakly_compressible_sph/rhs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ end
density_calculator,
correction)

# By default, just call the pressure acceleration formulation corresponding to the density calculator
# Without correction, the kernel gradient is symmetric, so call the symmetric
# pressure acceleration formulation corresponding to the density calculator.
return pressure_acceleration_symmetric(pressure_correction, m_b, p_a, p_b, rho_a, rho_b,
grad_kernel, density_calculator)
end
Expand All @@ -91,22 +92,24 @@ end
GradientCorrection,
BlendedGradientCorrection,
MixedKernelGradientCorrection})
W_b = smoothing_kernel_grad(neighbor_system, -pos_diff, distance, neighbor)

# By default, just call the pressure acceleration formulation corresponding to a locally corrected gradient
# With correction, the kernel gradient is not necessarily symmetric, so call the
# asymmetric pressure acceleration formulation corresponding to the density calculator.
return pressure_acceleration_asymmetric(pressure_correction, m_b, p_a, p_b,
rho_a, rho_b, pos_diff, distance, grad_kernel,
particle_system, neighbor,
neighbor_system, density_calculator)
W_b, density_calculator)
end

# As shown in "Variational and momentum preservation aspects of Smooth Particle Hydrodynamic
# formulations" by Bonet and Lok (1999), for a consistent formulation this form has to be
# used with `ContinuityDensity` with the formulation `\rho_a * \sum m_b / \rho_b ...`.
# This can also be seen in the tests for total energy conservation, which fail with the
# other `pressure_acceleration` form.
# We assume symmetry of the kernel gradient in this formulation. See below for the
# asymmetric version.
@inline function pressure_acceleration_symmetric(pressure_correction, m_b, p_a, p_b, rho_a,
rho_b,
grad_kernel, ::ContinuityDensity)
rho_b, grad_kernel, ::ContinuityDensity)
return (-m_b * (p_a + p_b) / (rho_a * rho_b) * grad_kernel) * pressure_correction
end

Expand All @@ -115,28 +118,27 @@ end
# used with `SummationDensity`.
# This can also be seen in the tests for total energy conservation, which fail with the
# other `pressure_acceleration` form.
# We assume symmetry of the kernel gradient in this formulation. See below for the
# asymmetric version.
@inline function pressure_acceleration_symmetric(pressure_correction, m_b, p_a, p_b, rho_a,
rho_b,
grad_kernel, ::SummationDensity)
rho_b, grad_kernel, ::SummationDensity)
return (-m_b * (p_a / rho_a^2 + p_b / rho_b^2) * grad_kernel) * pressure_correction
end

# Same as above, but not assuming symmetry of the kernel gradient. To be used with
# corrections that do not produce a symmetric kernel gradient.
@inline function pressure_acceleration_asymmetric(pressure_correction, m_b, p_a, p_b,
svchb marked this conversation as resolved.
Show resolved Hide resolved
rho_a, rho_b, pos_diff, distance, W_a,
svchb marked this conversation as resolved.
Show resolved Hide resolved
particle_system, neighbor,
neighbor_system, ::SummationDensity)
W_b = smoothing_kernel_grad(neighbor_system, -pos_diff, distance, neighbor)

return (-m_b * (p_a / rho_a^2 * W_a - p_b / rho_b^2 * W_b)) * pressure_correction
W_b, ::ContinuityDensity)
return -m_b / (rho_a * rho_b) * (p_a * W_a - p_b * W_b) * pressure_correction
end

# Same as above, but not assuming symmetry of the kernel gradient. To be used with
# corrections that do not produce a symmetric kernel gradient.
@inline function pressure_acceleration_asymmetric(pressure_correction, m_b, p_a, p_b,
rho_a, rho_b, pos_diff, distance, W_a,
particle_system, neighbor,
neighbor_system, ::ContinuityDensity)
W_b = smoothing_kernel_grad(neighbor_system, -pos_diff, distance, neighbor)

return -m_b / (rho_a * rho_b) * (p_a * W_a - p_b * W_b) * pressure_correction
W_b, ::SummationDensity)
return (-m_b * (p_a / rho_a^2 * W_a - p_b / rho_b^2 * W_b)) * pressure_correction
end

# With 'SummationDensity', density is calculated in wcsph/system.jl:compute_density!
Expand Down
8 changes: 4 additions & 4 deletions src/schemes/fluid/weakly_compressible_sph/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function update_pressure!(system::WeaklyCompressibleSPHSystem, v, u, v_ode, u_od
compute_correction_values!(system,
correction, v, u, v_ode, u_ode, semi, density_calculator)

compute_gradient_correction_matrix!(correction, system, u, u_ode, v_ode, semi)
compute_gradient_correction_matrix!(correction, system, u, v_ode, u_ode, semi)

# `kernel_correct_density!` only performed for `SummationDensity`
kernel_correct_density!(system, v, u, v_ode, u_ode, semi, correction,
Expand All @@ -225,22 +225,22 @@ end

function compute_gradient_correction_matrix!(correction,
system::WeaklyCompressibleSPHSystem, u,
u_ode, v_ode, semi)
v_ode, u_ode, semi)
return system
end

function compute_gradient_correction_matrix!(corr::Union{GradientCorrection,
BlendedGradientCorrection,
MixedKernelGradientCorrection},
system::WeaklyCompressibleSPHSystem, u,
u_ode, v_ode, semi)
v_ode, u_ode, semi)
(; cache, correction, smoothing_kernel, smoothing_length) = system
(; correction_matrix) = cache

system_coords = current_coordinates(u, system)

compute_gradient_correction_matrix!(correction_matrix, system, system_coords,
u_ode, v_ode, semi, correction, smoothing_length,
v_ode, u_ode, semi, correction, smoothing_length,
smoothing_kernel)
end

Expand Down
11 changes: 5 additions & 6 deletions src/schemes/solid/total_lagrangian_sph/rhs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ function interact!(dv, v_particle_system, u_particle_system,
grad_kernel = smoothing_kernel_grad(particle_system, pos_diff, distance)

# use `m_a` to get the same viscosity as for the fluid-solid direction.
dv_viscosity = viscosity(neighbor_system, particle_system,
v_neighbor_system, v_particle_system,
neighbor, particle,
pos_diff, distance, sound_speed, m_b, m_a, rho_mean)
dv_viscosity = viscosity(neighbor_system, particle_system, v_neighbor_system,
v_particle_system, neighbor, particle, pos_diff, distance,
sound_speed, m_b, m_a, rho_mean)

# In fluid-solid interaction, use the "hydrodynamic pressure" of the solid particles
# corresponding to the chosen boundary model.
Expand All @@ -104,9 +103,9 @@ function interact!(dv, v_particle_system, u_particle_system,
# Boundary forces
# Note: neighbor and particle pressure are switched in this call
# and `pressure_correction` is set to `1.0` (no correction)
dv_boundary = pressure_acceleration(1.0, m_b, p_b, p_a,
dv_boundary = pressure_acceleration(1.0, m_a, p_b, p_a,
rho_b, rho_a, pos_diff, distance, grad_kernel,
particle_system, neighbor, neighbor_system,
neighbor_system, neighbor, particle_system,
density_calculator, correction)
dv_particle = dv_boundary + dv_viscosity

Expand Down
22 changes: 7 additions & 15 deletions src/schemes/solid/total_lagrangian_sph/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,14 @@ struct TotalLagrangianSPHSystem{BM, NDIMS, ELTYPE <: Real, K, PF} <: SolidSystem
((1 + poisson_ratio) * (1 - 2 * poisson_ratio))
lame_mu = 0.5 * young_modulus / (1 + poisson_ratio)

return new{typeof(boundary_model),
NDIMS, ELTYPE,
return new{typeof(boundary_model), NDIMS, ELTYPE,
typeof(smoothing_kernel),
typeof(penalty_force)}(initial_condition,
initial_coordinates,
current_coordinates, mass,
correction_matrix,
pk1_corrected,
deformation_grad,
material_density,
n_moving_particles,
young_modulus, poisson_ratio,
lame_lambda, lame_mu,
smoothing_kernel,
smoothing_length,
acceleration_, boundary_model,
typeof(penalty_force)}(initial_condition, initial_coordinates,
current_coordinates, mass, correction_matrix,
pk1_corrected, deformation_grad, material_density,
n_moving_particles, young_modulus, poisson_ratio,
lame_lambda, lame_mu, smoothing_kernel,
smoothing_length, acceleration_, boundary_model,
penalty_force)
end
end
Expand Down
Loading