Path: blob/main/examples/structured_2d_dgsem/elixir_advection_meshview.jl
5586 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# Coupled semidiscretization of two linear advection systems using converter functions5# and mesh views for the semidiscretizations. First we define a parent mesh6# for the entire physical domain, then we define the two mesh views on this parent.7#8# In this elixir, we have a square domain that is divided into left and right subdomains.9# On each half of the domain, a completely independent `SemidiscretizationHyperbolic`10# is created for the linear advection equations. The two systems are coupled in the11# x-direction.12# For a high-level overview, see also the figure below:13#14# (-1, 1) ( 1, 1)15# ┌────────────────────┬────────────────────┐16# │ ↑ periodic ↑ │ ↑ periodic ↑ │17# │ │ │18# │ ========= │ ========= │19# │ system #1 │ system #2 │20# │ ========= │ ========= │21# │ │ │22# │<-- coupled │<-- coupled │23# │ coupled -->│ coupled -->│24# │ │ │25# │ ↓ periodic ↓ │ ↓ periodic ↓ │26# └────────────────────┴────────────────────┘27# (-1, -1) ( 1, -1)2829advection_velocity = (0.2, -0.7)30equations = LinearScalarAdvectionEquation2D(advection_velocity)3132# Create DG solver with polynomial degree = 333solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)3435# Domain size of the parent mesh.36coordinates_min = (-1.0, -1.0)37coordinates_max = (1.0, 1.0)3839# Cell dimensions of the parent mesh.40cells_per_dimension = (16, 16)4142# Create parent mesh with 16 x 16 elements43parent_mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max,44periodicity = true)4546# Create the two mesh views, each of which takes half of the parent mesh.47mesh1 = StructuredMeshView(parent_mesh; indices_min = (1, 1), indices_max = (8, 16))48mesh2 = StructuredMeshView(parent_mesh; indices_min = (9, 1), indices_max = (16, 16))4950# The coupling function is simply the identity, as we are dealing with two identical systems.51coupling_function = (x, u, equations_other, equations_own) -> u5253# Define the coupled boundary conditions54# The indices (:end, :i_forward) and (:begin, :i_forward) denote the interface indexing.55# For a system with coupling in x and y see examples/structured_2d_dgsem/elixir_advection_coupled.jl.56boundary_conditions1 = (57# Connect left boundary with right boundary of left mesh58x_neg = BoundaryConditionCoupled(2, (:end, :i_forward), Float64,59coupling_function),60x_pos = BoundaryConditionCoupled(2, (:begin, :i_forward), Float64,61coupling_function),62y_neg = boundary_condition_periodic,63y_pos = boundary_condition_periodic)64boundary_conditions2 = (65# Connect left boundary with right boundary of left mesh66x_neg = BoundaryConditionCoupled(1, (:end, :i_forward), Float64,67coupling_function),68x_pos = BoundaryConditionCoupled(1, (:begin, :i_forward), Float64,69coupling_function),70y_neg = boundary_condition_periodic,71y_pos = boundary_condition_periodic)7273# A semidiscretization collects data structures and functions for the spatial discretization74semi1 = SemidiscretizationHyperbolic(mesh1, equations, initial_condition_convergence_test,75solver; boundary_conditions = boundary_conditions1)76semi2 = SemidiscretizationHyperbolic(mesh2, equations, initial_condition_convergence_test,77solver; boundary_conditions = boundary_conditions2)78semi = SemidiscretizationCoupled(semi1, semi2)7980###############################################################################81# ODE solvers, callbacks etc.8283# Create ODE problem with time span from 0.0 to 1.084ode = semidiscretize(semi, (0.0, 1.0))8586# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup87# and resets the timers88summary_callback = SummaryCallback()8990# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results91analysis_callback1 = AnalysisCallback(semi1, interval = 100)92analysis_callback2 = AnalysisCallback(semi2, interval = 100)93analysis_callback = AnalysisCallbackCoupled(semi, analysis_callback1, analysis_callback2)9495analysis_interval = 10096alive_callback = AliveCallback(analysis_interval = analysis_interval)9798# The SaveSolutionCallback allows to save the solution to a file in regular intervals99save_solution = SaveSolutionCallback(interval = 100,100save_initial_solution = true,101save_final_solution = true,102solution_variables = cons2prim)103104# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step105stepsize_callback = StepsizeCallback(cfl = 1.6)106107# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver108callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,109stepsize_callback)110111###############################################################################112# run the simulation113114# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks115sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);116dt = 5.0e-2, # solve needs some value here but it will be overwritten by the stepsize_callback117ode_default_options()..., callback = callbacks);118119120