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

min_coordinates for RectangularTank #298

Merged
merged 9 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
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
8 changes: 7 additions & 1 deletion src/setups/rectangular_tank.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@doc raw"""
RectangularTank(particle_spacing, fluid_size, tank_size, fluid_density;
n_layers=1, spacing_ratio=1.0,
n_layers=1, spacing_ratio=1.0, min_coordinates=zeros(length(fluid_size))
LasNikas marked this conversation as resolved.
Show resolved Hide resolved
init_velocity=zeros(length(fluid_size)),
boundary_density=fluid_density,
faces=Tuple(trues(2 * length(fluid_size))))
Expand All @@ -18,6 +18,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 +59,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 +121,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.
LasNikas marked this conversation as resolved.
Show resolved Hide resolved
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
Loading