The burger equation


In [1]:
import pylab as pl
import numpy as np
from scipy.signal import gaussian

import triflow as trf

%matplotlib inline


Burgers' equation is a fundamental partial differential equation occurring in various areas of applied mathematics, such as fluid mechanics, nonlinear acoustics, gas dynamics, traffic flow. It is named for Johannes Martinus Burgers (1895–1981). (Wikipedia)

The viscous Burger equation in 1D reads: $$\partial_{t}U = k \partial_{xx} U - U \partial_{x} U$$

with

  • $U$ the velocity
  • $k$ a diffusion convection

The expected behaviour is a wave moving forward with a growing shock. This shock leads to discontinuity smoothed by the diffusion term.


In [2]:
model = trf.Model("k * dxxU - U * dxU", "U", "k")

We discretize our spatial domain. We want periodic condition, so endpoint=True exclude the final node (which will be redondant with the first node, $x=0$ and $x=100$ are merged)


In [3]:
x = np.linspace(0, 100, 500, endpoint=False)

We initialize with a simple gaussian pulse initial condition.


In [4]:
U = gaussian(x.size, 20) * 2
            
fields = model.fields_template(x=x, U=U)

pl.figure(figsize=(15, 4))
pl.plot(fields.x, fields.U)
pl.xlim(0, fields.x.max())
pl.show()


We precise our parameters. The default scheme provide an automatic time_stepping. We set the periodic flag to True


In [5]:
parameters = dict(k=1E-1, c=20, periodic=True)

We initialize the simulation.


In [6]:
%%opts Curve [show_grid=True, width=800] {-framewise}
t = 0
simulation = trf.Simulation(model, fields, parameters, dt=.1, tmax=5, tol=1E-2)
container = simulation.attach_container()
trf.display_fields(simulation)


Out[6]:

We iterate on the simulation until the end.


In [7]:
results = simulation.run()




In [8]:
container.data.U.plot()


Out[8]:
<matplotlib.collections.QuadMesh at 0x7fcb0b768400>