Run the model

Use this notebook to demonstrate how to run the diffusion model.

Before starting, make sure you've installed the bmi-live-2017 package in developer mode. Execute this statement at the command line (not in this notebook!):

$ python setup.py develop

Include one import that we'll use later in this notebook:


In [ ]:
import numpy as np

Start by importing the Diffusion class from the bmi-live-2017 package and creating an instance:


In [ ]:
from bmi_live.diffusion import Diffusion
m = Diffusion()

This instance uses default parameter values set up in the class. Let's view them


In [ ]:
print 'Number of columns:', m.nx
print 'Number of rows:', m.ny
print 'Spacing between columns:', m.dx
print 'Spacing between rows:', m.dy
print 'Diffusivity coefficient:', m.alpha

What does the initial temperature array look like?


In [ ]:
print m.temperature

Add a unit impulse to the initial temperature field:


In [ ]:
m.temperature[3, 3] = 100.0

Check that the temperature field has been updated:


In [ ]:
print m.temperature

Now advance the model by a single time step:


In [ ]:
m.advance()

View the new state of the temperature field:


In [ ]:
print m.temperature

There's diffusion!

Advance the model to some distant time:


In [ ]:
distant_time = 10
for _ in range(distant_time):
    m.advance()

View the new state of the temperature field (with help from np.set_printoptions):


In [ ]:
np.set_printoptions(formatter={'float': '{: 6.2f}'.format})
print m.temperature