Skip to content

Commit

Permalink
min_coordinates for RectangularTank (#298)
Browse files Browse the repository at this point in the history
* add `min_coordinates`

* add tests

* indentation

* implement suggestions

---------

Co-authored-by: Erik Faulhaber <[email protected]>
  • Loading branch information
LasNikas and efaulhaber authored Jan 2, 2024
1 parent 205d696 commit 4101f11
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 28 deletions.
9 changes: 3 additions & 6 deletions src/general/semidiscretization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ Create an `ODEProblem` from the semidiscretization with the specified `tspan`.
function semidiscretize(semi, tspan; reset_threads=true)
(; systems) = semi

@assert all(system -> eltype(system) === eltype(systems[1]),
systems)
@assert all(system -> eltype(system) === eltype(systems[1]), systems)
ELTYPE = eltype(systems[1])

# Optionally reset Polyester.jl threads. See
Expand All @@ -190,10 +189,8 @@ function semidiscretize(semi, tspan; reset_threads=true)
end
end

sizes_u = (u_nvariables(system) * n_moving_particles(system)
for system in systems)
sizes_v = (v_nvariables(system) * n_moving_particles(system)
for system in systems)
sizes_u = (u_nvariables(system) * n_moving_particles(system) for system in systems)
sizes_v = (v_nvariables(system) * n_moving_particles(system) for system in systems)
u0_ode = Vector{ELTYPE}(undef, sum(sizes_u))
v0_ode = Vector{ELTYPE}(undef, sum(sizes_v))

Expand Down
7 changes: 7 additions & 0 deletions src/setups/rectangular_tank.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@doc raw"""
RectangularTank(particle_spacing, fluid_size, tank_size, fluid_density;
n_layers=1, spacing_ratio=1.0,
min_coordinates=zeros(length(fluid_size)),
init_velocity=zeros(length(fluid_size)),
boundary_density=fluid_density,
faces=Tuple(trues(2 * length(fluid_size))))
Expand All @@ -18,6 +19,7 @@ Rectangular tank filled with a fluid to set up dam-break-style simulations.
- `spacing_ratio`: Ratio of `particle_spacing` to boundary particle spacing.
A value of 2 means that the boundary particle spacing will be
half the fluid particle spacing.
- `min_coordinates`: Coordinates of the corner in negative coordinate directions.
- `init_velocity`: The initial velocity of each fluid particle as `(x, y)` (or `(x, y, z)` in 3D).
- `boundary_density`: Density of each boundary particle (by default set to the rest density)
- `faces`: By default all faces are generated. Set faces by passing a
Expand Down Expand Up @@ -58,6 +60,7 @@ struct RectangularTank{NDIMS, NDIMSt2, ELTYPE <: Real}

function RectangularTank(particle_spacing, fluid_size, tank_size, fluid_density;
pressure=0.0, n_layers=1, spacing_ratio=1.0,
min_coordinates=zeros(length(fluid_size)),
init_velocity=zeros(length(fluid_size)),
boundary_density=fluid_density,
faces=Tuple(trues(2 * length(fluid_size))),
Expand Down Expand Up @@ -119,6 +122,10 @@ struct RectangularTank{NDIMS, NDIMSt2, ELTYPE <: Real}
boundary_masses, boundary_densities,
particle_spacing=boundary_spacing)

# Move the tank corner in the negative coordinate directions to the desired position
fluid.coordinates .+= min_coordinates
boundary.coordinates .+= min_coordinates

return new{NDIMS, 2 * NDIMS, ELTYPE}(fluid, boundary, fluid_size_, tank_size_,
faces, face_indices,
particle_spacing, spacing_ratio, n_layers,
Expand Down
57 changes: 35 additions & 22 deletions test/setups/rectangular_tank.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@testset "Coordinates" begin
particle_spacings = [0.1, 0.2]
spacing_ratios = [1, 3]
min_coordinates = [(0.0, 0.0), (-0.3, 2.0)]

expected_fluid_coords = [
[0.05 0.15 0.25 0.35 0.45 0.05 0.15 0.25 0.35 0.45 0.05 0.15 0.25 0.35 0.45 0.05 0.15 0.25 0.35 0.45;
Expand All @@ -33,17 +34,22 @@
],
]

@testset "Particle Spacing: $(particle_spacings[i])" for i in eachindex(particle_spacings)
@testset "Spacing Ratio: $(spacing_ratios[j])" for j in eachindex(spacing_ratios)
tank = RectangularTank(particle_spacings[i],
(water_width, water_height),
(tank_width, tank_height),
water_density,
spacing_ratio=spacing_ratios[j])

@test isapprox(tank.fluid.coordinates, expected_fluid_coords[i])
@test isapprox(tank.boundary.coordinates,
expected_bound_coords[i][j])
@testset "Move Tank: $(min_coordinates[i])" for i in eachindex(min_coordinates)
@testset "Particle Spacing: $(particle_spacings[j])" for j in eachindex(particle_spacings)
@testset "Spacing Ratio: $(spacing_ratios[k])" for k in eachindex(spacing_ratios)
tank = RectangularTank(particle_spacings[j],
(water_width, water_height),
(tank_width, tank_height),
water_density,
spacing_ratio=spacing_ratios[k],
min_coordinates=min_coordinates[i])
expected_fluid_coords_ = copy(expected_fluid_coords[j])
expected_bound_coords_ = copy(expected_bound_coords[j][k])
expected_fluid_coords_ .+= min_coordinates[i]
expected_bound_coords_ .+= min_coordinates[i]
@test isapprox(tank.fluid.coordinates, expected_fluid_coords_)
@test isapprox(tank.boundary.coordinates, expected_bound_coords_)
end
end
end
end
Expand Down Expand Up @@ -267,6 +273,7 @@ end
@testset "Coordinates" begin
particle_spacings = [0.1, 0.2]
spacing_ratios = [1, 3]
min_coordinates = [(0.0, 0.0, 0.0), (-0.3, 2.0, -0.5)]

expected_fluid_coords = [
[0.05 0.15 0.25 0.35 0.05 0.15 0.25 0.35 0.05 0.15 0.25 0.35 0.05 0.15 0.25 0.35 0.05 0.15 0.25 0.35 0.05 0.15 0.25 0.35 0.05 0.15 0.25 0.35 0.05 0.15 0.25 0.35 0.05 0.15 0.25 0.35 0.05 0.15 0.25 0.35 0.05 0.15 0.25 0.35 0.05 0.15 0.25 0.35 0.05 0.15 0.25 0.35 0.05 0.15 0.25 0.35 0.05 0.15 0.25 0.35 0.05 0.15 0.25 0.35;
Expand Down Expand Up @@ -296,17 +303,23 @@ end
],
]

@testset "Particle Spacing: $(particle_spacings[i])" for i in eachindex(particle_spacings)
@testset "Spacing Ratio: $(spacing_ratios[j])" for j in eachindex(spacing_ratios)
tank = RectangularTank(particle_spacings[i],
(water_width, water_height, water_depth),
(tank_width, tank_height, tank_depth),
water_density,
spacing_ratio=spacing_ratios[j])

@test isapprox(tank.fluid.coordinates, expected_fluid_coords[i])
@test isapprox(tank.boundary.coordinates,
expected_bound_coords[i][j])
@testset "Move Tank: $(min_coordinates[i])" for i in eachindex(min_coordinates)
@testset "Particle Spacing: $(particle_spacings[j])" for j in eachindex(particle_spacings)
@testset "Spacing Ratio: $(spacing_ratios[k])" for k in eachindex(spacing_ratios)
tank = RectangularTank(particle_spacings[j],
(water_width, water_height, water_depth),
(tank_width, tank_height, tank_depth),
water_density,
spacing_ratio=spacing_ratios[k],
min_coordinates=min_coordinates[i])
expected_fluid_coords_ = copy(expected_fluid_coords[j])
expected_bound_coords_ = copy(expected_bound_coords[j][k])
expected_fluid_coords_ .+= min_coordinates[i]
expected_bound_coords_ .+= min_coordinates[i]

@test isapprox(tank.fluid.coordinates, expected_fluid_coords_)
@test isapprox(tank.boundary.coordinates, expected_bound_coords_)
end
end
end
end
Expand Down

0 comments on commit 4101f11

Please sign in to comment.