The burger - kdv equation


In [1]:
from IPython.display import HTML, display, Image

import numpy as np
import pylab as pl
import triflow as trf
from scipy.signal import gaussian

%matplotlib inline


This notebook is an attempt to reproduce the Dedalus Project tutorial. The equation to solve is

$$\partial_{t}\,U + U \partial_{x}\,U = a\partial_{xx}\,U + b\partial_{xxx}\,U$$

In [2]:
model = trf.Model("-U * dxU + a * dxxU + b * dxxxU", "U", ["a", "b"])

We discretize our spatial domain. retstep=True ask to return the spatial step.


In [3]:
x, dx = np.linspace(-2, 6, 5000, retstep=True, endpoint=False)

We initialize with the same initial condition as in the Dedalus tutorial


In [4]:
n = 20
U = np.log(1 + np.cosh(n)**2/np.cosh(n*x)**2) / (2*n)

fields = model.fields_template(x=x, U=U)

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


We precise our parameters. The default scheme provide an automatic time_stepping.


In [5]:
parameters = dict(a=2E-4, b=1E-4, periodic=False)

We initialize the simulation.


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


Out[6]:

We iterate on the simulation until the end.


In [7]:
simulation.run()



Out[7]:
(10.0, <xarray.Field>
 Dimensions:  (x: 5000)
 Coordinates:
   * x        (x) float64 -2.0 -1.998 -1.997 -1.995 -1.994 -1.992 -1.99 ...
 Data variables:
     U        (x) float64 9.069e-08 9.063e-08 9.057e-08 9.046e-08 9.037e-08 ...)

In [8]:
display(HTML("<h3>Triflow result</h3>"))
pl.figure(figsize=(12, 8))
container.data.U.plot(vmin=-.65, vmax=.95, cmap="RdBu_r")
pl.show()
display(HTML("<h3>Dedalus result</h3>"))
display(Image('dedalus-kdv.png'))


Triflow result

Dedalus result


In [ ]:


In [ ]: