Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/t8code_3d_dgsem/elixir_advection_unstructured_curved.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the linear advection equation
6
7
advection_velocity = (0.2, -0.7, 0.5)
8
equations = LinearScalarAdvectionEquation3D(advection_velocity)
9
10
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
11
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
12
13
initial_condition = initial_condition_convergence_test
14
15
boundary_condition = BoundaryConditionDirichlet(initial_condition)
16
boundary_conditions = Dict(:all => boundary_condition)
17
18
# Mapping as described in https://arxiv.org/abs/2012.12040 but with less warping.
19
# The mapping will be interpolated at tree level, and then refined without changing
20
# the geometry interpolant. The original mapping applied to this unstructured mesh
21
# causes some Jacobians to be negative, which makes the mesh invalid.
22
function mapping(xi, eta, zeta)
23
# Don't transform input variables between -1 and 1 onto [0,3] to obtain curved boundaries
24
# xi = 1.5 * xi_ + 1.5
25
# eta = 1.5 * eta_ + 1.5
26
# zeta = 1.5 * zeta_ + 1.5
27
28
y = eta +
29
1 / 6 * (cos(1.5 * pi * (2 * xi - 3) / 3) *
30
cos(0.5 * pi * (2 * eta - 3) / 3) *
31
cos(0.5 * pi * (2 * zeta - 3) / 3))
32
33
x = xi +
34
1 / 6 * (cos(0.5 * pi * (2 * xi - 3) / 3) *
35
cos(2 * pi * (2 * y - 3) / 3) *
36
cos(0.5 * pi * (2 * zeta - 3) / 3))
37
38
z = zeta +
39
1 / 6 * (cos(0.5 * pi * (2 * x - 3) / 3) *
40
cos(pi * (2 * y - 3) / 3) *
41
cos(0.5 * pi * (2 * zeta - 3) / 3))
42
43
return SVector(x, y, z)
44
end
45
46
# Unstructured mesh with 68 cells of the cube domain [-1, 1]^3
47
mesh_file = Trixi.download("https://gist.githubusercontent.com/efaulhaber/d45c8ac1e248618885fa7cc31a50ab40/raw/37fba24890ab37cfa49c39eae98b44faf4502882/cube_unstructured_1.inp",
48
joinpath(@__DIR__, "cube_unstructured_1.inp"))
49
50
mesh = T8codeMesh(mesh_file, 3; polydeg = 3,
51
mapping = mapping,
52
initial_refinement_level = 2)
53
54
# A semidiscretization collects data structures and functions for the spatial discretization
55
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
56
boundary_conditions = boundary_conditions)
57
58
###############################################################################
59
# ODE solvers, callbacks etc.
60
61
# Create ODE problem with time span from 0.0 to 0.1
62
ode = semidiscretize(semi, (0.0, 0.1))
63
64
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
65
# and resets the timers
66
summary_callback = SummaryCallback()
67
68
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
69
analysis_interval = 100
70
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
71
72
alive_callback = AliveCallback(analysis_interval = analysis_interval)
73
74
# The SaveRestartCallback allows to save a file from which a Trixi.jl simulation can be restarted
75
save_restart = SaveRestartCallback(interval = 100,
76
save_final_restart = true)
77
78
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
79
save_solution = SaveSolutionCallback(interval = 100,
80
solution_variables = cons2prim)
81
82
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
83
stepsize_callback = StepsizeCallback(cfl = 1.2)
84
85
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
86
callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback, save_restart,
87
save_solution, stepsize_callback)
88
89
###############################################################################
90
# run the simulation
91
92
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
93
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
94
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
95
ode_default_options()..., callback = callbacks);
96
97