Skip to content

Commit

Permalink
Apply changes from code review and introduce new field equations.swe_…
Browse files Browse the repository at this point in the history
…trixi
  • Loading branch information
patrickersing committed Mar 8, 2024
1 parent be35c59 commit 033bb48
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 119 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
# This will use the latest version by default but you can set the version like so:
#
# julia -e 'using Pkg; Pkg.add(PackageSpec(name = "JuliaFormatter", version = "0.13.0"))'
#
# TODO: remove version restriction once formatting has sorted itself out
run: |
julia -e 'using Pkg; Pkg.add(PackageSpec(name = "JuliaFormatter", version="1.0.45"))'
julia -e 'using JuliaFormatter; format(".")'
Expand Down
2 changes: 1 addition & 1 deletion src/TrixiShallowWater.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module TrixiShallowWater
# https://github.com/trixi-framework/TrixiShallowWater.jl/pull/10#discussion_r1433720559
using Trixi
# Import additional symbols that are not exported by Trixi.jl
import Trixi: get_node_vars, set_node_vars!
using Trixi: get_node_vars, set_node_vars!
using MuladdMacro: @muladd
using StaticArrays: SVector
using Static: True, False
Expand Down
77 changes: 32 additions & 45 deletions src/equations/shallow_water_wet_dry_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ struct ShallowWaterEquationsWetDry1D{RealT <: Real} <:
# before calculating the numerical flux.
# Default is 5*eps() which in double precision is ≈1e-15.
threshold_wet::RealT
# Standard shallow water equations for dispatch on Trixi.jl functions
swe_trixi::typeof(ShallowWaterEquations1D(gravity_constant=1.0))
end

# Allow for flexibility to set the gravitational constant within an elixir depending on the
Expand All @@ -79,8 +81,11 @@ function ShallowWaterEquationsWetDry1D(; gravity_constant, H0 = zero(gravity_con
if threshold_wet === nothing
threshold_wet = 5 * eps(T)
end
# Construct standard SWE for dispatch
swe_trixi = ShallowWaterEquations1D(gravity_constant=gravity_constant, H0 = H0)

ShallowWaterEquationsWetDry1D(gravity_constant, H0, threshold_limiter,
threshold_wet)
threshold_wet, swe_trixi)
end

Trixi.have_nonconservative_terms(::ShallowWaterEquationsWetDry1D) = True()
Expand Down Expand Up @@ -110,8 +115,7 @@ A smooth initial condition used for convergence tests in combination with
function Trixi.initial_condition_convergence_test(x, t,
equations::ShallowWaterEquationsWetDry1D)
return Trixi.initial_condition_convergence_test(x, t,
ShallowWaterEquations1D(equations.gravity,
equations.H0))
equations.swe_trixi)
end

"""
Expand All @@ -129,8 +133,7 @@ as defined in [`initial_condition_convergence_test`](@ref).
@inline function Trixi.source_terms_convergence_test(u, x, t,
equations::ShallowWaterEquationsWetDry1D)
return Trixi.source_terms_convergence_test(u, x, t,
ShallowWaterEquations1D(equations.gravity,
equations.H0))
equations.swe_trixi)
end

"""
Expand All @@ -142,8 +145,7 @@ Note for the shallow water equations to the total energy acts as a mathematical
function Trixi.initial_condition_weak_blast_wave(x, t,
equations::ShallowWaterEquationsWetDry1D)
return Trixi.initial_condition_weak_blast_wave(x, t,
ShallowWaterEquations1D(equations.gravity,
equations.H0))
equations.swe_trixi)
end

