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_meshview.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# Most basic p4est mesh view setup where the entire domain
6
# is part of the single mesh view.
7
8
advection_velocity = (0.2, -0.7)
9
equations = LinearScalarAdvectionEquation2D(advection_velocity)
10
11
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
12
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
13
14
coordinates_min = (-1.0, -1.0) # minimum coordinates (min(x), min(y))
15
coordinates_max = (1.0, 1.0) # maximum coordinates (max(x), max(y))
16
17
trees_per_dimension = (8, 8)
18
19
# Create parent P4estMesh with 8 x 8 trees and 8 x 8 elements
20
parent_mesh = P4estMesh(trees_per_dimension, polydeg = 3,
21
coordinates_min = coordinates_min,
22
coordinates_max = coordinates_max,
23
initial_refinement_level = 0)
24
25
# Define the mesh view covering the whole parent mesh.
26
cell_ids = collect(1:Trixi.ncells(parent_mesh))
27
mesh = P4estMeshView(parent_mesh, cell_ids)
28
29
# A semidiscretization collects data structures and functions for the spatial discretization
30
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,
31
solver)
32
33
###############################################################################
34
# ODE solvers, callbacks etc.
35
36
# Create ODE problem with time span from 0.0 to 1.0
37
ode = semidiscretize(semi, (0.0, 1.0))
38
39
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
40
# and resets the timers
41
summary_callback = SummaryCallback()
42
43
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
44
# We require this definition for the test, even though we don't use it in the CallbackSet.
45
analysis_callback = AnalysisCallback(semi)
46
47
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
48
save_solution = SaveSolutionCallback(interval = 100,
49
solution_variables = cons2prim)
50
51
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
52
stepsize_callback = StepsizeCallback(cfl = 1.6)
53
54
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
55
callbacks = CallbackSet(summary_callback, save_solution,
56
stepsize_callback)
57
58
###############################################################################
59
# run the simulation
60
61
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
62
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
63
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
64
ode_default_options()..., callback = callbacks);
65
66