Path: blob/main/examples/tree_3d_dgsem/elixir_euler_blob_amr.jl
2055 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)7374semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)7576###############################################################################77# ODE solvers, callbacks etc.7879tspan = (0.0, 2.5)80ode = semidiscretize(semi, tspan)8182summary_callback = SummaryCallback()8384analysis_interval = 20085analysis_callback = AnalysisCallback(semi, interval = analysis_interval)8687alive_callback = AliveCallback(analysis_interval = analysis_interval)8889save_solution = SaveSolutionCallback(interval = 200,90save_initial_solution = true,91save_final_solution = true,92solution_variables = cons2prim)9394amr_indicator = IndicatorLöhner(semi,95variable = Trixi.density)96amr_controller = ControllerThreeLevel(semi, amr_indicator,97base_level = 1,98med_level = 0, med_threshold = 0.1, # med_level = current level99max_level = 6, max_threshold = 0.3)100amr_callback = AMRCallback(semi, amr_controller,101interval = 3,102adapt_initial_condition = false,103adapt_initial_condition_only_refine = true)104105stepsize_callback = StepsizeCallback(cfl = 1.7)106107callbacks = CallbackSet(summary_callback,108analysis_callback, alive_callback,109save_solution,110amr_callback, stepsize_callback)111112stage_limiter! = PositivityPreservingLimiterZhangShu(thresholds = (1.0e-4, 1.0e-4),113variables = (Trixi.density, pressure))114115###############################################################################116# run the simulation117118sol = solve(ode, CarpenterKennedy2N54(stage_limiter!, williamson_condition = false);119dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback120ode_default_options()..., callback = callbacks);121122123