Path: blob/main/docs/literate/src/files/parabolic_terms.jl
5591 views
#src # Parabolic terms (advection-diffusion).12# Experimental support for parabolic diffusion terms is available in Trixi.jl.3# This demo illustrates parabolic terms for the advection-diffusion equation.45using OrdinaryDiffEqLowStorageRK6using Trixi78# ## Splitting a system into hyperbolic and parabolic parts910# For a mixed hyperbolic-parabolic system, we represent the hyperbolic and parabolic11# parts of the system separately. We first define the hyperbolic (advection) part of12# the advection-diffusion equation.1314advection_velocity = (1.5, 1.0)15equations_hyperbolic = LinearScalarAdvectionEquation2D(advection_velocity);1617# Next, we define the parabolic diffusion term. The constructor requires knowledge of18# `equations_hyperbolic` to be passed in because the [`LaplaceDiffusion2D`](@ref) applies19# diffusion to every variable of the hyperbolic system.2021diffusivity = 5.0e-222equations_parabolic = LaplaceDiffusion2D(diffusivity, equations_hyperbolic);2324# ## Boundary conditions2526# As with the equations, we define boundary conditions separately for the hyperbolic and27# parabolic part of the system. For this example, we impose inflow BCs for the hyperbolic28# system (no condition is imposed on the outflow), and we impose Dirichlet boundary conditions29# for the parabolic equations. Both `BoundaryConditionDirichlet` and `BoundaryConditionNeumann`30# are defined for `LaplaceDiffusion2D`.31#32# The hyperbolic and parabolic boundary conditions are assumed to be consistent with each other.3334boundary_condition_zero_dirichlet = BoundaryConditionDirichlet((x, t, equations) -> SVector(0.0))3536boundary_conditions_hyperbolic = (;37x_neg = BoundaryConditionDirichlet((x, t, equations) -> SVector(1 +380.5 *39x[2])),40y_neg = boundary_condition_zero_dirichlet,41y_pos = boundary_condition_do_nothing,42x_pos = boundary_condition_do_nothing)4344boundary_conditions_parabolic = (;45x_neg = BoundaryConditionDirichlet((x, t, equations) -> SVector(1 +460.5 *47x[2])),48y_neg = boundary_condition_zero_dirichlet,49y_pos = boundary_condition_zero_dirichlet,50x_pos = boundary_condition_zero_dirichlet);5152# ## Defining the solver and mesh5354# The process of creating the DG solver and mesh is the same as for a purely55# hyperbolic system of equations.5657solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)58coordinates_min = (-1.0, -1.0) # minimum coordinates (min(x), min(y))59coordinates_max = (1.0, 1.0) # maximum coordinates (max(x), max(y))60mesh = TreeMesh(coordinates_min, coordinates_max,61initial_refinement_level = 4,62periodicity = false, n_cells_max = 30_000) # set maximum capacity of tree data structure6364initial_condition = (x, t, equations) -> SVector(0.0);6566# ## Semidiscretizing and solving6768# To semidiscretize a hyperbolic-parabolic system, we create a [`SemidiscretizationHyperbolicParabolic`](@ref).69# This differs from a [`SemidiscretizationHyperbolic`](@ref) in that we pass in a `Tuple` containing both the70# hyperbolic and parabolic equation, as well as a `Tuple` containing the hyperbolic and parabolic71# boundary conditions.7273semi = SemidiscretizationHyperbolicParabolic(mesh,74(equations_hyperbolic, equations_parabolic),75initial_condition, solver;76boundary_conditions = (boundary_conditions_hyperbolic,77boundary_conditions_parabolic))7879# The rest of the code is identical to the hyperbolic case. We create a system of ODEs through80# `semidiscretize`, defining callbacks, and then passing the system to OrdinaryDiffEq.jl.8182tspan = (0.0, 1.5)83ode = semidiscretize(semi, tspan)84callbacks = CallbackSet(SummaryCallback())85time_int_tol = 1.0e-686sol = solve(ode, RDPK3SpFSAL49(); abstol = time_int_tol, reltol = time_int_tol,87ode_default_options()..., callback = callbacks);8889# We can now visualize the solution, which develops a boundary layer at the outflow boundaries.9091using Plots92plot(sol)9394# ## Package versions9596# These results were obtained using the following versions.9798using InteractiveUtils99versioninfo()100101using Pkg102Pkg.status(["Trixi", "OrdinaryDiffEqLowStorageRK", "Plots"],103mode = PKGMODE_MANIFEST)104105106