"""
Expand Down Expand Up @@ -188,7 +190,7 @@ end
@inline function Trixi.flux(u, orientation::Integer,
equations::ShallowWaterEquationsWetDry1D)
return Trixi.flux(u, orientation,
ShallowWaterEquations1D(equations.gravity, equations.H0))
equations.swe_trixi)
end

"""
Expand All @@ -208,8 +210,7 @@ Further details are available in the paper:#include("numerical_fluxes.jl")
orientation::Integer,
equations::ShallowWaterEquationsWetDry1D)
return Trixi.flux_nonconservative_wintermeyer_etal(u_ll, u_rr, orientation,
ShallowWaterEquations1D(equations.gravity,
equations.H0))
equations.swe_trixi)
end

"""
Expand Down Expand Up @@ -239,8 +240,7 @@ and for curvilinear 2D case in the paper:
orientation::Integer,
equations::ShallowWaterEquationsWetDry1D)
return Trixi.flux_nonconservative_fjordholm_etal(u_ll, u_rr, orientation,
ShallowWaterEquations1D(equations.gravity,
equations.H0))
equations.swe_trixi)
end

"""
Expand All @@ -266,8 +266,7 @@ Further details on the hydrostatic reconstruction and its motivation can be foun
equations::ShallowWaterEquationsWetDry1D)
return Trixi.flux_nonconservative_audusse_etal(u_ll, u_rr,
orientation,
ShallowWaterEquations1D(equations.gravity,
equations.H0))
equations.swe_trixi)
end

"""
Expand Down Expand Up @@ -338,8 +337,7 @@ For further details see:
orientation::Integer,
equations::ShallowWaterEquationsWetDry1D)
return Trixi.flux_nonconservative_ersing_etal(u_ll, u_rr, orientation,
ShallowWaterEquations1D(equations.gravity,
equations.H0))
equations.swe_trixi)
end

"""
Expand All @@ -358,8 +356,7 @@ Details are available in Eq. (4.1) in the paper:
@inline function Trixi.flux_fjordholm_etal(u_ll, u_rr, orientation::Integer,
equations::ShallowWaterEquationsWetDry1D)
return Trixi.flux_fjordholm_etal(u_ll, u_rr, orientation,
ShallowWaterEquations1D(equations.gravity,
equations.H0))
equations.swe_trixi)
end

"""
Expand All @@ -379,8 +376,7 @@ Further details are available in Theorem 1 of the paper:
@inline function Trixi.flux_wintermeyer_etal(u_ll, u_rr, orientation::Integer,
equations::ShallowWaterEquationsWetDry1D)
return Trixi.flux_wintermeyer_etal(u_ll, u_rr, orientation,
ShallowWaterEquations1D(equations.gravity,
equations.H0))
equations.swe_trixi)
end

"""
Expand All @@ -400,8 +396,7 @@ Further details on this hydrostatic reconstruction and its motivation can be fou
@inline function Trixi.hydrostatic_reconstruction_audusse_etal(u_ll, u_rr,
equations::ShallowWaterEquationsWetDry1D)
return Trixi.hydrostatic_reconstruction_audusse_etal(u_ll, u_rr,
ShallowWaterEquations1D(equations.gravity,
equations.H0))
equations.swe_trixi)
end

