Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shallow water equation #112

Closed
xtalax opened this issue Jun 10, 2022 · 2 comments
Closed

Fix shallow water equation #112

xtalax opened this issue Jun 10, 2022 · 2 comments

Comments

@xtalax
Copy link
Member

xtalax commented Jun 10, 2022

Instability found in following solution, what could be causing this?

using ModelingToolkit, MethodOfLines, DomainSets, OrdinaryDiffEq
using Plots
using IfElse

# Define the system of equations
@parameters t x
@variables u(..) η(..)
#hu(..)

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

tmin = 0.0;
tmax = 6000.;

xmin = 0.0;
xmax = 200.;

dx = 2.0;

slope = 0.001;
n= 0.03;
order= 2;


elevation(x) =  (xmax - x) * slope;
h(t,x) = η(t,x) - elevation(x);


source(t) = ifelse(t < 3600, 1/60/1000, 0.0)
@register_symbolic source(t)
g = 9.81;

exp = -4/3

eqs = [
    Dt(η(t,x))  ~ source(t) - u(t,x) * Dx(η(t,x)) + u(t,x) * (-slope) - h(t,x) * Dx(u(t,x)) ,
    Dt(u(t,x))  ~ - g * Dx(η(t,x))  - u(t,x) * Dx(u(t,x))  - g * u(t,x)^2 * n^2 * IfElse.ifelse(h(t,x) > 1e-5, h(t,x)^exp, (1e-5)^exp)
]

domain = [x  Interval(xmin,xmax),
        t  Interval(tmin,tmax)]


bcs = [
    η(tmin,x)     ~ elevation(x)+1e-5,
    u(tmin,x)     ~ 0.0,
    η(t,xmin)     ~ elevation(xmin),
    u(t, xmin)    ~ 0.0,
]

@named pdesys = PDESystem(eqs, bcs, domain, [t, x], [u(t,x),  η(t,x)])
discretization = MOLFiniteDifference([x => dx], t, jac = true, sparse = true) #
grid = get_discrete(pdesys, discretization)

prob = ModelingToolkit.discretize(pdesys, discretization)
@time sol = solve(prob, Tsit5())

anim = @animate for (i, T) in enumerate(sol.t)
    plot(map(d->sol[d][i], grid[u(t,x)]), label="u", title = "t = $T")
    plot!(map(d->sol[d][i], grid[η(t,x)]), label="η")
end
gif(anim, "plots/shallow_water.gif", fps = 10)

Plot:
shallow_water

@YichengDWu
Copy link
Contributor

Looks oscillatory to me. WENO methods may fix this.

@xtalax xtalax closed this as completed Dec 1, 2022
@xtalax
Copy link
Member Author

xtalax commented Dec 1, 2022

Fixed with WENO and implicit methods

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants