Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaLampert committed Sep 15, 2024
1 parent c1360b5 commit e5d29d3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ out*/
run
run/*
**/*.code-workspace
.vscode/
2 changes: 1 addition & 1 deletion src/equations/equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ varnames(::typeof(energy_total_modified), equations) = ("e_modified",)
Alias for [`energy_total_modified`](@ref).
"""
@inline function entropy_modified(q_global, equations::AbstractShallowWaterEquations, cache)
@inline function entropy_modified(q_global, equations::AbstractEquations, cache)
e = similar(q_global.x[begin])
return entropy_modified!(e, q_global, equations, cache)
end
Expand Down
6 changes: 3 additions & 3 deletions test/test_bbm_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ EXAMPLES_DIR = joinpath(examples_dir(), "bbm_1d")
cons_error=[7.105427357601002e-15],
change_waterheight=-7.105427357601002e-15,
change_entropy_modified=-4.4274395039067826e-7,
change_hamiltonian=-3.198066679033218e-6)
change_hamiltonian=-5.33011109249415e-7)

@test_allocations(semi, sol, allocs=5_000)

Expand Down Expand Up @@ -105,7 +105,7 @@ EXAMPLES_DIR = joinpath(examples_dir(), "bbm_1d")
cons_error=[5.329070518200751e-15],
change_waterheight=5.329070518200751e-15,
change_entropy_modified=0.0,
change_hamiltonian=-1.0308752962373546e-8)
change_hamiltonian=-1.7181174261082788e-9)

@test_allocations(semi, sol, allocs=5_000)
end
Expand All @@ -131,7 +131,7 @@ EXAMPLES_DIR = joinpath(examples_dir(), "bbm_1d")
cons_error=[1.1546319456101628e-14],
change_waterheight=-1.1546319456101628e-14,
change_entropy_modified=-4.4266038123907947e-7,
change_hamiltonian=-3.1871549026618595e-6)
change_hamiltonian=-5.311924822226644e-7)

@test_allocations(semi, sol, allocs=5_000)
end
Expand Down
23 changes: 21 additions & 2 deletions test/test_unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ using SparseArrays: sparse, SparseMatrixCSC
prim2phys,
energy_total_modified,
entropy_modified,
invariant_cubic,
hamiltonian,
]
for conversion in conversion_functions
@test DispersiveShallowWater.varnames(conversion, equations) isa Tuple
Expand All @@ -132,7 +132,26 @@ using SparseArrays: sparse, SparseMatrixCSC
@test @inferred(waterheight(q, equations)) == 42.0
@test @inferred(still_water_surface(q, equations)) == 0.0
@test @inferred(prim2phys(q, equations)) == @inferred(prim2prim(q, equations))
@test @inferred(hamiltonian(q, equations)) == 13230.0
@testset "energy_total_modified and hamiltonian" begin
initial_condition = initial_condition_manufactured
boundary_conditions = boundary_condition_periodic
mesh = @inferred Mesh1D(-1.0, 1.0, 10)
solver = Solver(mesh, 4)
semi = @inferred Semidiscretization(mesh, equations, initial_condition,
solver; boundary_conditions)
q = @inferred DispersiveShallowWater.compute_coefficients(initial_condition,
0.0, semi)
_, _, _, cache = @inferred DispersiveShallowWater.mesh_equations_solver_cache(semi)
e_modified = @inferred energy_total_modified(q, equations, cache)
e_modified_total = @inferred DispersiveShallowWater.integrate(e_modified, semi)
@test isapprox(e_modified_total, 19.76398144922061)
U_modified = @inferred entropy_modified(q, equations, cache)
U_modified_total = @inferred DispersiveShallowWater.integrate(U_modified, semi)
@test isapprox(U_modified_total, e_modified_total)
h = @inferred hamiltonian(q, equations, cache)
h_total = @inferred DispersiveShallowWater.integrate(h, semi)
@test isapprox(h_total, 0.5)
end
end

@testset "BBMBBMEquations1D" begin
Expand Down

0 comments on commit e5d29d3

Please sign in to comment.