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

Fixes for Open Boundary Systems for free surfaces #609

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
ed83ea1
set test up for 1.11
svchb Aug 8, 2024
493e26b
Merge branch 'main' into prepare_for_1.11
svchb Aug 12, 2024
bf4bea2
fix
LasNikas Aug 15, 2024
f629239
typo
LasNikas Aug 15, 2024
7d5a5fc
fix again
LasNikas Aug 15, 2024
9f7d1c1
remove soundspeed from OBS
svchb Aug 20, 2024
5c4734c
Merge branch 'main' into remove_soundspeed
svchb Aug 20, 2024
a01311c
skip empty system
svchb Aug 20, 2024
24a21fc
fix test
svchb Aug 21, 2024
dcecbe0
fix tests
svchb Aug 21, 2024
6151f7f
fix tests
svchb Aug 21, 2024
43e89fd
fix bug
svchb Aug 21, 2024
da719c8
Merge remote-tracking branch 'origin/apply_samesys_dd' into fix_obs_f…
svchb Aug 22, 2024
1ba97a5
Merge remote-tracking branch 'origin/remove_soundspeed' into fix_obs_…
svchb Aug 22, 2024
3678983
Merge remote-tracking branch 'origin/skip_empty_system_io' into fix_o…
svchb Aug 22, 2024
b164e7a
Merge branch 'fix-moving-boundaries' into fix_obs_for_free_surface
svchb Aug 22, 2024
0091cc3
fix
svchb Aug 22, 2024
fbaf108
check dimensionality of reference functions
svchb Aug 23, 2024
e720529
propagate characteristics
svchb Aug 23, 2024
7400487
update
svchb Sep 27, 2024
5ebc4e7
Merge remote-tracking branch 'upstream/main' into fix_obs_for_free_su…
svchb Oct 7, 2024
550146f
cleanup
svchb Oct 8, 2024
90766fe
update
svchb Oct 8, 2024
31b2f75
Merge branch 'main' into prepare_for_1.11
svchb Oct 9, 2024
1d05304
Merge branch 'main' into prepare_for_1.11
svchb Oct 9, 2024
4ed0b91
Increase errors for 1.11
svchb Oct 9, 2024
1ce0460
Fix invalidations
svchb Oct 9, 2024
1774f5a
Fix tests
svchb Oct 9, 2024
4daf984
Update ci.yml
svchb Oct 9, 2024
ac2eb2c
revert
svchb Oct 9, 2024
258f2ba
Update ci.yml
svchb Oct 9, 2024
139e282
Merge remote-tracking branch 'origin/prepare_for_1.11' into fix_obs_f…
svchb Oct 10, 2024
1a9f3f5
Update test/validation/validation.jl
svchb Oct 10, 2024
da9be38
revert changes that had no benefit
svchb Oct 10, 2024
95be0e9
update
svchb Oct 10, 2024
4b87c7c
cleanup
svchb Oct 10, 2024
8c72576
include in test run
svchb Oct 10, 2024
782f9de
remove redundancy
svchb Oct 10, 2024
b0d24cc
Merge remote-tracking branch 'origin/prepare_for_1.11' into fix_obs_f…
svchb Oct 10, 2024
6f5ca10
revert
svchb Oct 10, 2024
5e688d2
fix tests
svchb Oct 11, 2024
7557879
fix
svchb Oct 11, 2024
8294aa9
fix test
svchb Oct 11, 2024
bdd6756
fix test
svchb Oct 11, 2024
cde7990
Merge branch 'main' into fix_obs_for_free_surface
svchb Oct 11, 2024
1ec7eac
fix the test
svchb Oct 16, 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
6 changes: 3 additions & 3 deletions examples/fluid/pipe_flow_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fluid_system = EntropicallyDampedSPHSystem(pipe.fluid, smoothing_kernel, smoothi

# ==========================================================================================
# ==== Open Boundary
function velocity_function(pos, t)
function velocity_function2d(pos, t)
# Use this for a time-dependent inflow velocity
# return SVector(0.5prescribed_velocity * sin(2pi * t) + prescribed_velocity, 0)

Expand All @@ -92,7 +92,7 @@ open_boundary_in = OpenBoundarySPHSystem(inflow; fluid_system,
buffer_size=n_buffer_particles,
reference_density=fluid_density,
reference_pressure=pressure,
reference_velocity=velocity_function)
reference_velocity=velocity_function2d)

