Path: blob/main/examples/t8code_2d_dgsem/elixir_advection_unstructured_flag.jl
2055 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# Semidiscretization of the linear advection equation.56advection_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 flux.15solver = 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]^n.29mesh_file = Trixi.download("https://gist.githubusercontent.com/efaulhaber/63ff2ea224409e55ee8423b3a33e316a/raw/7db58af7446d1479753ae718930741c47a3b79b7/square_unstructured_2.inp",30joinpath(@__DIR__, "square_unstructured_2.inp"))3132mesh = T8codeMesh(mesh_file, 2;33mapping = mapping_flag, polydeg = 3,34initial_refinement_level = 2)3536# A semidiscretization collects data structures and functions for the spatial discretization.37semi = 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.2.44tspan = (0.0, 0.2)45ode = semidiscretize(semi, tspan)4647# At the beginning of the main loop, the SummaryCallback prints a summary of48# the simulation setup and resets the timers.49summary_callback = SummaryCallback()5051# The AnalysisCallback allows to analyse the solution in regular intervals and52# prints the results.53analysis_callback = AnalysisCallback(semi, interval = 100)5455# The SaveSolutionCallback allows to save the solution to a file in regular intervals56save_solution = SaveSolutionCallback(interval = 100,57solution_variables = cons2prim)5859# The StepsizeCallback handles the re-calculation of the maximum Δt after each60# time step.61stepsize_callback = StepsizeCallback(cfl = 1.4)6263# Create a CallbackSet to collect all callbacks such that they can be passed to64# the ODE solver.65callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,66stepsize_callback)6768###############################################################################69# Run the simulation.7071# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks.72sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);73dt = 1.0, # Solve needs some value here but it will be overwritten by the stepsize_callback.74ode_default_options()..., callback = callbacks);757677