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.
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?