Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/p4est_2d_dgsem/elixir_euler_NACA0012airfoil_mach085.jl
2055 views
1
using OrdinaryDiffEqSSPRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the compressible Euler equations
6
7
equations = CompressibleEulerEquations2D(1.4)
8
9
p_inf() = 1.0
10
rho_inf() = p_inf() / (1.0 * 287.87) # p_inf = 1.0, T = 1, R = 287.87
11
mach_inf() = 0.85
12
aoa() = pi / 180.0 # 1 Degree angle of attack
13
c_inf(equations) = sqrt(equations.gamma * p_inf() / rho_inf())
14
u_inf(equations) = mach_inf() * c_inf(equations)
15
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)
20
v1 = u_inf(equations) * cos(aoa())
21
v2 = u_inf(equations) * sin(aoa())
22
23
prim = SVector(rho_inf(), v1, v2, p_inf())
24
return prim2cons(prim, equations)
25
end
26
27
initial_condition = initial_condition_mach085_flow
28
29
volume_flux = flux_ranocha_turbo
30
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
31
# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.
32
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
33
# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.
34
# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.
35
# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the
36
# `StepsizeCallback` (CFL-Condition) and less diffusion.
37
surface_flux = FluxLaxFriedrichs(max_abs_speed_naive)
38
39
polydeg = 3
40
basis = LobattoLegendreBasis(polydeg)
41
shock_indicator = IndicatorHennemannGassner(equations, basis,
42
alpha_max = 0.5,
43
alpha_min = 0.001,
44
alpha_smooth = true,
45
variable = density_pressure)
46
volume_integral = VolumeIntegralShockCapturingHG(shock_indicator;
47
volume_flux_dg = volume_flux,
48
volume_flux_fv = surface_flux)
49
solver = DGSEM(polydeg = polydeg, surface_flux = surface_flux,
50
volume_integral = volume_integral)
51
52
mesh_file = Trixi.download("https://gist.githubusercontent.com/Arpit-Babbar/339662b4b46164a016e35c81c66383bb/raw/8bf94f5b426ba907ace87405cfcc1dcc2ef7cbda/NACA0012.inp",
53
joinpath(@__DIR__, "NACA0012.inp"))
54
55
mesh = P4estMesh{2}(mesh_file)
56
57
# The outer boundary is constant but subsonic, so we cannot compute the
58
# boundary flux for the external information alone. Thus, we use the numerical flux to distinguish
59
# between inflow and outflow characteristics
60
@inline function boundary_condition_subsonic_constant(u_inner,
61
normal_direction::AbstractVector, x,
62
t,
63
surface_flux_function,
64
equations::CompressibleEulerEquations2D)
65
u_boundary = initial_condition_mach085_flow(x, t, equations)
66
67
return flux_hll(u_inner, u_boundary, normal_direction, equations)
68
end
69
70
boundary_conditions = Dict(:Left => boundary_condition_subsonic_constant,
71
:Right => boundary_condition_subsonic_constant,
72
:Top => boundary_condition_subsonic_constant,
73
:Bottom => boundary_condition_subsonic_constant,
74
:AirfoilBottom => boundary_condition_slip_wall,
75
:AirfoilTop => boundary_condition_slip_wall)
76
77
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
78
boundary_conditions = boundary_conditions)
79
80
###############################################################################
81
# ODE solvers
82
83
# Run for a long time to reach a steady state
84
tspan = (0.0, 20.0)
85
ode = semidiscretize(semi, tspan)
86
87
# Callbacks
88
89
summary_callback = SummaryCallback()
90
91
analysis_interval = 2000
92
93
l_inf = 1.0 # Length of airfoil
94
95
force_boundary_names = (:AirfoilBottom, :AirfoilTop)
96
drag_coefficient = AnalysisSurfaceIntegral(force_boundary_names,
97
DragCoefficientPressure2D(aoa(), rho_inf(),
98
u_inf(equations),
99
l_inf))
100
101
lift_coefficient = AnalysisSurfaceIntegral(force_boundary_names,
102
LiftCoefficientPressure2D(aoa(), rho_inf(),
103
u_inf(equations),
104
l_inf))
105
106
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
107
output_directory = "out",
108
save_analysis = true,
109
analysis_integrals = (drag_coefficient,
110
lift_coefficient))
111
112
alive_callback = AliveCallback(analysis_interval = analysis_interval)
113
114
save_solution = SaveSolutionCallback(interval = 500,
115
save_initial_solution = true,
116
save_final_solution = true,
117
solution_variables = cons2prim)
118
119
stepsize_callback = StepsizeCallback(cfl = 1.0)
120
121
amr_indicator = IndicatorLöhner(semi, variable = Trixi.density)
122
123
amr_controller = ControllerThreeLevel(semi, amr_indicator,
124
base_level = 1,
125
med_level = 3, med_threshold = 0.05,
126
max_level = 4, max_threshold = 0.1)
127
128
amr_interval = 100
129
amr_callback = AMRCallback(semi, amr_controller,
130
interval = amr_interval,
131
adapt_initial_condition = true,
132
adapt_initial_condition_only_refine = true)
133
134
save_restart = SaveRestartCallback(interval = 10_000,
135
save_final_restart = true)
136
137
callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback,
138
save_solution, save_restart,
139
stepsize_callback, amr_callback)
140
141
###############################################################################
142
# run the simulation
143
sol = solve(ode, SSPRK54(thread = Trixi.True());
144
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
145
ode_default_options()..., callback = callbacks);
146
147