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

Cleanup examples #592

Merged
merged 16 commits into from
Aug 12, 2024
50 changes: 2 additions & 48 deletions examples/fluid/accelerated_tank_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,17 @@
using TrixiParticles
using OrdinaryDiffEq

# ==========================================================================================
# ==== Resolution
# Resolution
fluid_particle_spacing = 0.05

# Make sure that the kernel support of fluid particles at a boundary is always fully sampled
boundary_layers = 3

# ==========================================================================================
# ==== Experiment Setup
tspan = (0.0, 1.0)

# Boundary geometry and initial fluid particle positions
initial_fluid_size = (1.0, 0.9)
tank_size = (1.0, 1.0)

fluid_density = 1000.0
sound_speed = 10.0
state_equation = StateEquationCole(; sound_speed, reference_density=fluid_density,
exponent=7, clip_negative_pressure=false)

tank = RectangularTank(fluid_particle_spacing, initial_fluid_size, tank_size, fluid_density,
acceleration=(0.0, -9.81), state_equation=state_equation,
n_layers=boundary_layers, spacing_ratio=1.0)

# Function for moving boundaries
movement_function(t) = SVector(0.0, 0.5 * 9.81 * t^2)

is_moving(t) = true

boundary_movement = BoundaryMovement(movement_function, is_moving)

# Import the setup from `hydrostatic_water_column_2d.jl`
trixi_include(@__MODULE__,
svchb marked this conversation as resolved.
Show resolved Hide resolved
joinpath(examples_dir(), "fluid", "hydrostatic_water_column_2d.jl"),
fluid_particle_spacing=fluid_particle_spacing, movement=boundary_movement,
acceleration=(0.0, 0.0), tank=tank, semi=nothing, ode=nothing,
sol=nothing) # Overwrite `sol` assignment to skip time integration

# ==========================================================================================
# ==== Simulation
semi = Semidiscretization(fluid_system, boundary_system)
ode = semidiscretize(semi, tspan)

info_callback = InfoCallback(interval=50)
saving_callback = SolutionSavingCallback(dt=0.02, prefix="")

callbacks = CallbackSet(info_callback, saving_callback)

# Use a Runge-Kutta method with automatic (error based) time step size control.
# Limiting of the maximum stepsize is necessary to prevent crashing.
# When particles are approaching a wall in a uniform way, they can be advanced
# with large time steps. Close to the wall, the stepsize has to be reduced drastically.
# Sometimes, the method fails to do so because forces become extremely large when
# fluid particles are very close to boundary particles, and the time integration method
# interprets this as an instability.
sol = solve(ode, RDPK3SpFSAL35(),
abstol=1e-5, # Default abstol is 1e-6 (may need to be tuned to prevent boundary penetration)
reltol=1e-3, # Default reltol is 1e-3 (may need to be tuned to prevent boundary penetration)
dtmax=1e-2, # Limit stepsize to prevent crashing
save_everystep=false, callback=callbacks);
tspan=(0.0, 1.0), system_acceleration=(0.0, 0.0))
31 changes: 0 additions & 31 deletions examples/fluid/dam_break_2d_surface_tension.jl

This file was deleted.

12 changes: 8 additions & 4 deletions examples/fluid/hydrostatic_water_column_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,25 @@ state_equation = StateEquationCole(; sound_speed, reference_density=fluid_densit
exponent=7, clip_negative_pressure=false)

tank = RectangularTank(fluid_particle_spacing, initial_fluid_size, tank_size, fluid_density,
n_layers=boundary_layers,
acceleration=(0.0, -gravity), state_equation=state_equation)
n_layers=boundary_layers, acceleration=(0.0, -gravity),
state_equation=state_equation)

# ==========================================================================================
# ==== Fluid
smoothing_length = 1.2 * fluid_particle_spacing
smoothing_kernel = SchoenbergCubicSplineKernel{2}()

viscosity = ArtificialViscosityMonaghan(alpha=0.02, beta=0.0)
alpha = 0.02
viscosity = ArtificialViscosityMonaghan(alpha=alpha, beta=0.0)
svchb marked this conversation as resolved.
Show resolved Hide resolved

fluid_density_calculator = ContinuityDensity()

# This is to set acceleration with `trixi_include`
system_acceleration = (0.0, -gravity)
fluid_system = WeaklyCompressibleSPHSystem(tank.fluid, fluid_density_calculator,
state_equation, smoothing_kernel,
smoothing_length, viscosity=viscosity,
acceleration=(0.0, -gravity),
acceleration=system_acceleration,
source_terms=nothing)

# ==========================================================================================
Expand Down
35 changes: 0 additions & 35 deletions examples/fluid/hydrostatic_water_column_edac_2d.jl

This file was deleted.

32 changes: 24 additions & 8 deletions src/general/semidiscretization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -715,19 +715,27 @@ function update_nhs!(neighborhood_search,
points_moving=(true, neighbor.ismoving[]))
end

# This function is the same as the one below to avoid ambiguous dispatch when using `Union`
function update_nhs!(neighborhood_search,
system::BoundarySPHSystem,
neighbor::Union{FluidSystem, TotalLagrangianSPHSystem,
BoundarySPHSystem},
u_system, u_neighbor)
# Don't update. This NHS is never used.
return neighborhood_search
system::BoundarySPHSystem{<:BoundaryModelDummyParticles},
neighbor::FluidSystem, u_system, u_neighbor)
# Depending on the density calculator of the boundary model, this NHS is used for
# - kernel summation (`SummationDensity`)
# - continuity equation (`ContinuityDensity`)
# - pressure extrapolation (`AdamiPressureExtrapolation`)
#
# Boundary coordinates only change over time when `neighbor.ismoving[]`.
# The current coordinates of fluids and solids change over time.
update!(neighborhood_search, system,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(system.ismoving[], true))
end

# This function is the same as the one above to avoid ambiguous dispatch when using `Union`
function update_nhs!(neighborhood_search,
system::BoundarySPHSystem{<:BoundaryModelDummyParticles},
neighbor::Union{FluidSystem, TotalLagrangianSPHSystem},
u_system, u_neighbor)
neighbor::TotalLagrangianSPHSystem, u_system, u_neighbor)
# Depending on the density calculator of the boundary model, this NHS is used for
# - kernel summation (`SummationDensity`)
# - continuity equation (`ContinuityDensity`)
Expand Down Expand Up @@ -773,6 +781,14 @@ function update_nhs!(neighborhood_search,
points_moving=(true, false))
end

function update_nhs!(neighborhood_search,
system::BoundarySPHSystem,
neighbor::FluidSystem,
u_system, u_neighbor)
# Don't update. This NHS is never used.
return neighborhood_search
end

function update_nhs!(neighborhood_search,
system::BoundaryDEMSystem,
neighbor::Union{DEMSystem, BoundaryDEMSystem},
Expand Down
Loading
Loading