First we need to create a rectangular grid. We use the following statements:
x_grid is an array defining the x coordinates of the grids while
y_grid defines the y coordinates of the grid. In this case we use points over the interval
in both directions.
Now the values created by esys.escript need to be interpolated to this grid. We will use the matplotlib
mlab.griddata function to do this. We can easily extract spatial coordinates as a list by
In principle we can apply the same toListOfTuples method to extract the values from the
PDE solution u. However, we have to make sure that the Data object we extract the values from
uses the same FunctionSpace as we have us when extracting x and y. We apply the
interpolation to u before extraction to achieve this:
The values in z are now the values at the points with the coordinates given by x and y. These
values are now interpolated to the grid defined by x_grid and y_grid by using
z_grid gives now the values of the PDE solution u at the grid. The values can be plotted now
using the contourf:
Here we use contours. The last statement writes the plot to the file u.png in the PNG format. Alternatively, one can use
which gives an interactive browser window.
Now we can write the script to solve our Poisson problem
The entire code is available as poissonmatplotlib.py in the example directory.
You can run the script using the escript environment
escript poisson_matplotlib.pyThis will create the u.png, see Figure Figure 1.3. For details on the usage of the matplotlib module we refer to the documentation [12].
As pointed out, matplotlib is restricted to the two-dimensional case and
should be used for small problems only. It can not be used under MPI as the toListOfTuples method is
not safe under MPI .
esys@esscc.uq.edu.au