Skip to content

Commit

Permalink
add unit tests and namespace conflict test
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickersing committed Dec 19, 2023
1 parent 5d5d29a commit b58e902
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 20 deletions.
19 changes: 0 additions & 19 deletions src/equations/shallow_water_wet_dry_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -627,25 +627,6 @@ end
eps()))
end

"""
calc_wavespeed_roe(u_ll, u_rr, direction::Integer,
equations::ShallowWaterEquationsWetDry1D)
Calculate Roe-averaged velocity `v_roe` and wavespeed `c_roe = sqrt{g * h_roe}`
See for instance equation (62) in
- Paul A. Ullrich, Christiane Jablonowski, and Bram van Leer (2010)
High-order finite-volume methods for the shallow-water equations on the sphere
[DOI: 10.1016/j.jcp.2010.04.044](https://doi.org/10.1016/j.jcp.2010.04.044)
Or equation (9.17) in [this lecture notes](https://metaphor.ethz.ch/x/2019/hs/401-4671-00L/literature/mishra_hyperbolic_pdes.pdf).
"""
@inline function Trixi.calc_wavespeed_roe(u_ll, u_rr, direction::Integer,
equations::ShallowWaterEquationsWetDry1D)
return Trixi.calc_wavespeed_roe(u_ll, u_rr, direction::Integer,
Trixi.ShallowWaterEquations1D(equations.gravity,
equations.H0, eps(),
eps()))
end

# Entropy function for the shallow water equations is the total energy
@inline function Trixi.entropy(cons, equations::ShallowWaterEquationsWetDry1D)
Trixi.energy_total(cons, equations)

Check warning on line 632 in src/equations/shallow_water_wet_dry_1d.jl

View check run for this annotation

Codecov / codecov/patch

src/equations/shallow_water_wet_dry_1d.jl#L631-L632

Added lines #L631 - L632 were not covered by tests
Expand Down
9 changes: 8 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Trixi
using TrixiShallowWater
using Test

Expand All @@ -12,9 +13,15 @@ const TRIXI_NTHREADS = clamp(Sys.CPU_THREADS, 2, 3)
@time @testset "TrixiShallowWater.jl tests" begin
@time if TRIXI_TEST == "all"
include("test_tree_1d_shallowwater_wet_dry.jl")
include("test_unit.jl")
end

@time if TRIXI_TEST == "all" || TRIXI_TEST == "upstream"

@testset "Namespace conflicts" begin
# Test for namespace conflicts between TrixiShallowWater.jl and Trixi.jl
for name in names(Trixi)
@test !(name in names(TrixiShallowWater))
end
end
end
end
53 changes: 53 additions & 0 deletions test/test_unit.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module TestUnit

using Test
using Trixi
using TrixiShallowWater

include("test_trixi.jl")

# Start with a clean environment: remove Trixi.jl output directory if it exists
outdir = "out"
isdir(outdir) && rm(outdir, recursive = true)

# Run various unit (= non-elixir-triggered) tests
@testset "Unit tests" begin
#! format: noindent

@timed_testset "Shallow water conversion between conservative/entropy variables" begin
H, v, b = 3.5, 0.25, 0.4

let equations = ShallowWaterEquations1D(gravity_constant = 9.8)
cons_vars = Trixi.prim2cons(SVector(H, v, b), equations)
entropy_vars = Trixi.cons2entropy(cons_vars, equations)
@test cons_vars Trixi.entropy2cons(entropy_vars, equations)

total_energy = Trixi.energy_total(cons_vars, equations)
@test total_energy Trixi.entropy(cons_vars, equations)

# test tuple args
cons_vars = Trixi.prim2cons((H, v, b), equations)
entropy_vars = Trixi.cons2entropy(cons_vars, equations)
@test cons_vars Trixi.entropy2cons(entropy_vars, equations)
end
end

@timed_testset "Connectivity with Trixi.jl" begin
u = SVector(SVector(1, 0.5, 0.0))
orientation = 1
equations = ShallowWaterEquationsWetDry1D(gravity_constant = 9.81)
equations_trixi = ShallowWaterEquations1D(gravity_constant = 9.81)

# We only need to check equivalence between the equation systems. The functionality is tested in
# Trixi.jl. We choose these specific ones to improve code coverage, as they are not tested in
# any elixirs.
@test min_max_speed_einfeldt(u, u, orientation, equations) ==
min_max_speed_einfeldt(u, u, orientation, equations_trixi)
@test min_max_speed_davis(u, u, orientation, equations) ==
min_max_speed_davis(u, u, orientation, equations_trixi)
@test max_abs_speed_naive(u, u, orientation, equations) ==
max_abs_speed_naive(u, u, orientation, equations_trixi)
end
end

end # module

0 comments on commit b58e902

Please sign in to comment.