From 74f94fb4e49ca61fbd63a006eecdf68f40f625b4 Mon Sep 17 00:00:00 2001 From: Yik Haw Teoh Date: Thu, 7 Dec 2023 21:36:18 -0600 Subject: [PATCH] Added test cases for entropy2cons and cons2entropy for compressible multicomponent euler 1d and 2d --- test/test_tree_1d_eulermulti.jl | 13 +++++++++++++ test/test_tree_2d_eulermulti.jl | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/test/test_tree_1d_eulermulti.jl b/test/test_tree_1d_eulermulti.jl index bd86de928e3..3c763809258 100644 --- a/test/test_tree_1d_eulermulti.jl +++ b/test/test_tree_1d_eulermulti.jl @@ -2,6 +2,7 @@ module TestExamples1DEulerMulti using Test using Trixi +using ForwardDiff include("test_trixi.jl") @@ -10,6 +11,18 @@ EXAMPLES_DIR = pkgdir(Trixi, "examples", "tree_1d_dgsem") @testset "Compressible Euler Multicomponent" begin #! format: noindent +@trixi_testset "Testing entropy2cons and cons2entropy" begin + using ForwardDiff + gammas = (1.3272378792562836, 1.5269959187969864, 1.8362285750521512, 1.0409061360276926, 1.4652015053812224, 1.3626493264184423) + gas_constants = (1.817636851910076, 6.760820475922636, 5.588953939749113, 6.31574782981543, 3.362932038038397, 3.212779569399733) + equations = CompressibleEulerMulticomponentEquations1D(gammas=SVector{length(gammas)}(gammas...), + gas_constants=SVector{length(gas_constants)}(gas_constants...)) + u = [-1.4632513788889214, 0.9908786980927811, 0.2909066990257628, 0.6256623915420473, 0.4905882754313441, 0.14481800501749112, 1.0333532872771651, 0.6805599818745411] + w = cons2entropy(u, equations) + @test w ≈ ForwardDiff.gradient(u -> total_entropy(u, equations), u) + @test entropy2cons(w, equations) ≈ u +end + @trixi_testset "elixir_eulermulti_ec.jl" begin @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_eulermulti_ec.jl"), l2=[0.15330089521538684, 0.4417674632047301, diff --git a/test/test_tree_2d_eulermulti.jl b/test/test_tree_2d_eulermulti.jl index 30d52b37b96..4f65462cfa3 100644 --- a/test/test_tree_2d_eulermulti.jl +++ b/test/test_tree_2d_eulermulti.jl @@ -10,6 +10,18 @@ EXAMPLES_DIR = pkgdir(Trixi, "examples", "tree_2d_dgsem") @testset "Compressible Euler Multicomponent" begin #! format: noindent +@trixi_testset "Testing entropy2cons and cons2entropy" begin + using ForwardDiff + gammas = (1.1546412974182538, 1.1171560258914812, 1.097107661471476, 1.0587601652669245, 1.6209889683979308, 1.6732209755396386, 1.2954303574165822) + gas_constants = (5.969461071171914, 3.6660802003290183, 6.639008614675539, 8.116604827140456, 6.190706056680031, 1.6795013743693712, 2.197737590916966) + equations = CompressibleEulerMulticomponentEquations2D(gammas=SVector{length(gammas)}(gammas...), + gas_constants=SVector{length(gas_constants)}(gas_constants...)) + u = [-1.7433292819144075, 0.8844413258376495, 0.6050737175812364, 0.8261998359817043, 1.0801186290896465, 0.505654488367698, 0.6364415555805734, 0.851669392285058, 0.31219606420306223, 1.0930477805612038] + w = cons2entropy(u, equations) + @test w ≈ ForwardDiff.gradient(u -> total_entropy(u, equations), u) + @test entropy2cons(w, equations) ≈ u +end + # NOTE: Some of the L2/Linf errors are comparably large. This is due to the fact that some of the # simulations are set up with dimensional states. For example, the reference pressure in SI # units is 101325 Pa, i.e., pressure has values of O(10^5)