Skip to content

Commit

Permalink
Update eg_burgers.md
Browse files Browse the repository at this point in the history
  • Loading branch information
vavrines authored Aug 5, 2021
1 parent 7d84574 commit 40ecf66
Showing 1 changed file with 17 additions and 46 deletions.
63 changes: 17 additions & 46 deletions docs/src/eg_burgers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,78 +4,49 @@ Now we could turn to the Burgers equation.
It's a typical hyperbolic conservation law, where discontinuous solution can emerge in a self-evolving system.
Let's consider the same initial configuration as advection-diffusion example.
```julia
using ProgressMeter, OffsetArrays, Plots
import KitBase
using KitBase, Plots

set = KitBase.Setup(
set = Setup(
"scalar", # matter
"advection", # case
"burgers", # case
"1d0f0v", # space
"gks", # flux
"", # collision: for scalar conservation laws there are none
1, # species
2, # interpolation order
1, # interpolation order
"vanleer", # limiter
"period", # boundary
0.5, # cfl
1.0, # simulation time
)

pSpace = KitBase.PSpace1D(0.0, 1.0, 100, 1)
pSpace = PSpace1D(0.0, 1.0, 100, 1)
vSpace = nothing
property = KitBase.Scalar(0, 1e-6)

property = Scalar(0, 1e-4)
w0 = 1.0
prim0 = KitBase.conserve_prim(w0)
ib = KitBase.IB(w0, prim0, prim0, w0, prim0, prim0)
ks = KitBase.SolverSet(set, pSpace, vSpace, property, ib, @__DIR__)
prim0 = conserve_prim(w0, property.a)
ib = IB(w0, prim0, prim0, w0, prim0, prim0)
ks = SolverSet(set, pSpace, vSpace, property, ib)
```

The we allocate the data structure needed.
```julia
ctr = OffsetArray{KitBase.ControlVolume1D}(undef, eachindex(ks.pSpace.x))
ctr, face = init_fvm(ks, ks.ps)
for i in eachindex(ctr)
u = sin(2π * ks.pSpace.x[i])
ctr[i] = KitBase.ControlVolume1D(
ks.pSpace.x[i],
ks.pSpace.dx[i],
u,
KitBase.conserve_prim(u)
)
end

face = Array{KitBase.Interface1D}(undef, ks.pSpace.nx+1)
for i = 1:ks.pSpace.nx+1
face[i] = KitBase.Interface1D(0.0)
ctr[i].w = sin(2π * ks.pSpace.x[i]) # initial condition
ctr[i].prim .= conserve_prim(ctr[i].w)
end
```

The solution algorithm can be processed together with visualization.
```julia
t = 0.0
dt = KitBase.timestep(ks, ctr, t)
nt = ks.set.maxTime÷dt |> Int
nt = ks.set.maxTime ÷ dt |> Int

anim = @animate for iter = 1:nt
KitBase.reconstruct!(ks, ctr)

for i in eachindex(face)
face[i].fw = KitBase.flux_gks(
ctr[i-1].w,
ctr[i].w,
ks.gas.μᵣ,
dt,
0.5 * ctr[i-1].dx,
0.5 * ctr[i].dx,
)
end

for i in 1:ks.pSpace.nx
ctr[i].w += (face[i].fw - face[i+1].fw) / ctr[i].dx
ctr[i].prim .= KitBase.conserve_prim(ctr[i].w)
end
ctr[0].w = ctr[ks.pSpace.nx].w
ctr[ks.pSpace.nx+1].w = ctr[1].w
reconstruct!(ks, ctr)
evolve!(ks, ctr, face, dt)
update!(ks, ctr, face, dt, 0.0)

sol = zeros(ks.pSpace.nx)
for i in 1:ks.pSpace.nx
Expand All @@ -87,4 +58,4 @@ end
gif(anim, "burgers.gif", fps = 45)
```

![](./assets/burgers.gif)
![](./assets/burgers.gif)

0 comments on commit 40ecf66

Please sign in to comment.