Skip to content

Commit a5a6e27

Browse files
Example for restarting hyperbolic-parabolic from purely hyperbolic (#2452)
* Example for restarting hyperbolic-parabolic from purely hyperbolic * fix file * test vals * comments + interval
1 parent 73691fc commit a5a6e27

File tree

3 files changed

+122
-3
lines changed

3 files changed

+122
-3
lines changed

examples/p4est_2d_dgsem/elixir_euler_NACA0012airfoil_mach085.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ aoa() = pi / 180.0 # 1 Degree angle of attack
1313
c_inf(equations) = sqrt(equations.gamma * p_inf() / rho_inf())
1414
u_inf(equations) = mach_inf() * c_inf(equations)
1515

16-
@inline function initial_condition_mach085_flow(x, t,
17-
equations::CompressibleEulerEquations2D)
16+
# Leave `equations` unspecified here to enable usage of `BoundaryConditionDirichlet(initial_condition)`
17+
# in the "elixir_navierstokes_NACA0012airfoil_mach085_restart.jl" which includes this elixir to
18+
# demonstrate restarting/initializing a hyperbolic-parabolic simulation from a purely hyperbolic simulation.
19+
@inline function initial_condition_mach085_flow(x, t, equations)
1820
v1 = u_inf(equations) * cos(aoa())
1921
v2 = u_inf(equations) * sin(aoa())
2022

@@ -122,7 +124,11 @@ amr_callback = AMRCallback(semi, amr_controller,
122124
adapt_initial_condition = true,
123125
adapt_initial_condition_only_refine = true)
124126

125-
callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback, save_solution,
127+
save_restart = SaveRestartCallback(interval = 10_000,
128+
save_final_restart = true)
129+
130+
callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback,
131+
save_solution, save_restart,
126132
stepsize_callback, amr_callback)
127133

128134
###############################################################################
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using Trixi
2+
3+
###############################################################################
4+
# This example shows that one can restart a hyperbolic-parabolic simulation from
5+
# a purely hyperbolic simulation/restart file.
6+
7+
base_elixir = "elixir_euler_NACA0012airfoil_mach085.jl"
8+
trixi_include(@__MODULE__, joinpath(@__DIR__, base_elixir),
9+
tspan = (0.0, 0.005))
10+
11+
###############################################################################
12+
# semidiscretization of the compressible Navier-Stokes equations
13+
14+
Re() = 50000.0
15+
airfoil_cord_length() = 1.0
16+
mu() = rho_inf() * u_inf(equations) * airfoil_cord_length() / Re()
17+
18+
prandtl_number() = 0.72
19+
20+
equations_parabolic = CompressibleNavierStokesDiffusion2D(equations, mu = mu(),
21+
Prandtl = prandtl_number(),
22+
gradient_variables = GradientVariablesPrimitive())
23+
24+
###############################################################################
25+
26+
velocity_bc_airfoil = NoSlip((x, t, equations) -> SVector(0.0, 0.0))
27+
heat_bc = Adiabatic((x, t, equations) -> 0.0)
28+
boundary_condition_airfoil = BoundaryConditionNavierStokesWall(velocity_bc_airfoil, heat_bc)
29+
30+
boundary_condition_free_stream = BoundaryConditionDirichlet(initial_condition)
31+
32+
boundary_conditions_hyp = Dict(:Left => boundary_condition_free_stream,
33+
:Right => boundary_condition_free_stream,
34+
:Top => boundary_condition_free_stream,
35+
:Bottom => boundary_condition_free_stream,
36+
:AirfoilBottom => boundary_condition_slip_wall,
37+
:AirfoilTop => boundary_condition_slip_wall)
38+
39+
boundary_conditions_para = Dict(:Left => boundary_condition_free_stream,
40+
:Right => boundary_condition_free_stream,
41+
:Top => boundary_condition_free_stream,
42+
:Bottom => boundary_condition_free_stream,
43+
:AirfoilBottom => boundary_condition_airfoil,
44+
:AirfoilTop => boundary_condition_airfoil)
45+
46+
restart_file = "restart_000000584.h5"
47+
restart_filename = joinpath("out", restart_file)
48+
mesh = load_mesh(restart_filename)
49+
50+
semi = SemidiscretizationHyperbolicParabolic(mesh, (equations, equations_parabolic),
51+
initial_condition, solver;
52+
boundary_conditions = (boundary_conditions_hyp,
53+
boundary_conditions_para))
54+
55+
###############################################################################
56+
57+
tspan = (0.0, 10.0)
58+
dt_restart = load_dt(restart_filename)
59+
ode = semidiscretize(semi, tspan, restart_filename)
60+
61+
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
62+
output_directory = "out",
63+
save_analysis = true,
64+
analysis_integrals = (drag_coefficient,
65+
lift_coefficient))
66+
67+
amr_indicator = IndicatorLöhner(semi, variable = Trixi.density)
68+
69+
amr_controller = ControllerThreeLevel(semi, amr_indicator,
70+
base_level = 1,
71+
med_level = 3, med_threshold = 0.05,
72+
max_level = 4, max_threshold = 0.1)
73+
74+
amr_interval = 100
75+
amr_callback = AMRCallback(semi, amr_controller,
76+
interval = amr_interval,
77+
adapt_initial_condition = true,
78+
adapt_initial_condition_only_refine = true)
79+
80+
callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback,
81+
save_solution, save_restart,
82+
stepsize_callback, amr_callback)
83+
84+
###############################################################################
85+
86+
sol = solve(ode, SSPRK54(thread = Trixi.True());
87+
dt = dt_restart,
88+
ode_default_options()..., callback = callbacks);

test/test_parabolic_2d.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,31 @@ end
816816
@test isapprox(lift_f, 0.005621910087395724, atol = 1e-13)
817817
end
818818

819+
@trixi_testset "elixir_navierstokes_NACA0012airfoil_mach085_restart.jl" begin
820+
@test_trixi_include(joinpath(examples_dir(), "p4est_2d_dgsem",
821+
"elixir_navierstokes_NACA0012airfoil_mach085_restart.jl"),
822+
l2=[
823+
6.191672324705442e-6,
824+
0.00011583392224949682,
825+
0.00011897020463459889,
826+
0.006467379086802275
827+
],
828+
linf=[
829+
0.0017446176443216936,
830+
0.06961708834164942,
831+
0.037063246278530367,
832+
1.4435072005258793
833+
], tspan=(0.0, 0.01),)
834+
# Ensure that we do not have excessive memory allocations
835+
# (e.g., from type instabilities)
836+
let
837+
t = sol.t[end]
838+
u_ode = sol.u[end]
839+
du_ode = similar(u_ode)
840+
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
841+
end
842+
end
843+
819844
@trixi_testset "P4estMesh2D: elixir_navierstokes_viscous_shock.jl" begin
820845
@test_trixi_include(joinpath(examples_dir(), "p4est_2d_dgsem",
821846
"elixir_navierstokes_viscous_shock.jl"),

0 commit comments

Comments
 (0)