Path: blob/main/test/test_performance_specializations_2d.jl
2055 views
module TestPerformanceSpecializations2D12using Test3using Trixi45include("test_trixi.jl")67EXAMPLES_DIR = examples_dir()89# Start with a clean environment: remove Trixi.jl output directory if it exists10outdir = "out"11isdir(outdir) && rm(outdir, recursive = true)1213@testset "Performance specializations 2D" begin14#! format: noindent1516@timed_testset "TreeMesh2D, flux_shima_etal_turbo" begin17trixi_include(@__MODULE__,18joinpath(EXAMPLES_DIR, "tree_2d_dgsem", "elixir_euler_ec.jl"),19initial_refinement_level = 0, tspan = (0.0, 0.0), polydeg = 3,20volume_flux = flux_shima_etal_turbo,21surface_flux = flux_shima_etal_turbo)22u_ode = copy(sol.u[end])23du_ode = zero(u_ode)2425# Preserve original memory since it will be `unsafe_wrap`ped and might26# thus otherwise be garbage collected27GC.@preserve u_ode du_ode begin28u = Trixi.wrap_array(u_ode, semi)29du = Trixi.wrap_array(du_ode, semi)30nonconservative_terms = Trixi.have_nonconservative_terms(semi.equations)3132# Call the optimized default version33du .= 034Trixi.flux_differencing_kernel!(du, u, 1, semi.mesh,35nonconservative_terms, semi.equations,36semi.solver.volume_integral.volume_flux,37semi.solver, semi.cache, true)38du_specialized = du[:, :, :, 1]3940# Call the plain version - note the argument type `Function` of41# `semi.solver.volume_integral.volume_flux`42du .= 043invoke(Trixi.flux_differencing_kernel!,44Tuple{typeof(du), typeof(u), Integer, typeof(semi.mesh),45typeof(nonconservative_terms), typeof(semi.equations),46Function, typeof(semi.solver), typeof(semi.cache), Bool},47du, u, 1, semi.mesh,48nonconservative_terms, semi.equations,49semi.solver.volume_integral.volume_flux, semi.solver, semi.cache, true)50du_baseline = du[:, :, :, 1]5152@test du_specialized ≈ du_baseline53end54end5556@timed_testset "TreeMesh2D, flux_ranocha_turbo" begin57trixi_include(@__MODULE__,58joinpath(EXAMPLES_DIR, "tree_2d_dgsem", "elixir_euler_ec.jl"),59initial_refinement_level = 0, tspan = (0.0, 0.0), polydeg = 3,60volume_flux = flux_ranocha_turbo, surface_flux = flux_ranocha_turbo)61u_ode = copy(sol.u[end])62du_ode = zero(u_ode)6364# Preserve original memory since it will be `unsafe_wrap`ped and might65# thus otherwise be garbage collected66GC.@preserve u_ode du_ode begin67u = Trixi.wrap_array(u_ode, semi)68du = Trixi.wrap_array(du_ode, semi)69nonconservative_terms = Trixi.have_nonconservative_terms(semi.equations)7071# Call the optimized default version72du .= 073Trixi.flux_differencing_kernel!(du, u, 1, semi.mesh,74nonconservative_terms, semi.equations,75semi.solver.volume_integral.volume_flux,76semi.solver, semi.cache, true)77du_specialized = du[:, :, :, 1]7879# Call the plain version - note the argument type `Function` of80# `semi.solver.volume_integral.volume_flux`81du .= 082invoke(Trixi.flux_differencing_kernel!,83Tuple{typeof(du), typeof(u), Integer, typeof(semi.mesh),84typeof(nonconservative_terms), typeof(semi.equations),85Function, typeof(semi.solver), typeof(semi.cache), Bool},86du, u, 1, semi.mesh,87nonconservative_terms, semi.equations,88semi.solver.volume_integral.volume_flux, semi.solver, semi.cache, true)89du_baseline = du[:, :, :, 1]9091@test du_specialized ≈ du_baseline92end93end9495@timed_testset "StructuredMesh2D, flux_shima_etal_turbo" begin96trixi_include(@__MODULE__,97joinpath(EXAMPLES_DIR, "structured_2d_dgsem", "elixir_euler_ec.jl"),98cells_per_dimension = (1, 1), tspan = (0.0, 0.0), polydeg = 3,99volume_flux = flux_shima_etal_turbo,100surface_flux = flux_shima_etal_turbo)101u_ode = copy(sol.u[end])102du_ode = zero(u_ode)103104# Preserve original memory since it will be `unsafe_wrap`ped and might105# thus otherwise be garbage collected106GC.@preserve u_ode du_ode begin107u = Trixi.wrap_array(u_ode, semi)108du = Trixi.wrap_array(du_ode, semi)109nonconservative_terms = Trixi.have_nonconservative_terms(semi.equations)110111# Call the optimized default version112du .= 0113Trixi.flux_differencing_kernel!(du, u, 1, semi.mesh,114nonconservative_terms, semi.equations,115semi.solver.volume_integral.volume_flux,116semi.solver, semi.cache, true)117du_specialized = du[:, :, :, 1]118119# Call the plain version - note the argument type `Function` of120# `semi.solver.volume_integral.volume_flux`121du .= 0122invoke(Trixi.flux_differencing_kernel!,123Tuple{typeof(du), typeof(u), Integer, typeof(semi.mesh),124typeof(nonconservative_terms), typeof(semi.equations),125Function, typeof(semi.solver), typeof(semi.cache), Bool},126du, u, 1, semi.mesh,127nonconservative_terms, semi.equations,128semi.solver.volume_integral.volume_flux, semi.solver, semi.cache, true)129du_baseline = du[:, :, :, 1]130131@test du_specialized ≈ du_baseline132end133end134135@timed_testset "StructuredMesh2D, flux_ranocha_turbo" begin136trixi_include(@__MODULE__,137joinpath(EXAMPLES_DIR, "structured_2d_dgsem", "elixir_euler_ec.jl"),138cells_per_dimension = (1, 1), tspan = (0.0, 0.0), polydeg = 3,139volume_flux = flux_ranocha_turbo, surface_flux = flux_ranocha_turbo)140u_ode = copy(sol.u[end])141du_ode = zero(u_ode)142143# Preserve original memory since it will be `unsafe_wrap`ped and might144# thus otherwise be garbage collected145GC.@preserve u_ode du_ode begin146u = Trixi.wrap_array(u_ode, semi)147du = Trixi.wrap_array(du_ode, semi)148nonconservative_terms = Trixi.have_nonconservative_terms(semi.equations)149150# Call the optimized default version151du .= 0152Trixi.flux_differencing_kernel!(du, u, 1, semi.mesh,153nonconservative_terms, semi.equations,154semi.solver.volume_integral.volume_flux,155semi.solver, semi.cache, true)156du_specialized = du[:, :, :, 1]157158# Call the plain version - note the argument type `Function` of159# `semi.solver.volume_integral.volume_flux`160du .= 0161invoke(Trixi.flux_differencing_kernel!,162Tuple{typeof(du), typeof(u), Integer, typeof(semi.mesh),163typeof(nonconservative_terms), typeof(semi.equations),164Function, typeof(semi.solver), typeof(semi.cache), Bool},165du, u, 1, semi.mesh,166nonconservative_terms, semi.equations,167semi.solver.volume_integral.volume_flux, semi.solver, semi.cache, true)168du_baseline = du[:, :, :, 1]169170@test du_specialized ≈ du_baseline171end172end173end174175# Clean up afterwards: delete Trixi.jl output directory176@test_nowarn rm(outdir, recursive = true)177178end #module179180181