module TestExamples2DEulerMulticomponent

using Test
using Trixi

include("test_trixi.jl")

# pathof(Trixi) returns /path/to/Trixi/src/Trixi.jl, dirname gives the parent directory
EXAMPLES_DIR = joinpath(pathof(Trixi) |> dirname |> dirname, "examples", "tree_2d_dgsem")

@testset "MHD Multicomponent" begin

  @trixi_testset "elixir_mhdmulti_ec.jl" begin
    @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_mhdmulti_ec.jl"),
      l2   = [0.04301155595653797, 0.0429973578727621, 0.025745530869947734, 0.16206102676791534, 0.01745438427233918, 0.01745523378100093, 0.026879482381500168, 0.00020380087569638123, 0.012094208262809793, 0.024188416525619587],
      linf = [0.3156206778985403, 0.3094169692980939, 0.2116756351925415, 0.9688251298546025, 0.09076254289155039, 0.09160589769497807, 0.15698032974768816, 0.006131914796912256, 0.0783928755595098, 0.1567857511190196])
  end

  @trixi_testset "elixir_mhdmulti_es.jl" begin
    @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_mhdmulti_es.jl"),
      l2   = [0.042511651022704613, 0.04250604885998708, 0.023846653305641972, 0.11554598944911021, 0.01636256247880442, 0.01636284413777288, 0.025815885276624734, 0.00023041275897137022, 0.010819647132572942, 0.021639294265145884],
      linf = [0.23483836992423804, 0.23500711333514657, 0.11900732096172402, 0.5334761163947968, 0.06168598081763488, 0.06170710018441339, 0.0957218767073531, 0.004187945734585529, 0.06209058954605229, 0.12418117909210458])
  end

  @trixi_testset "elixir_mhdmulti_convergence.jl" begin
    @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_mhdmulti_convergence.jl"),
      l2   = [0.00026086814345575545, 0.0002608681434558476, 0.00048401141419704093, 0.0003246315763252851, 0.0003655995669606298, 0.00036559956696067316, 0.0005007680779079482, 0.0003855610470758256, 5.258783225290134e-5, 0.00010517566450580267, 0.00021035132901160535],
      linf = [0.0015430152095171022, 0.0015430152095179052, 0.0023883101781443854, 0.0010097026785059748, 0.001880514662696009, 0.00188051466269612, 0.0026096395828504393, 0.0010868614907852264, 0.0002056455895989573, 0.0004112911791979146, 0.0008225823583958292])
  end

  @trixi_testset "elixir_mhdmulti_rotor.jl" begin
    @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_mhdmulti_rotor.jl"),
      l2   = [0.7176533615514566, 0.7229955636121396, 0.0, 0.834554078472726, 0.04749874413702431, 0.07911052149635948, 0.0, 0.001984674887414827, 0.19160481586887373, 0.09580240793443687],
      linf = [11.13806940653242, 11.018014654552669, 0.0, 12.446432961705831, 0.6353833312104487, 1.0674585003641777, 0.0, 0.06416407003456842, 3.489953221760654, 1.744976610880327],
      tspan = (0.0, 0.01))

  # TODO: nonconservative terms, remove
  @trixi_testset "elixir_mhdmulti_ec.jl with old nonconservative stuff" begin
    @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_mhdmulti_ec.jl"),
      l2   = [0.04301155595653797, 0.0429973578727621, 0.025745530869947734, 0.16206102676791534, 0.01745438427233918, 0.01745523378100093, 0.026879482381500168, 0.00020380087569638123, 0.012094208262809793, 0.024188416525619587],
      linf = [0.3156206778985403, 0.3094169692980939, 0.2116756351925415, 0.9688251298546025, 0.09076254289155039, 0.09160589769497807, 0.15698032974768816, 0.006131914796912256, 0.0783928755595098, 0.1567857511190196],
      volume_flux  = flux_derigs_etal,
      surface_flux = flux_derigs_etal)
  end
end

end

end # module
