Path: blob/main/examples/p4est_2d_dgsem/elixir_advection_coupled.jl
5586 views
using OrdinaryDiffEqSSPRK, OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# Simplest coupled setup consisting of two non-trivial mesh views.56advection_velocity = (0.2, -0.7)7equations = LinearScalarAdvectionEquation2D(advection_velocity)89# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux10solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)1112# Define the physical domain for the parent mesh.13coordinates_min = (-1.0, -1.0) # minimum coordinates (min(x), min(y))14coordinates_max = (1.0, 1.0) # maximum coordinates (max(x), max(y))1516trees_per_dimension = (8, 8)1718# Create parent P4estMesh with 8 x 8 trees and 8 x 8 elements19# Since we couple through the boundaries, the periodicity does not matter here,20# but it is to trigger parts of the code for the test.21parent_mesh = P4estMesh(trees_per_dimension, polydeg = 3,22coordinates_min = coordinates_min,23coordinates_max = coordinates_max,24initial_refinement_level = 0,25periodicity = false)2627# Define the mesh views consisting of a small square in the center28# and a square ring around it.29cell_ids1 = vcat((1:18), (23:26), (31:34), (39:42), (47:64))30mesh1 = P4estMeshView(parent_mesh, cell_ids1)31cell_ids2 = vcat((19:22), (27:30), (35:38), (43:46))32mesh2 = P4estMeshView(parent_mesh, cell_ids2)3334# Define a trivial coupling function.35coupling_function = (x, u, equations_other, equations_own) -> u3637# The mesh is coupled across the physical boundaries, which makes this setup38# effectively double periodic.39boundary_conditions = (; x_neg = BoundaryConditionCoupledP4est(coupling_function),40y_neg = BoundaryConditionCoupledP4est(coupling_function),41y_pos = BoundaryConditionCoupledP4est(coupling_function),42x_pos = BoundaryConditionCoupledP4est(coupling_function))4344semi1 = SemidiscretizationHyperbolic(mesh1, equations, initial_condition_convergence_test,45solver,46boundary_conditions = boundary_conditions)47semi2 = SemidiscretizationHyperbolic(mesh2, equations, initial_condition_convergence_test,48solver,49boundary_conditions = boundary_conditions)5051# Create a semidiscretization that bundles semi1 and semi252semi = SemidiscretizationCoupledP4est(semi1, semi2)5354###############################################################################55# ODE solvers, callbacks etc.5657# Create ODE problem with time span from 0.0 to 2.058ode = semidiscretize(semi, (0.0, 2.0))5960# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup61# and resets the timers62summary_callback = SummaryCallback()6364# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results65# We require this definition for the test, even though we don't use it in the CallbackSet.66analysis_callback1 = AnalysisCallback(semi1, interval = 100)67analysis_callback2 = AnalysisCallback(semi2, interval = 100)68analysis_callback = AnalysisCallbackCoupledP4est(semi, analysis_callback1,69analysis_callback2)7071# The SaveSolutionCallback allows to save the solution to a file in regular intervals72save_solution = SaveSolutionCallback(interval = 100,73solution_variables = cons2prim)7475# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step76stepsize_callback = StepsizeCallback(cfl = 1.6)7778# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver79callbacks = CallbackSet(summary_callback, save_solution, stepsize_callback)8081###############################################################################82# run the simulation8384# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks85sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);86dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback87ode_default_options()..., callback = callbacks);888990