outflow = OutFlow(; plane=([domain_size[1], 0.0], [domain_size[1], domain_size[2]]),
flow_direction, open_boundary_layers, density=fluid_density,
Expand All @@ -103,7 +103,7 @@ open_boundary_out = OpenBoundarySPHSystem(outflow; fluid_system,
buffer_size=n_buffer_particles,
reference_density=fluid_density,
reference_pressure=pressure,
reference_velocity=velocity_function)
reference_velocity=velocity_function2d)

# ==========================================================================================
# ==== Boundary
Expand Down
46 changes: 46 additions & 0 deletions examples/fluid/pipe_flow_3d.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 3D channel flow simulation with open boundaries.
using TrixiParticles
using OrdinaryDiffEq

tspan = (0.0, 2.0)

# load variables
trixi_include(@__MODULE__, joinpath(examples_dir(), "fluid", "pipe_flow_2d.jl"),
sol=nothing)

function velocity_function3d(pos, t)
# Use this for a time-dependent inflow velocity
# return SVector(0.5prescribed_velocity * sin(2pi * t) + prescribed_velocity, 0)

return SVector(prescribed_velocity, 0.0, 0.0)
end

domain_size = (1.0, 0.4, 0.4)

boundary_size = (domain_size[1] + 2 * particle_spacing * open_boundary_layers,
domain_size[2], domain_size[3])

pipe3d = RectangularTank(particle_spacing, domain_size, boundary_size, fluid_density,
pressure=pressure, n_layers=boundary_layers,
faces=(false, false, true, true, true, true))

flow_direction = [1.0, 0.0, 0.0]

# setup simulation
trixi_include(@__MODULE__, joinpath(examples_dir(), "fluid", "pipe_flow_2d.jl"),
domain_size=domain_size, flow_direction=flow_direction,
pipe=pipe3d,
n_buffer_particles=4 * pipe3d.n_particles_per_dimension[2]^2,
smoothing_kernel=WendlandC2Kernel{3}(),
reference_velocity=velocity_function3d,
inflow=InFlow(;
plane=([0.0, 0.0, 0.0],
[0.0, domain_size[2], 0.0],
[0.0, 0.0, domain_size[3]]), flow_direction,
open_boundary_layers, density=fluid_density, particle_spacing),
outflow=OutFlow(;
plane=([domain_size[1], 0.0, 0.0],
[domain_size[1], domain_size[2], 0.0],
[domain_size[1], 0.0, domain_size[3]]),
flow_direction, open_boundary_layers, density=fluid_density,
particle_spacing))
17 changes: 9 additions & 8 deletions src/schemes/boundary/open_boundary/boundary_zones.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ struct InFlow{NDIMS, IC, S, ZO, ZW, FD}

if !isapprox(abs(dot_), 1.0, atol=1e-7)
throw(ArgumentError("`flow_direction` is not normal to inflow plane"))
else
# Flip the normal vector to point in the opposite direction of `flow_direction`
spanning_set[:, 1] .*= -sign(dot_)
end

# Flip the normal vector to point in the opposite direction of `flow_direction`
spanning_set[:, 1] .*= -sign(dot_)

spanning_set_ = reinterpret(reshape, SVector{NDIMS, ELTYPE}, spanning_set)

# Remove particles outside the boundary zone.
Expand Down Expand Up @@ -251,11 +251,11 @@ struct OutFlow{NDIMS, IC, S, ZO, ZW, FD}

if !isapprox(abs(dot_), 1.0, atol=1e-7)
throw(ArgumentError("`flow_direction` is not normal to outflow plane"))
else
# Flip the normal vector to point in `flow_direction`
spanning_set[:, 1] .*= sign(dot_)
end

