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_advection_unstructured_flag.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)
8
equations = LinearScalarAdvectionEquation2D(advection_velocity)
9
10
initial_condition = initial_condition_convergence_test
11
12
boundary_condition = BoundaryConditionDirichlet(initial_condition)
13
boundary_conditions = Dict(:all => boundary_condition)
14
15
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
16
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
17
18
# Deformed rectangle that looks like a waving flag,
19
# lower and upper faces are sinus curves, left and right are vertical lines.
20
f1(s) = SVector(-1.0, s - 1.0)
21
f2(s) = SVector(1.0, s + 1.0)
22
f3(s) = SVector(s, -1.0 + sin(0.5 * pi * s))
23
f4(s) = SVector(s, 1.0 + sin(0.5 * pi * s))
24
faces = (f1, f2, f3, f4)
25
26
Trixi.validate_faces(faces)
27
mapping_flag = Trixi.transfinite_mapping(faces)
28
29
# Unstructured mesh with 24 cells of the square domain [-1, 1]^n
30
mesh_file = Trixi.download("https://gist.githubusercontent.com/efaulhaber/63ff2ea224409e55ee8423b3a33e316a/raw/7db58af7446d1479753ae718930741c47a3b79b7/square_unstructured_2.inp",
31
joinpath(@__DIR__, "square_unstructured_2.inp"))
32
33
mesh = P4estMesh{2}(mesh_file, polydeg = 3,
34
mapping = mapping_flag,
35
initial_refinement_level = 2)
36
37
# A semidiscretization collects data structures and functions for the spatial discretization
38
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
39
boundary_conditions = boundary_conditions)
40
41
###############################################################################
42
# ODE solvers, callbacks etc.
43
44
# Create ODE problem with time span from 0.0 to 0.2
45
tspan = (0.0, 0.2)
46
ode = semidiscretize(semi, tspan)
47
48
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
49
# and resets the timers
50
summary_callback = SummaryCallback()
51
52
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
53
analysis_callback = AnalysisCallback(semi, interval = 100)
54
55
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
56
save_solution = SaveSolutionCallback(interval = 100,
57
solution_variables = cons2prim)
58
59
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
60
stepsize_callback = StepsizeCallback(cfl = 1.4)
61
62
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
63
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,
64
stepsize_callback)
65
66
###############################################################################
67
# run the simulation
68
69
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
70
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
71
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
72
ode_default_options()..., callback = callbacks);
73
74