Path: blob/main/examples/structured_2d_dgsem/elixir_advection_rotated.jl
2055 views
# This elixir transforms the setup of elixir_advection_basic to a rotated square.1# The nodal values of the initial condition and the exact solution are the same as2# in elixir_advection_basic.3# However, on this rotated mesh, the metric terms are non-trivial.4# The same errors as with elixir_advection_basic are expected (except for rounding errors).56using OrdinaryDiffEqLowStorageRK7using Trixi89# Define new structs inside a module to allow re-evaluating the file.10# This module name needs to be unique among all examples, otherwise Julia will throw warnings11# if multiple test cases using the same module name are run in the same session.12module TrixiExtensionAdvectionRotated1314using Trixi1516# initial_condition_convergence_test transformed to the rotated rectangle17struct InitialConditionConvergenceTestRotated18sin_alpha::Float6419cos_alpha::Float6420end2122function InitialConditionConvergenceTestRotated(alpha)23sin_alpha, cos_alpha = sincos(alpha)2425InitialConditionConvergenceTestRotated(sin_alpha, cos_alpha)26end2728function (initial_condition::InitialConditionConvergenceTestRotated)(x, t,29equation::LinearScalarAdvectionEquation2D)30sin_ = initial_condition.sin_alpha31cos_ = initial_condition.cos_alpha3233# Rotate back to unit square3435# Clockwise rotation by α and translation by 136# Multiply with [ cos(α) sin(α);37# -sin(α) cos(α)]38x_rot = SVector(cos_ * x[1] + sin_ * x[2], -sin_ * x[1] + cos_ * x[2])39a = equation.advection_velocity40a_rot = SVector(cos_ * a[1] + sin_ * a[2], -sin_ * a[1] + cos_ * a[2])4142# Store translated coordinate for easy use of exact solution43x_trans = x_rot - a_rot * t4445c = 1.046A = 0.547L = 248f = 1 / L49omega = 2 * pi * f50scalar = c + A * sin(omega * sum(x_trans))5152return SVector(scalar)53end5455end # module TrixiExtensionAdvectionRotated5657import .TrixiExtensionAdvectionRotated5859###############################################################################60# semidiscretization of the linear advection equation6162alpha = pi * 0.163initial_condition = TrixiExtensionAdvectionRotated.InitialConditionConvergenceTestRotated(alpha)64sin_ = initial_condition.sin_alpha65cos_ = initial_condition.cos_alpha66T = [cos_ -sin_; sin_ cos_]6768advection_velocity = Tuple(T * [0.2, -0.7])69equations = LinearScalarAdvectionEquation2D(advection_velocity)7071# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux72solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)7374mapping(xi, eta) = T * SVector(xi, eta)7576cells_per_dimension = (16, 16)7778# Create curved mesh with 16 x 16 elements79mesh = StructuredMesh(cells_per_dimension, mapping)8081# A semidiscretization collects data structures and functions for the spatial discretization82semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)8384###############################################################################85# ODE solvers, callbacks etc.8687# Create ODE problem with time span from 0.0 to 1.088ode = semidiscretize(semi, (0.0, 1.0))8990# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup91# and resets the timers92summary_callback = SummaryCallback()9394# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results95analysis_callback = AnalysisCallback(semi, interval = 100)9697# The SaveSolutionCallback allows to save the solution to a file in regular intervals98save_solution = SaveSolutionCallback(interval = 100,99solution_variables = cons2prim)100101# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step102stepsize_callback = StepsizeCallback(cfl = 1.6)103104# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver105callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,106stepsize_callback)107108###############################################################################109# run the simulation110111# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks112sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);113dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback114ode_default_options()..., callback = callbacks);115116117