Poisson problem with Python

In this example we access lower-level Basilisk functions from Python.

As in the 2D turbulence example, we import matplotlib, numpy and the stream Basilisk module. We also use math functions.

import matplotlib.pyplot as plt
import numpy as np
import stream as bas
from math import *

We initialise the 2562 regular grid.

N = 256

We allocate two new scalar fields a and b.

a = bas.scalar()
b = bas.scalar()

And initialize them with simple arithmetic functions.

a.f = lambda x,y: 0.
b.f = lambda x,y: sin(2.*pi*x)*cos(2.*pi*y)

We then call the multigrid Poisson solver to solve 2a=b


And use matplotlib to display the solution.

x = np.linspace(0, 1, N)
y = np.linspace(0, 1, N)
X,Y = np.meshgrid(x,y)

Note that we could reuse the same module because the streamfunction–vorticity solver (which we don’t use in this example) also exports the interface for the Poisson solver (which we do use in this example).