Skip to content

Commit

Permalink
Fix moving boundaries (#603)
Browse files Browse the repository at this point in the history
* fix

* typo

* fix again

* implement suggestions
  • Loading branch information
LasNikas authored Sep 26, 2024
1 parent 16b6b5d commit 4816551
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/fluid/accelerated_tank_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ boundary_movement = BoundaryMovement(movement_function, is_moving)
trixi_include(@__MODULE__,
joinpath(examples_dir(), "fluid", "hydrostatic_water_column_2d.jl"),
fluid_particle_spacing=fluid_particle_spacing, movement=boundary_movement,
tspan=(0.0, 1.0), system_acceleration=(0.0, 0.0))
tspan=(0.0, 1.0), system_acceleration=(0.0, 0.0));
18 changes: 13 additions & 5 deletions src/schemes/boundary/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ end
create_cache_boundary(::Nothing, initial_condition) = (;)

function create_cache_boundary(::BoundaryMovement, initial_condition)
initial_coordinates = copy(initial_condition.coordinates)
velocity = zero(initial_condition.velocity)
acceleration = zero(initial_condition.velocity)
return (; velocity, acceleration)
return (; velocity, acceleration, initial_coordinates)
end

function Base.show(io::IO, system::BoundarySPHSystem)
Expand Down Expand Up @@ -194,10 +195,17 @@ timer_name(::Union{BoundarySPHSystem, BoundaryDEMSystem}) = "boundary"
eltype(system.coordinates)
end

# This does not account for moving boundaries, but it's only used to initialize the
# neighborhood search, anyway.
@inline function initial_coordinates(system::Union{BoundarySPHSystem, BoundaryDEMSystem})
system.coordinates
@inline function initial_coordinates(system::BoundarySPHSystem)
initial_coordinates(system::BoundarySPHSystem, system.movement)
end

@inline initial_coordinates(system::BoundaryDEMSystem) = system.coordinates

@inline initial_coordinates(system::BoundarySPHSystem, ::Nothing) = system.coordinates

# We need static initial coordinates as reference when system is moving
@inline function initial_coordinates(system::BoundarySPHSystem, movement)
return system.cache.initial_coordinates
end

function (movement::BoundaryMovement)(system, t)
Expand Down

0 comments on commit 4816551

Please sign in to comment.