Reducing Numerical Diffusion in advection model using ModelingToolkit.jl and MethodOfLines.jl

Hello, I have been trying to model the advection equation( du(x,t)/dt + du(x,t)/dx = 0) using ModelingToolkit.jl and MethodOfLines.jl.


import OrdinaryDiffEq, ModelingToolkit, MethodOfLines, DomainSets

ModelingToolkit.@parameters t x
ModelingToolkit.@constants a = -1
ModelingToolkit.@variables u(..)

Dt = ModelingToolkit.Differential(t)
Dx = ModelingToolkit.Differential(x)


eq = Dt(u(t, x)) ~ a*Dx(u(t, x))


bcs = [u(0, x) ~ 0
    u(t, 0) ~ 10*(t>=0.2)*(t<=0.4)
    ]
    
domains = [t ∈ DomainSets.Interval(0.0, 1.0)
    x ∈ DomainSets.Interval(0.0, 1.0)]

parameters, variables)
ModelingToolkit.@named pdysys = ModelingToolkit.PDESystem(eq, bcs, domains, [t, x], [u(t, x)])

dx = 0.01

order = 2

discretization = MethodOfLines.MOLFiniteDifference([x => dx], t, approx_order = order)

prob = MethodOfLines.discretize(pdysys, discretization)

sol = OrdinaryDiffEq.solve(prob, OrdinaryDiffEq.Tsit5(), saveat=0.05)

discrete_x = sol[x]
discrete_t = sol[t]
sol_u = sol[u(t, x)]

import Plots
anim = Plots.@animate for k in eachindex(discrete_t)
    Plots.plot(discrete_x, sol_u[k, :], ylims=(0,10), label="t= $(discrete_t[k])")
end
Plots.gif(anim,"advection.gif", fps = 8)

I have been tryding different input signals and notices that for a rectangular wave there is a lot of numerical dissipation.
advection_tsit5_kink

I have tryed increasing the approximate order of the discretization, different solvers, such as DP8() and Vern9() and reducing the spatial step. Only using a smaller step removed the loss in amplitude but the shape was still rounded. Also tryed using the WENOScheme() but could not manage to implement it.

Any suggestions on how to reduce the dissipation and preserve the wave shape?

That wouldn’t do anything. Did you try decreasing the time stepping abstol and reltol?

This is very classical. A FVM scheme is well suited for tjid with SSPRK intzgrator

You may have a look at Trixi.jl which is devoted to hyperbolic systems and uses some sophisticated discretization approaches.
They also have an intro example for the advection equation: 3 Introduction to DG methods · Trixi.jl

2 Likes

Also tryed changing those to higher values but it did not help

I am doing this for a university project and am somewhat required to do it using ModelingToolkit.jl and MethodOfLines.jl. From a short look at Trixi.jl it does not seem to combine with the two.

How can that be done using the mentioned packages?

You might want to read Approximate Riemann Solvers :slightly_smiling_face: