Path: blob/main/examples/tree_3d_dgsem/elixir_euler_blob_amr.jl
5586 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the compressible Euler equations5gamma = 5 / 36equations = CompressibleEulerEquations3D(gamma)78"""9initial_condition_blob(x, t, equations::CompressibleEulerEquations3D)1011The blob test case taken from12- Agertz et al. (2006)13Fundamental differences between SPH and grid methods14[arXiv: astro-ph/0610051](https://arxiv.org/abs/astro-ph/0610051)15"""16function initial_condition_blob(x, t, equations::CompressibleEulerEquations3D)17# blob test case, see Agertz et al. https://arxiv.org/pdf/astro-ph/0610051.pdf18# other reference: https://doi.org/10.1111/j.1365-2966.2007.12183.x19# change discontinuity to tanh20# typical domain is rectangular, we change it to a square21# resolution 128^3, 256^322# domain size is [-20.0,20.0]^323# gamma = 5/3 for this test case24R = 1.0 # radius of the blob25# background density26rho = 1.027Chi = 10.0 # density contrast28# reference time of characteristic growth of KH instability equal to 1.029tau_kh = 1.030tau_cr = tau_kh / 1.6 # crushing time31# determine background velocity32v1 = 2 * R * sqrt(Chi) / tau_cr33v2 = 0.034v3 = 0.035Ma0 = 2.7 # background flow Mach number Ma=v/c36c = v1 / Ma0 # sound speed37# use perfect gas assumption to compute background pressure via the sound speed c^2 = gamma * pressure/density38p = c * c * rho / equations.gamma39# initial center of the blob40inicenter = [-15, 0, 0]41x_rel = x - inicenter42r = sqrt(x_rel[1]^2 + x_rel[2]^2 + x_rel[3]^2)43# steepness of the tanh transition zone44slope = 245# density blob46rho = rho +47(Chi - 1) * 0.5 * (1 + (tanh(slope * (r + R)) - (tanh(slope * (r - R)) + 1)))48# velocity blob is zero49v1 = v1 - v1 * 0.5 * (1 + (tanh(slope * (r + R)) - (tanh(slope * (r - R)) + 1)))50return prim2cons(SVector(rho, v1, v2, v3, p), equations)51end52initial_condition = initial_condition_blob5354volume_flux = flux_ranocha55solver = DGSEM(polydeg = 3, surface_flux = flux_hllc,56volume_integral = VolumeIntegralFluxDifferencing(volume_flux))5758coordinates_min = (-20.0, -20.0, -20.0)59coordinates_max = (20.0, 20.0, 20.0)6061refinement_patches = ((type = "box", coordinates_min = (-20.0, -10.0, -10.0),62coordinates_max = (-10.0, 10.0, 10.0)),63(type = "box", coordinates_min = (-20.0, -5.0, -5.0),64coordinates_max = (-10.0, 5.0, 5.0)),65(type = "box", coordinates_min = (-17.0, -2.0, -2.0),66coordinates_max = (-13.0, 2.0, 2.0)),67(type = "box", coordinates_min = (-17.0, -2.0, -2.0),68coordinates_max = (-13.0, 2.0, 2.0)))69mesh = TreeMesh(coordinates_min, coordinates_max,70initial_refinement_level = 2,71refinement_patches = refinement_patches,72n_cells_max = 100_000, periodicity = true)7374semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;75boundary_conditions = boundary_condition_periodic)7677###############################################################################78# ODE solvers, callbacks etc.7980tspan = (0.0, 2.5)81ode = semidiscretize(semi, tspan)8283summary_callback = SummaryCallback()8485analysis_interval = 20086analysis_callback = AnalysisCallback(semi, interval = analysis_interval)8788alive_callback = AliveCallback(analysis_interval = analysis_interval)8990save_solution = SaveSolutionCallback(interval = 200,91save_initial_solution = true,92save_final_solution = true,93solution_variables = cons2prim)9495amr_indicator = IndicatorLöhner(semi,96variable = Trixi.density)97amr_controller = ControllerThreeLevel(semi, amr_indicator,98base_level = 1,99med_level = 0, med_threshold = 0.1, # med_level = current level100max_level = 6, max_threshold = 0.3)101amr_callback = AMRCallback(semi, amr_controller,102interval = 3,103adapt_initial_condition = false,104adapt_initial_condition_only_refine = true)105106stepsize_callback = StepsizeCallback(cfl = 1.7)107108callbacks = CallbackSet(summary_callback,109analysis_callback, alive_callback,110save_solution,111amr_callback, stepsize_callback)112113stage_limiter! = PositivityPreservingLimiterZhangShu(thresholds = (1.0e-4, 1.0e-4),114variables = (Trixi.density, pressure))115116###############################################################################117# run the simulation118119sol = solve(ode, CarpenterKennedy2N54(stage_limiter!, williamson_condition = false);120dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback121ode_default_options()..., callback = callbacks);122123124