-
Notifications
You must be signed in to change notification settings - Fork 12
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
Move viscosity to boundary sph system #564
Closed
Closed
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
d681053
Add Viscosity Moris
svchb c2150fc
format
svchb 67708f2
fix
svchb 4ccea65
Merge branch 'main' into add_nu
svchb fcc3596
implement suggestions
svchb be1cf13
other suggestions
svchb 69721d0
fix equation
svchb e948561
format
svchb 1384c30
review comments
svchb 06a3fdd
fixes
svchb 2575ad1
fix
svchb 2f4e20c
update test
svchb f182363
update
svchb b5dd785
Merge branch 'main' into add_nu
svchb 25f7f2b
fix open boundary
svchb cc899b8
update reference files
svchb afc1aaf
update validation criteria
svchb a05975e
update reference file
svchb aa74848
new reference files
svchb 5862bc0
ups
svchb 5e7f9b0
update ref file
svchb 4e9bb1b
update validation error bounds
svchb 5106260
update error bound
svchb f14a239
update error bound
svchb d712791
add comment and correct setting of 'v'
svchb 4528915
Merge branch 'main' into add_nu
svchb be3849d
move viscosity to boundarysphsys
svchb dc1a930
format
svchb 45e713b
Merge remote-tracking branch 'refs/remotes/upstream/main'
svchb 387ed0a
bla
svchb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,7 +1,7 @@ | ||||||||||||||||||
@doc raw""" | ||||||||||||||||||
BoundaryModelDummyParticles(initial_density, hydrodynamic_mass, | ||||||||||||||||||
density_calculator, smoothing_kernel, | ||||||||||||||||||
smoothing_length; viscosity=nothing, | ||||||||||||||||||
smoothing_length; | ||||||||||||||||||
state_equation=nothing, correction=nothing) | ||||||||||||||||||
|
||||||||||||||||||
`boundary_model` for `BoundarySPHSystem`. | ||||||||||||||||||
|
@@ -12,15 +12,11 @@ | |||||||||||||||||
See description above for more information. | ||||||||||||||||||
- `density_calculator`: Strategy to compute the hydrodynamic density of the boundary particles. | ||||||||||||||||||
See description below for more information. | ||||||||||||||||||
- `smoothing_kernel`: Smoothing kernel should be the same as for the adjacent fluid system. | ||||||||||||||||||
- `smoothing_length`: Smoothing length should be the same as for the adjacent fluid system. | ||||||||||||||||||
|
||||||||||||||||||
# Keywords | ||||||||||||||||||
- `state_equation`: This should be the same as for the adjacent fluid system | ||||||||||||||||||
(see e.g. [`StateEquationCole`](@ref)). | ||||||||||||||||||
- `correction`: Correction method of the adjacent fluid system (see [Corrections](@ref corrections)). | ||||||||||||||||||
- `viscosity`: Slip (default) or no-slip condition. See description below for further | ||||||||||||||||||
information. | ||||||||||||||||||
|
||||||||||||||||||
# Examples | ||||||||||||||||||
```jldoctest; output = false, setup = :(densities = [1.0, 2.0, 3.0]; masses = [0.1, 0.2, 0.3]; smoothing_kernel = SchoenbergCubicSplineKernel{2}(); smoothing_length = 0.1) | ||||||||||||||||||
|
@@ -30,21 +26,19 @@ boundary_model = BoundaryModelDummyParticles(densities, masses, AdamiPressureExt | |||||||||||||||||
|
||||||||||||||||||
# No-slip condition | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This example doesn't make sense anymore. |
||||||||||||||||||
boundary_model = BoundaryModelDummyParticles(densities, masses, AdamiPressureExtrapolation(), | ||||||||||||||||||
smoothing_kernel, smoothing_length, | ||||||||||||||||||
viscosity=ViscosityAdami(nu=1e-6)) | ||||||||||||||||||
smoothing_kernel, smoothing_length) | ||||||||||||||||||
|
||||||||||||||||||
# output | ||||||||||||||||||
BoundaryModelDummyParticles(AdamiPressureExtrapolation, ViscosityAdami) | ||||||||||||||||||
BoundaryModelDummyParticles(AdamiPressureExtrapolation) | ||||||||||||||||||
``` | ||||||||||||||||||
""" | ||||||||||||||||||
struct BoundaryModelDummyParticles{DC, ELTYPE <: Real, VECTOR, SE, K, V, COR, C} | ||||||||||||||||||
struct BoundaryModelDummyParticles{DC, ELTYPE <: Real, VECTOR, SE, K, COR, C} | ||||||||||||||||||
pressure :: VECTOR # Vector{ELTYPE} | ||||||||||||||||||
hydrodynamic_mass :: VECTOR # Vector{ELTYPE} | ||||||||||||||||||
state_equation :: SE | ||||||||||||||||||
density_calculator :: DC | ||||||||||||||||||
smoothing_kernel :: K | ||||||||||||||||||
smoothing_length :: ELTYPE | ||||||||||||||||||
viscosity :: V | ||||||||||||||||||
correction :: COR | ||||||||||||||||||
cache :: C | ||||||||||||||||||
end | ||||||||||||||||||
|
@@ -53,23 +47,20 @@ end | |||||||||||||||||
# See the comments in general/gpu.jl for more details. | ||||||||||||||||||
function BoundaryModelDummyParticles(initial_density, hydrodynamic_mass, | ||||||||||||||||||
density_calculator, smoothing_kernel, | ||||||||||||||||||
smoothing_length; viscosity=nothing, | ||||||||||||||||||
smoothing_length; | ||||||||||||||||||
state_equation=nothing, correction=nothing) | ||||||||||||||||||
pressure = initial_boundary_pressure(initial_density, density_calculator, | ||||||||||||||||||
state_equation) | ||||||||||||||||||
NDIMS = ndims(smoothing_kernel) | ||||||||||||||||||
|
||||||||||||||||||
n_particles = length(initial_density) | ||||||||||||||||||
|
||||||||||||||||||
cache = (; create_cache_model(viscosity, n_particles, NDIMS)..., | ||||||||||||||||||
create_cache_model(initial_density, density_calculator)...) | ||||||||||||||||||
cache = (; create_cache_model(correction, initial_density, NDIMS, | ||||||||||||||||||
n_particles)..., cache...) | ||||||||||||||||||
cache = (; create_cache_model(initial_density, density_calculator)..., | ||||||||||||||||||
create_cache_model(correction, initial_density, NDIMS, n_particles)...) | ||||||||||||||||||
|
||||||||||||||||||
return BoundaryModelDummyParticles(pressure, hydrodynamic_mass, | ||||||||||||||||||
state_equation, density_calculator, | ||||||||||||||||||
smoothing_kernel, smoothing_length, | ||||||||||||||||||
viscosity, correction, cache) | ||||||||||||||||||
return BoundaryModelDummyParticles(pressure, hydrodynamic_mass, state_equation, | ||||||||||||||||||
density_calculator, smoothing_kernel, | ||||||||||||||||||
smoothing_length, correction, cache) | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
@doc raw""" | ||||||||||||||||||
|
@@ -146,36 +137,11 @@ function create_cache_model(initial_density, ::AdamiPressureExtrapolation) | |||||||||||||||||
return (; density, volume) | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
function create_cache_model(viscosity::Nothing, n_particles, n_dims) | ||||||||||||||||||
return (;) | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
function create_cache_model(viscosity, n_particles, n_dims) | ||||||||||||||||||
ELTYPE = eltype(viscosity.epsilon) | ||||||||||||||||||
|
||||||||||||||||||
wall_velocity = zeros(ELTYPE, n_dims, n_particles) | ||||||||||||||||||
|
||||||||||||||||||
return (; wall_velocity) | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
@inline reset_cache!(cache, viscosity) = set_zero!(cache.volume) | ||||||||||||||||||
|
||||||||||||||||||
function reset_cache!(cache, viscosity::ViscosityAdami) | ||||||||||||||||||
(; volume, wall_velocity) = cache | ||||||||||||||||||
|
||||||||||||||||||
set_zero!(volume) | ||||||||||||||||||
set_zero!(wall_velocity) | ||||||||||||||||||
|
||||||||||||||||||
return cache | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
function Base.show(io::IO, model::BoundaryModelDummyParticles) | ||||||||||||||||||
@nospecialize model # reduce precompilation time | ||||||||||||||||||
|
||||||||||||||||||
print(io, "BoundaryModelDummyParticles(") | ||||||||||||||||||
print(io, model.density_calculator |> typeof |> nameof) | ||||||||||||||||||
print(io, ", ") | ||||||||||||||||||
print(io, model.viscosity |> typeof |> nameof) | ||||||||||||||||||
print(io, ")") | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -306,15 +272,22 @@ end | |||||||||||||||||
boundary_model.pressure[particle] = max(boundary_model.state_equation(density), 0.0) | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
reset_wall_velocity!(viscosity, system) = system | ||||||||||||||||||
|
||||||||||||||||||
@inline function reset_wall_velocity!(viscosity::ViscosityAdami, system) | ||||||||||||||||||
set_zero!(system.cache.wall_velocity) | ||||||||||||||||||
return system.cache | ||||||||||||||||||
end | ||||||||||||||||||
Comment on lines
+277
to
+280
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
function compute_pressure!(boundary_model, ::AdamiPressureExtrapolation, | ||||||||||||||||||
system, v, u, v_ode, u_ode, semi) | ||||||||||||||||||
(; pressure, state_equation, cache, viscosity) = boundary_model | ||||||||||||||||||
(; volume, density) = cache | ||||||||||||||||||
(; pressure, cache) = boundary_model | ||||||||||||||||||
|
||||||||||||||||||
set_zero!(pressure) | ||||||||||||||||||
|
||||||||||||||||||
# Set `volume` to zero. For `ViscosityAdami` the `wall_velocity` is also set to zero. | ||||||||||||||||||
reset_cache!(cache, viscosity) | ||||||||||||||||||
set_zero!(cache.volume) | ||||||||||||||||||
reset_wall_velocity!(system.viscosity, system) | ||||||||||||||||||
|
||||||||||||||||||
system_coords = current_coordinates(u, system) | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -363,7 +336,7 @@ end | |||||||||||||||||
# Otherwise, `@threaded` does not work here with Julia ARM on macOS. | ||||||||||||||||||
# See https://github.com/JuliaSIMD/Polyester.jl/issues/88. | ||||||||||||||||||
function compute_adami_density!(boundary_model, system, system_coords, particle) | ||||||||||||||||||
(; pressure, state_equation, cache, viscosity) = boundary_model | ||||||||||||||||||
(; pressure, state_equation, cache) = boundary_model | ||||||||||||||||||
(; volume, density) = cache | ||||||||||||||||||
|
||||||||||||||||||
# The summation is only over fluid particles, thus the volume stays zero when a boundary | ||||||||||||||||||
|
@@ -373,7 +346,7 @@ function compute_adami_density!(boundary_model, system, system_coords, particle) | |||||||||||||||||
pressure[particle] /= volume[particle] | ||||||||||||||||||
|
||||||||||||||||||
# To impose no-slip condition | ||||||||||||||||||
compute_wall_velocity!(viscosity, system, system_coords, particle) | ||||||||||||||||||
compute_wall_velocity!(system.viscosity, system, system_coords, particle) | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
# Apply inverse state equation to compute density (not used with EDAC) | ||||||||||||||||||
|
@@ -386,13 +359,18 @@ function compute_pressure!(boundary_model, ::Union{PressureMirroring, PressureZe | |||||||||||||||||
return boundary_model | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
@inline function adami_pressure_extrapolation_neighbor!(boundary_model, system, | ||||||||||||||||||
neighbor_system, system_coords, | ||||||||||||||||||
neighbor_coords, v_neighbor_system, | ||||||||||||||||||
neighborhood_search) | ||||||||||||||||||
return boundary_model | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
@inline function adami_pressure_extrapolation_neighbor!(boundary_model, system, | ||||||||||||||||||
neighbor_system::FluidSystem, | ||||||||||||||||||
system_coords, neighbor_coords, | ||||||||||||||||||
v_neighbor_system, | ||||||||||||||||||
neighborhood_search) | ||||||||||||||||||
(; pressure, cache, viscosity) = boundary_model | ||||||||||||||||||
|
||||||||||||||||||
for_particle_neighbor(neighbor_system, system, | ||||||||||||||||||
neighbor_coords, system_coords, | ||||||||||||||||||
neighborhood_search; | ||||||||||||||||||
|
@@ -401,26 +379,22 @@ end | |||||||||||||||||
pos_diff, distance | ||||||||||||||||||
# Since neighbor and particle are switched | ||||||||||||||||||
pos_diff = -pos_diff | ||||||||||||||||||
adami_pressure_inner!(boundary_model, system, neighbor_system::FluidSystem, | ||||||||||||||||||
adami_pressure_inner!(boundary_model, system, neighbor_system, | ||||||||||||||||||
v_neighbor_system, particle, neighbor, pos_diff, | ||||||||||||||||||
distance, viscosity, cache, pressure) | ||||||||||||||||||
distance) | ||||||||||||||||||
end | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
@inline function adami_pressure_extrapolation_neighbor!(boundary_model, system, | ||||||||||||||||||
neighbor_system, | ||||||||||||||||||
system_coords, neighbor_coords, | ||||||||||||||||||
v_neighbor_system, | ||||||||||||||||||
neighborhood_search) | ||||||||||||||||||
@inline function adami_pressure_extrapolation!(boundary_model, system, neighbor_system, | ||||||||||||||||||
system_coords, neighbor_coords, | ||||||||||||||||||
v_neighbor_system, neighborhood_search) | ||||||||||||||||||
return boundary_model | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
@inline function adami_pressure_extrapolation!(boundary_model, system, | ||||||||||||||||||
neighbor_system::FluidSystem, | ||||||||||||||||||
system_coords, neighbor_coords, | ||||||||||||||||||
v_neighbor_system, neighborhood_search) | ||||||||||||||||||
(; pressure, cache, viscosity) = boundary_model | ||||||||||||||||||
|
||||||||||||||||||
# Loop over all pairs of particles and neighbors within the kernel cutoff. | ||||||||||||||||||
for_particle_neighbor(system, neighbor_system, | ||||||||||||||||||
system_coords, neighbor_coords, | ||||||||||||||||||
|
@@ -429,20 +403,15 @@ end | |||||||||||||||||
pos_diff, distance | ||||||||||||||||||
adami_pressure_inner!(boundary_model, system, neighbor_system, | ||||||||||||||||||
v_neighbor_system, particle, neighbor, pos_diff, | ||||||||||||||||||
distance, viscosity, cache, pressure) | ||||||||||||||||||
distance) | ||||||||||||||||||
end | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
@inline function adami_pressure_extrapolation!(boundary_model, system, neighbor_system, | ||||||||||||||||||
system_coords, neighbor_coords, | ||||||||||||||||||
v_neighbor_system, neighborhood_search) | ||||||||||||||||||
return boundary_model | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
@inline function adami_pressure_inner!(boundary_model, system, | ||||||||||||||||||
neighbor_system::FluidSystem, | ||||||||||||||||||
@inline function adami_pressure_inner!(boundary_model, system, neighbor_system, | ||||||||||||||||||
v_neighbor_system, particle, neighbor, pos_diff, | ||||||||||||||||||
distance, viscosity, cache, pressure) | ||||||||||||||||||
distance) | ||||||||||||||||||
(; pressure, cache) = boundary_model | ||||||||||||||||||
|
||||||||||||||||||
density_neighbor = particle_density(v_neighbor_system, neighbor_system, neighbor) | ||||||||||||||||||
|
||||||||||||||||||
resulting_acc = neighbor_system.acceleration - | ||||||||||||||||||
|
@@ -457,7 +426,8 @@ end | |||||||||||||||||
|
||||||||||||||||||
cache.volume[particle] += kernel_weight | ||||||||||||||||||
|
||||||||||||||||||
compute_smoothed_velocity!(cache, viscosity, neighbor_system, v_neighbor_system, | ||||||||||||||||||
compute_smoothed_velocity!(system.cache, system.viscosity, neighbor_system, | ||||||||||||||||||
v_neighbor_system, | ||||||||||||||||||
kernel_weight, particle, neighbor) | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -510,8 +480,7 @@ end | |||||||||||||||||
return density | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
@inline function smoothing_kernel_grad(system::BoundarySystem, pos_diff, | ||||||||||||||||||
distance, particle) | ||||||||||||||||||
@inline function smoothing_kernel_grad(system::BoundarySystem, pos_diff, distance, particle) | ||||||||||||||||||
(; smoothing_kernel, smoothing_length, correction) = system.boundary_model | ||||||||||||||||||
|
||||||||||||||||||
return corrected_kernel_grad(smoothing_kernel, pos_diff, distance, | ||||||||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These arguments are still there.