# Flip the normal vector to point in `flow_direction`
spanning_set[:, 1] .*= sign(dot_)

spanning_set_ = reinterpret(reshape, SVector{NDIMS, ELTYPE}, spanning_set)

# Remove particles outside the boundary zone.
Expand Down Expand Up @@ -289,8 +289,9 @@ function spanning_vectors(plane_points::NTuple{3}, zone_width)
edge1 = plane_points[2] - plane_points[1]
edge2 = plane_points[3] - plane_points[1]

if !isapprox(dot(edge1, edge2), 0.0, atol=1e-7)
throw(ArgumentError("the vectors `AB` and `AC` for the provided points `A`, `B`, `C` must be orthogonal"))
# Check if the edges are linearly dependent (to avoid degenerate planes)
if isapprox(norm(cross(edge1, edge2)), 0.0; atol=eps())
throw(ArgumentError("The vectors `AB` and `AC` must not be collinear"))
end

# Calculate normal vector of plane
Expand Down
23 changes: 17 additions & 6 deletions src/schemes/boundary/open_boundary/method_of_characteristics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ about the method see [description below](@ref method_of_characteristics).
"""
struct BoundaryModelLastiwka end

@inline function update_quantities!(system, boundary_model::BoundaryModelLastiwka,
v, u, v_ode, u_ode, semi, t)
# Called from update callback via update_open_boundary_eachstep!
@inline function update_boundary_quantities!(system, boundary_model::BoundaryModelLastiwka,
v, u, v_ode, u_ode, semi, t)
(; density, pressure, cache, flow_direction,
reference_velocity, reference_pressure, reference_density) = system

Expand Down Expand Up @@ -45,10 +46,13 @@ struct BoundaryModelLastiwka end
return system
end

# Called from semidiscretization
function update_final!(system, ::BoundaryModelLastiwka, v, u, v_ode, u_ode, semi, t)
@trixi_timeit timer() "evaluate characteristics" begin
evaluate_characteristics!(system, v, u, v_ode, u_ode, semi, t)
end

return system
end

# ==== Characteristics
Expand Down Expand Up @@ -98,9 +102,16 @@ function evaluate_characteristics!(system, v, u, v_ode, u_ode, semi, t)
end
end

characteristics[1, particle] = avg_J1 / counter
characteristics[2, particle] = avg_J2 / counter
characteristics[3, particle] = avg_J3 / counter
# To prevent NANs here if the boundary has not been in contact before.
if counter > 0
characteristics[1, particle] = avg_J1 / counter
characteristics[2, particle] = avg_J2 / counter
characteristics[3, particle] = avg_J3 / counter
else
characteristics[1, particle] = 0.0
characteristics[2, particle] = 0.0
characteristics[3, particle] = 0.0
end
else
characteristics[1, particle] /= volume[particle]
characteristics[2, particle] /= volume[particle]
Expand Down Expand Up @@ -164,7 +175,7 @@ end

@inline function prescribe_conditions!(characteristics, particle, ::OutFlow)
# J3 is prescribed (i.e. determined from the exterior of the domain).
# J1 and J2 is transimtted from the domain interior.
# J1 and J2 is transmitted from the domain interior.
characteristics[3, particle] = zero(eltype(characteristics))

return characteristics
Expand Down
28 changes: 24 additions & 4 deletions src/schemes/boundary/open_boundary/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ struct OpenBoundarySPHSystem{BM, BZ, NDIMS, ELTYPE <: Real, IC, FS, ARRAY1D, RV,
"an array where the ``i``-th column holds the velocity of particle ``i`` " *
"or, for a constant fluid velocity, a vector of length $NDIMS for a $(NDIMS)D problem holding this velocity"))
else
if reference_velocity isa Function
test_result = reference_velocity(zeros(NDIMS), 0.0)
if length(test_result) != NDIMS
throw(ArgumentError("`reference_velocity` function must be of dimension $NDIMS"))
end
end
reference_velocity_ = wrap_reference_function(reference_velocity, Val(NDIMS))
end

Expand All @@ -86,6 +92,12 @@ struct OpenBoundarySPHSystem{BM, BZ, NDIMS, ELTYPE <: Real, IC, FS, ARRAY1D, RV,
"each particle's coordinates and time to its pressure, " *
"a vector holding the pressure of each particle, or a scalar"))
else
if reference_pressure isa Function
test_result = reference_pressure(zeros(NDIMS), 0.0)
if length(test_result) != 1
throw(ArgumentError("`reference_pressure` function must be a scalar function"))
end
end
reference_pressure_ = wrap_reference_function(reference_pressure, Val(NDIMS))
end

Expand All @@ -95,6 +107,12 @@ struct OpenBoundarySPHSystem{BM, BZ, NDIMS, ELTYPE <: Real, IC, FS, ARRAY1D, RV,
"each particle's coordinates and time to its density, " *
"a vector holding the density of each particle, or a scalar"))
else
if reference_density isa Function
test_result = reference_density(zeros(NDIMS), 0.0)
if length(test_result) != 1
throw(ArgumentError("`reference_density` function must be a scalar function"))
end
end
reference_density_ = wrap_reference_function(reference_density, Val(NDIMS))
end

Expand Down Expand Up @@ -190,10 +208,12 @@ function update_open_boundary_eachstep!(system::OpenBoundarySPHSystem, v_ode, u_

# Update density, pressure and velocity based on the characteristic variables.
# See eq. 13-15 in Lastiwka (2009) https://doi.org/10.1002/fld.1971
@trixi_timeit timer() "update quantities" update_quantities!(system,
system.boundary_model,
v, u, v_ode, u_ode,
semi, t)
@trixi_timeit timer() "update boundary quantities" update_boundary_quantities!(system,
system.boundary_model,
v, u,
v_ode,
u_ode,
semi, t)

@trixi_timeit timer() "check domain" check_domain!(system, v, u, v_ode, u_ode, semi)

Expand Down
4 changes: 2 additions & 2 deletions src/setups/extrude_geometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ function sample_plane(plane_points::NTuple{3}, particle_spacing; tlsph=nothing)
edge2 = point3_ - point1_

# Check if the points are collinear
if norm(cross(edge1, edge2)) == 0
throw(ArgumentError("the points must not be collinear"))
if isapprox(norm(cross(edge1, edge2)), 0.0; atol=eps())
throw(ArgumentError("The vectors `AB` and `AC` must not be collinear"))
end

# Determine the number of points along each edge
Expand Down
8 changes: 8 additions & 0 deletions test/examples/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@
@test count_rhs_allocations(sol, semi) == 0
end

@trixi_testset "fluid/pipe_flow_3d.jl" begin
@test_nowarn_mod trixi_include(@__MODULE__, tspan=(0.0, 0.5),
joinpath(examples_dir(), "fluid",
"pipe_flow_3d.jl"))
@test sol.retcode == ReturnCode.Success
@test count_rhs_allocations(sol, semi) == 0
end

@trixi_testset "fluid/sphere_surface_tension_2d.jl" begin
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "fluid",
Expand Down
4 changes: 2 additions & 2 deletions test/schemes/boundary/open_boundary/boundary_zone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@
end

@testset verbose=true "Illegal Inputs" begin
no_rectangular_plane = [[0.2, 0.3, -0.5], [-1.0, 1.5, 0.2], [-0.2, 2.0, -0.5]]
no_rectangular_plane = [[0.2, 0.3, -0.5], [-1.0, 1.5, 0.2], [-0.4, 0.9, -0.15]]
flow_direction = [0.0, 0.0, 1.0]

error_str = "the vectors `AB` and `AC` for the provided points `A`, `B`, `C` must be orthogonal"
error_str = "The vectors `AB` and `AC` must not be collinear"

@test_throws ArgumentError(error_str) InFlow(; plane=no_rectangular_plane,
particle_spacing=0.1,
Expand Down
Loading