Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/structured_2d_dgsem/elixir_advection_parallelogram.jl
2055 views
1
# This elixir transforms the setup of elixir_advection_basic to a parallelogram.
2
# The nodal values of the initial condition and the exact solution are the same as
3
# in elixir_advection_basic.
4
# However, on this non-rectangular mesh, the metric terms are non-trivial.
5
# The same errors as with elixir_advection_basic are expected.
6
7
using OrdinaryDiffEqLowStorageRK
8
using Trixi
9
10
# initial_condition_convergence_test transformed to the parallelogram
11
function initial_condition_parallelogram(x, t, equation::LinearScalarAdvectionEquation2D)
12
# Transform back to unit square
13
x_transformed = SVector(x[1] - x[2], x[2])
14
a = equation.advection_velocity
15
a_transformed = SVector(a[1] - a[2], a[2])
16
17
# Store translated coordinate for easy use of exact solution
18
x_translated = x_transformed - a_transformed * t
19
20
c = 1.0
21
A = 0.5
22
L = 2
23
f = 1 / L
24
omega = 2 * pi * f
25
scalar = c + A * sin(omega * sum(x_translated))
26
return SVector(scalar)
27
end
28
29
###############################################################################
30
# semidiscretization of the linear advection equation
31
32
# Transformed advection_velocity = (0.2, -0.7) by transformation mapping
33
advection_velocity = (-0.5, -0.7)
34
equations = LinearScalarAdvectionEquation2D(advection_velocity)
35
36
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
37
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
38
39
# Define faces for a parallelogram that looks like this
40
#
41
# (0,1) __________ (2, 1)
42
# ⟋ ⟋
43
# ⟋ ⟋
44
# ⟋ ⟋
45
# (-2,-1) ‾‾‾‾‾‾‾‾‾‾ (0,-1)
46
mapping(xi, eta) = SVector(xi + eta, eta)
47
48
cells_per_dimension = (16, 16)
49
50
# Create curved mesh with 16 x 16 elements, periodic in both dimensions
51
mesh = StructuredMesh(cells_per_dimension, mapping; periodicity = (true, true))
52
53
# A semidiscretization collects data structures and functions for the spatial discretization
54
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_parallelogram,
55
solver)
56
57
###############################################################################
58
# ODE solvers, callbacks etc.
59
60
# Create ODE problem with time span from 0.0 to 1.0
61
ode = semidiscretize(semi, (0.0, 1.0))
62
63
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
64
# and resets the timers
65
summary_callback = SummaryCallback()
66
67
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
68
analysis_callback = AnalysisCallback(semi, interval = 100)
69
70
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
71
save_solution = SaveSolutionCallback(interval = 100,
72
solution_variables = cons2prim)
73
74
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
75
stepsize_callback = StepsizeCallback(cfl = 1.6)
76
77
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
78
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,
79
stepsize_callback)
80
81
###############################################################################
82
# run the simulation
83
84
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
85
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
86
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
87
ode_default_options()..., callback = callbacks);
88
89