/[escript]/trunk/doc/examples/usersguide/poisson_matplotlib.py
ViewVC logotype

Contents of /trunk/doc/examples/usersguide/poisson_matplotlib.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5707 - (show annotations)
Mon Jun 29 03:59:06 2015 UTC (3 years, 8 months ago) by sshaw
File MIME type: text/x-python
File size: 2540 byte(s)
adding copyright headers to files without copyright info, moved header to top of file in some cases where it wasn't
1 ##############################################################################
2 #
3 # Copyright (c) 2003-2015 by The University of Queensland
4 # http://www.uq.edu.au
5 #
6 # Primary Business: Queensland, Australia
7 # Licensed under the Open Software License version 3.0
8 # http://www.opensource.org/licenses/osl-3.0.php
9 #
10 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
11 # Development 2012-2013 by School of Earth Sciences
12 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
13 #
14 ##############################################################################
15 from __future__ import print_function, division
16
17 __copyright__="""Copyright (c) 2003-2015 by The University of Queensland
18 http://www.uq.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Open Software License version 3.0
21 http://www.opensource.org/licenses/osl-3.0.php"""
22 __url__="https://launchpad.net/escript-finley"
23
24 import matplotlib
25 matplotlib.use('agg') #For interactive use, you can comment out this line
26 #It's just here to make testing easier
27
28 import numpy
29 import pylab
30
31 from esys.escript import *
32 from esys.escript.linearPDEs import Poisson
33 from esys.finley import Rectangle
34
35 #Testing whether we have a late enough version of matplotlib
36 try:
37 matplotlib.mlab.griddata
38
39 # TO keep the version distributed by openSuse happy
40 interp='nn'
41 try:
42 from mpl_toolkits.natgrid import _natgrid
43 except ImportError:
44 interp='linear'
45 # generate domain:
46 mydomain = Rectangle(l0=1.,l1=1.,n0=40, n1=20)
47 # define characteristic function of Gamma^D
48 x = mydomain.getX()
49 gammaD = whereZero(x[0])+whereZero(x[1])
50 # define PDE and get its solution u
51 mypde = Poisson(domain=mydomain)
52 mypde.setValue(f=1,q=gammaD)
53 u = mypde.getSolution()
54
55 # interpolate u to a matplotlib grid:
56 x_grid = numpy.linspace(0.,1.,50)
57 y_grid = numpy.linspace(0.,1.,50)
58 x=mydomain.getX()[0].toListOfTuples()
59 y=mydomain.getX()[1].toListOfTuples()
60 z=interpolate(u,mydomain.getX().getFunctionSpace()).toListOfTuples()
61 z_grid = matplotlib.mlab.griddata(x,y,z,xi=x_grid,yi=y_grid,interp=interp )
62 # interpolate u to a rectangular grid:
63 matplotlib.pyplot.contourf(x_grid, y_grid, z_grid, 5)
64 matplotlib.pyplot.savefig("u.png")
65 # uncomment this line if you want to interact with a plot window
66 #matplotlib.pyplot.show()
67
68 except AttributeError:
69 print("Your version of matplotlib does not provide the griddata method.\nSkipping example.\n")

  ViewVC Help
Powered by ViewVC 1.1.26