Path: blob/main/examples/special_elixirs/elixir_euler_ad.jl
2055 views
# This example is described in more detail in the documentation of Trixi.jl12using Trixi, LinearAlgebra, ForwardDiff34equations = CompressibleEulerEquations2D(1.4)56mesh = TreeMesh((-1.0, -1.0), (1.0, 1.0),7initial_refinement_level = 2, n_cells_max = 10^5)89# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of10# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.11# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.12# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.13# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.14# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the15# `StepsizeCallback` (CFL-Condition) and less diffusion.16solver = DGSEM(polydeg = 3, surface_flux = FluxLaxFriedrichs(max_abs_speed_naive),17volume_integral = VolumeIntegralFluxDifferencing(flux_ranocha))1819"""20initial_condition_isentropic_vortex(x, t, equations::CompressibleEulerEquations2D)2122The classical isentropic vortex test case of23- Chi-Wang Shu (1997)24Essentially Non-Oscillatory and Weighted Essentially Non-Oscillatory25Schemes for Hyperbolic Conservation Laws26[NASA/CR-97-206253](https://ntrs.nasa.gov/citations/19980007543)27"""28function initial_condition_isentropic_vortex(x, t, equations::CompressibleEulerEquations2D)29# needs appropriate mesh size, e.g. [-10,-10]x[10,10]30# for error convergence: make sure that the end time is such that the vortex is back at the initial state!!31# for the current velocity and domain size: t_end should be a multiple of 20s32# initial center of the vortex33inicenter = SVector(0.0, 0.0)34# size and strength of the vortex35iniamplitude = 5.036# base flow37rho = 1.038v1 = 1.039v2 = 1.040vel = SVector(v1, v2)41p = 25.042rt = p / rho # ideal gas equation43t_loc = 0.044cent = inicenter + vel * t_loc # advection of center45# ATTENTION: handle periodic BC, but only for v1 = v2 = 1.0 (!!!!)46cent = x - cent # distance to center point47# cent = cross(iniaxis, cent) # distance to axis, tangent vector, length r48# cross product with iniaxis = [0, 0, 1]49cent = SVector(-cent[2], cent[1])50r2 = cent[1]^2 + cent[2]^251du = iniamplitude / (2 * π) * exp(0.5 * (1 - r2)) # vel. perturbation52dtemp = -(equations.gamma - 1) / (2 * equations.gamma * rt) * du^2 # isentropic53rho = rho * (1 + dtemp)^(1 / (equations.gamma - 1))54vel = vel + du * cent55v1, v2 = vel56p = p * (1 + dtemp)^(equations.gamma / (equations.gamma - 1))57prim = SVector(rho, v1, v2, p)58return prim2cons(prim, equations)59end60semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_isentropic_vortex,61solver)6263u0_ode = compute_coefficients(0.0, semi)6465J = ForwardDiff.jacobian((du_ode, γ) -> begin66equations_inner = CompressibleEulerEquations2D(first(γ))67semi_inner = Trixi.remake(semi, equations = equations_inner,68uEltype = eltype(γ))69Trixi.rhs!(du_ode, u0_ode, semi_inner, 0.0)70end, similar(u0_ode), [1.4]); # γ needs to be an `AbstractArray`717273