Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • dg/dg1d.jl
1 result
Show changes
Showing
with 49 additions and 262 deletions
File added
[EquationOfState]
idealgas_gamma = 1.4
eos = "idealgas"
[EulerEq]
id = "sod_shock_tube"
bc = "from_id"
[Evolution]
cfl = 0.4
tend = 0.2
[Mesh]
periodic = [false]
range = [-1.0, 1.0]
k = 512
scheme = "FV"
[Output]
variables = ["rho", "q", "E"]
every_dt = 0.01
File added
[Evolution]
cfl = 0.1
tend = 1.4
[HeatEq]
id = "sine"
id_sine_width = 4.0 # =^= domain size
# id = "gaussian"
# id_gaussian_width = 0.2
id_sine_width = 4.0
[Mesh]
range = [ -2.0, 2.0 ]
cfl = 0.1
n = 4
range = [-2.0, 2.0]
k = 20
basis = "lgl"
n = 4
[Output]
variables = ["u", "q"]
every_dt = 0.1
every_iteration = 0
every_dt = 0.1
variables = [ "u", "q" ]
[Evolution]
tend = 1.4
[Evolution]
cfl = 0.1
tend = 1.4
[HeatEq]
id = "sine"
id_sine_width = 4.0 # =^= domain size
id_sine_width = 4.0
[Mesh]
range = [ -2.0, 2.0 ]
cfl = 0.1
n = 4
range = [-2.0, 2.0]
k = 20
basis = "lgl"
n = 4
[Output]
variables = ["u", "q"]
every_dt = 0.1
every_iteration = 0
every_dt = 0.1
variables = [ "u", "q" ]
[Evolution]
tend = 1.4
No preview for this file type
......@@ -7,7 +7,6 @@ id = "smooth"
[Mesh]
range = [ -1.0, 1.0 ]
cfl = 0.10
n = 4
k = 67
basis = "lgl"
......@@ -19,6 +18,7 @@ variables = [ "D", "S", "tau" ]
[Evolution]
tend = 0.4
cfl = 0.10
[TCI]
method = "mda"
......@@ -7,6 +7,9 @@ default_abstol = 1e-8
[advection_sine]
variables = [ "u" ]
[fv_advection_sine]
variables = [ "u" ]
[advection_sine_glgl]
variables = [ "u" ]
......@@ -49,10 +52,13 @@ variables = [ "rho", "q", "E" ]
# [euler_sod_shock_tube_entropyav]
# variables = [ "rho", "q", "E" ]
[fv_euler_sod_shock_tube]
variables = [ "rho", "q", "E" ]
# TODO Disabled due to refactoring
# [srhd_smooth]
# # stops before discontinuity appears
# variables = [ "D", "S", "tau" ]
[srhd_smooth]
# stops before discontinuity appears
variables = [ "D", "S", "tau" ]
# 2D tests
......
......@@ -193,50 +193,4 @@ end
end
@testset "broadcast_volume!" begin
# some definitions
struct MyEquation end
# need an @eval here, because of nested @testsets
@eval @with_signature function compute_rhs(eq::MyEquation)
@accepts u, v
rhs_u = 2.0 * u
rhs_v = 3.0 * v - 1.0
@returns rhs_u, rhs_v
end
# setup cache
cache = Cache(100, 50, 10)
dg1d.register_variables!(cache,
dynamic_variablenames = (:u, :v),
rhs_variablenames = (:rhs_u, :rhs_v))
# prepare data
@unpack u, v = get_dynamic_variables(cache)
@unpack rhs_u, rhs_v = get_rhs_variables(cache)
# fill u,v with random numbers
map!.(el -> randn(), [u, v], [u, v])
# compute
broadcast_volume!(compute_rhs, MyEquation(), cache)
expected_rhs_u = @. 2.0 * u
expected_rhs_v = @. 3.0 * v - 1.0
@test all(isapprox.(rhs_u, expected_rhs_u))
@test all(isapprox.(rhs_v, expected_rhs_v))
#### edge cases
# call broadcast_volume! with function that was not defined with @with_signature
@test_throws ErrorException broadcast_volume!(args -> args, MyEquation(), cache)
# call broadcast_volume! with function and wrong dispatch type
struct WrongEquation end
@test_throws ErrorException broadcast_volume!(args -> args, WrongEquation(), cache)
end
end
......@@ -136,7 +136,6 @@ end
callback_fullstep=(u,t::String,n::Int)->nothing)
@test_throws ArgumentError evolve(rhs!, u0, dt, tend, alg,
callback_substep=(u,t::Vector{Real},n::Int)->nothing)
@test_throws ArgumentError evolve(rhs!, u0, dt, tend, alg, cfl=-0.1)
end
......
@testset "RiemannSolver" begin
# setup a new equation type
struct MyDummyEquation <: AbstractEquation end
function register_variables!(cache::Cache, eq::MyDummyEquation)
dg1d.register_variables!(cache, dynamic_variablenames = (:a, :b),
rhs_variablenames = (:f_a, :f_b),
cell_variablenames = (:max_v,))
end
# define methods needed for ApproxRiemannSolver interface
@with_signature function flux(::MyDummyEquation)
@accepts State(a, b)
f_a, f_b = a + b, a - b
@returns f_a, f_b
end
@with_signature function speed(::MyDummyEquation)
@accepts State(a, b)
max_v = max(1.0 + 1.0, 1.0 - 1.0)
@returns max_v
end
@with_signature function speed_no_state_tag(::MyDummyEquation)
@accepts a, b
max_v = max(1.0 + 1.0, 1.0 - 1.0)
@returns max_v
end
@with_signature function speed_wrong_states(::MyDummyEquation)
@accepts State(a, c)
max_v = max(1.0 + 1.0, 1.0 - 1.0)
@returns max_v
end
@testset "ApproxRiemannSolver" begin
mesh = Mesh1d()
cache = dg1d.cache(mesh)
equation = MyDummyEquation()
register_variables!(cache, equation)
### constructor
rsolver = ApproxRiemannSolver(flux, speed, equation)
### check registration
dg1d.register_variables!(cache, rsolver)
to_be_registered_bdry_vars = [ :nflx_a, :nflx_b ]
all_bdry_vars = dg1d.names(get_bdry_variables(cache))
@test issubset(to_be_registered_bdry_vars, all_bdry_vars)
### only test if implemented methods compute something when used with
### broadcasting_cached!; actual result should be verified with integration tests
# fill a, b with random numbers
@unpack a, b = get_dynamic_variables(cache)
map!.(el -> randn(), [a,b], [a,b])
for fn in [ lax_friedrich_flux, central_flux, mean_flux ]
broadcast_faces!(fn, rsolver, cache, mesh)
end
# mismatch between signatures of flux and speed functions
@test_throws AssertionError ApproxRiemannSolver(flux, speed_wrong_states, equation)
@test_throws AssertionError ApproxRiemannSolver(flux, speed_no_state_tag, equation)
end
# setup a new equation type
struct MyDummyEquation2d <: AbstractEquation end
function register_variables!(cache::Cache, eq::MyDummyEquation2d)
dg1d.register_variables!(cache, dynamic_variablenames = (:a, :b),
rhs_variablenames = (:f_a, :f_b),
cell_variablenames = (:max_v,))
end
# define methods needed for ApproxRiemannSolver interface
@with_signature function flux(::MyDummyEquation2d)
@accepts State(a), b
f_a1, f_a2 = a+b, a-b, a*b, a/b
@returns f_a1, f_a2
end
@with_signature function flux_wrong_returns(::MyDummyEquation2d)
@accepts State(a), b
f_a1, f_a2 = a+b, a-b, a*b, a/b
f_b1, fb_2 = 1.0, 2.0
@returns f_a1, f_a2, f_b1, f_b2
end
@with_signature function speed(::MyDummyEquation2d)
@accepts State(a), b
max_v = max(1.0 + 1.0, 1.0 - 1.0)
@returns max_v
end
@with_signature function speed_no_state_tag(::MyDummyEquation2d)
@accepts a, b
max_v = max(1.0 + 1.0, 1.0 - 1.0)
@returns max_v
end
@with_signature function speed_wrong_states(::MyDummyEquation2d)
@accepts State(a, c)
max_v = max(1.0 + 1.0, 1.0 - 1.0)
@returns max_v
end
@testset "ApproxRiemannSolver2d" begin
mesh = Mesh2d()
cache = dg1d.cache(mesh)
equation = MyDummyEquation2d()
register_variables!(cache, equation)
### constructor
rsolver = ApproxRiemannSolver2d(flux, speed, equation)
### check registration
dg1d.register_variables!(cache, rsolver)
to_be_registered_bdry_vars = [ :nflx_a, :nx, :ny #= normal vectors =# ]
all_bdry_vars = dg1d.names(get_bdry_variables(cache))
@test issubset(to_be_registered_bdry_vars, all_bdry_vars)
### only test if implemented methods compute something when used with
### broadcasting_cached!; actual result should be verified with integration tests
# fill a, b with random numbers
@unpack a, b = get_dynamic_variables(cache)
map!.(el -> randn(), [a,b], [a,b])
for fn in [ lax_friedrich_flux, central_flux, mean_flux ]
broadcast_faces!(fn, rsolver, cache, mesh)
end
# mismatch between signatures of flux and speed functions
@test_throws AssertionError ApproxRiemannSolver2d(flux, speed_wrong_states, equation)
@test_throws AssertionError ApproxRiemannSolver2d(flux, speed_no_state_tag, equation)
@test_throws AssertionError ApproxRiemannSolver2d(flux_wrong_returns, speed, equation)
end
@testset "BoundaryConditions" begin
mesh = Mesh1d()
cache = dg1d.cache(mesh)
equation = MyDummyEquation()
register_variables!(cache, equation)
### constructor
rsolver = ApproxRiemannSolver(flux, speed, equation)
dg1d.register_variables!(cache, rsolver)
lhs_bc = DirichletBC(t -> (0.0,1.0))
rhs_bc = OutflowBC()
bdryconds = BoundaryConditions(lhs_bc, rhs_bc, rsolver)
### only test if implemented methods compute something when used with
### broadcasting_cached!; actual result should be verified with integration tests
for fn in [ lax_friedrich_flux, central_flux ]
dg1d.broadcast_boundaryconditions!(fn, bdryconds, cache, mesh, 0.0)
end
### edge cases
# incompatible bdry conitions
@test_throws AssertionError BoundaryConditions(DirichletBC(t-> (0.0,)),
DirichletBC(t-> (0.0,1.0,2.0)),
rsolver)
# mismatch between boundary states and flux arguments
@test_throws AssertionError BoundaryConditions(DirichletBC(t-> (0.0,)),
DirichletBC(t-> (1.0,)),
rsolver)
# single periodic boundary does not make sense
@test_throws AssertionError BoundaryConditions(PeriodicBC(),
DirichletBC(t-> (1.0,)),
rsolver)
end
end
......@@ -13,7 +13,6 @@ include("test_objectcache.jl")
include("test_rootfinders.jl")
# include("test_refvector.jl")
include("test_with_signature.jl")
# include("test_riemannsolver.jl")
include("test_spectral.jl")
include("test_tensorbasis.jl")
include("test_box.jl")
......