Path: blob/main/examples/p4est_2d_dgsem/elixir_advection_unstructured_flag.jl
2055 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the linear advection equation56advection_velocity = (0.2, -0.7)7equations = LinearScalarAdvectionEquation2D(advection_velocity)89initial_condition = initial_condition_convergence_test1011boundary_condition = BoundaryConditionDirichlet(initial_condition)12boundary_conditions = Dict(:all => boundary_condition)1314# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux15solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)1617# Deformed rectangle that looks like a waving flag,18# lower and upper faces are sinus curves, left and right are vertical lines.19f1(s) = SVector(-1.0, s - 1.0)20f2(s) = SVector(1.0, s + 1.0)21f3(s) = SVector(s, -1.0 + sin(0.5 * pi * s))22f4(s) = SVector(s, 1.0 + sin(0.5 * pi * s))23faces = (f1, f2, f3, f4)2425Trixi.validate_faces(faces)26mapping_flag = Trixi.transfinite_mapping(faces)2728# Unstructured mesh with 24 cells of the square domain [-1, 1]^n29mesh_file = Trixi.download("https://gist.githubusercontent.com/efaulhaber/63ff2ea224409e55ee8423b3a33e316a/raw/7db58af7446d1479753ae718930741c47a3b79b7/square_unstructured_2.inp",30joinpath(@__DIR__, "square_unstructured_2.inp"))3132mesh = P4estMesh{2}(mesh_file, polydeg = 3,33mapping = mapping_flag,34initial_refinement_level = 2)3536# A semidiscretization collects data structures and functions for the spatial discretization37semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,38boundary_conditions = boundary_conditions)3940###############################################################################41# ODE solvers, callbacks etc.4243# Create ODE problem with time span from 0.0 to 0.244tspan = (0.0, 0.2)45ode = semidiscretize(semi, tspan)4647# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup48# and resets the timers49summary_callback = SummaryCallback()5051# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results52analysis_callback = AnalysisCallback(semi, interval = 100)5354# The SaveSolutionCallback allows to save the solution to a file in regular intervals55save_solution = SaveSolutionCallback(interval = 100,56solution_variables = cons2prim)5758# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step59stepsize_callback = StepsizeCallback(cfl = 1.4)6061# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver62callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,63stepsize_callback)6465###############################################################################66# run the simulation6768# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks69sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);70dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback71ode_default_options()..., callback = callbacks);727374