"""
Expand Down Expand Up @@ -470,8 +465,7 @@ end
equations::ShallowWaterEquationsWetDry1D)
return (dissipation::DissipationLocalLaxFriedrichs)(u_ll, u_rr,
orientation_or_normal_direction,
ShallowWaterEquations1D(equations.gravity,
equations.H0))
equations.swe_trixi)
end

# Specialized `FluxHLL` to avoid spurious dissipation in the bottom topography
Expand Down Expand Up @@ -531,80 +525,74 @@ end

@inline function Trixi.max_abs_speeds(u, equations::ShallowWaterEquationsWetDry1D)
return Trixi.max_abs_speeds(u,
ShallowWaterEquations1D(equations.gravity,
equations.H0))
equations.swe_trixi)
end

# Calculate estimates for minimum and maximum wave speeds for HLL-type fluxes
@inline function Trixi.min_max_speed_naive(u_ll, u_rr, orientation::Integer,
equations::ShallowWaterEquationsWetDry1D)
return Trixi.min_max_speed_naive(u_ll, u_rr, orientation,
ShallowWaterEquations1D(equations.gravity,
equations.H0))
equations.swe_trixi)
end

# More refined estimates for minimum and maximum wave speeds for HLL-type fluxes
@inline function Trixi.min_max_speed_davis(u_ll, u_rr, orientation::Integer,
equations::ShallowWaterEquationsWetDry1D)
return Trixi.min_max_speed_davis(u_ll, u_rr, orientation,
ShallowWaterEquations1D(equations.gravity,
equations.H0))
equations.swe_trixi)
end

@inline function Trixi.min_max_speed_einfeldt(u_ll, u_rr, orientation::Integer,
equations::ShallowWaterEquationsWetDry1D)
return Trixi.min_max_speed_einfeldt(u_ll, u_rr, orientation,
ShallowWaterEquations1D(equations.gravity,
equations.H0))
equations.swe_trixi)
end

# Helper function to extract the velocity vector from the conservative variables
@inline function Trixi.velocity(u, equations::ShallowWaterEquationsWetDry1D)
return Trixi.velocity(u,
ShallowWaterEquations1D(equations.gravity, equations.H0))
equations.swe_trixi)
end

# Convert conservative variables to primitive
@inline function Trixi.cons2prim(u, equations::ShallowWaterEquationsWetDry1D)
return Trixi.cons2prim(u,
ShallowWaterEquations1D(equations.gravity, equations.H0))
equations.swe_trixi)
end

# Convert conservative variables to entropy
# Note, only the first two are the entropy variables, the third entry still
# just carries the bottom topography values for convenience
@inline function Trixi.cons2entropy(u, equations::ShallowWaterEquationsWetDry1D)
return Trixi.cons2entropy(u,
ShallowWaterEquations1D(equations.gravity, equations.H0))
equations.swe_trixi)
end

# Convert entropy variables to conservative
@inline function Trixi.entropy2cons(w, equations::ShallowWaterEquationsWetDry1D)
return Trixi.entropy2cons(w,
ShallowWaterEquations1D(equations.gravity, equations.H0))
equations.swe_trixi)
end

# Convert primitive to conservative variables
@inline function Trixi.prim2cons(prim, equations::ShallowWaterEquationsWetDry1D)
return Trixi.prim2cons(prim,
ShallowWaterEquations1D(equations.gravity, equations.H0))
equations.swe_trixi)
end

@inline function Trixi.waterheight(u, equations::ShallowWaterEquationsWetDry1D)
return Trixi.waterheight(u,
ShallowWaterEquations1D(equations.gravity,
equations.H0))
equations.swe_trixi)
end

@inline function Trixi.pressure(u, equations::ShallowWaterEquationsWetDry1D)
return Trixi.pressure(u,
ShallowWaterEquations1D(equations.gravity, equations.H0))
equations.swe_trixi)
end

@inline function Trixi.waterheight_pressure(u, equations::ShallowWaterEquationsWetDry1D)
return Trixi.waterheight_pressure(u,
ShallowWaterEquations1D(equations.gravity,
equations.H0))
equations.swe_trixi)
end

# Entropy function for the shallow water equations is the total energy
Expand All @@ -615,14 +603,13 @@ end
# Calculate total energy for a conservative state `cons`
@inline function Trixi.energy_total(cons, equations::ShallowWaterEquationsWetDry1D)
return Trixi.energy_total(cons,
ShallowWaterEquations1D(equations.gravity, equations.H0))
equations.swe_trixi)
end

# Calculate kinetic energy for a conservative state `cons`
@inline function Trixi.energy_kinetic(u, equations::ShallowWaterEquationsWetDry1D)
return Trixi.energy_kinetic(u,
ShallowWaterEquations1D(equations.gravity,
equations.H0))
equations.swe_trixi)
end

# Calculate potential energy for a conservative state `cons`
Expand Down
Loading

0 comments on commit 033bb48

Please sign in to comment.