Coupled burger's-like equations


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

%matplotlib inline


We initialize the model with a coupled burger-like system of equations

\begin{align} \partial_{t}U &= k \partial_{xx} U - c U \partial_{x} V \\ \partial_{t}V &= k \partial_{xx} U - c V \partial_{x} U \end{align}

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

We discretize our spatial domain. retstep=True ask to return the spatial step. 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, dx = np.linspace(0, 100, 500, retstep=True, endpoint=False)

We initialize with cosine and sine function for $U$ and $V$.


In [4]:
U = np.cos(x * 2 * np.pi / x.max() * 5) * .5 + 1
V = np.sin(x * 2 * np.pi / x.max() * 5) * .5 + 1
fields = model.fields_template(x=x, U=U, V=V)

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


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

We initialize the simulation


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


Out[6]:

We iterate on the simulation until the end.


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




In [8]:
fig, axs = pl.subplots(1, 2, figsize=(12, 5),
                       sharex="all", sharey="all")
pl.sca(axs[0])
container.data.U.plot()
pl.sca(axs[1])
container.data.V.plot();



In [ ]: