/[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 2574 - (show annotations)
Mon Aug 3 09:09:20 2009 UTC (11 years, 1 month ago) by gross
File MIME type: text/x-python
File size: 1737 byte(s)
matplotlib description added to usersguide
1
2 ########################################################
3 #
4 # Copyright (c) 2003-2009 by University of Queensland
5 # Earth Systems Science Computational Center (ESSCC)
6 # http://www.uq.edu.au/esscc
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 ########################################################
13
14 __copyright__="""Copyright (c) 2003-2009 by University of Queensland
15 Earth Systems Science Computational Center (ESSCC)
16 http://www.uq.edu.au/esscc
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __url__="https://launchpad.net/escript-finley"
21
22 from esys.escript import *
23 from esys.escript.linearPDEs import Poisson
24 from esys.finley import Rectangle
25 import numpy
26 import matplotlib
27
28 import pylab
29 # generate domain:
30 mydomain = Rectangle(l0=1.,l1=1.,n0=40, n1=20)
31 # define characteristic function of Gamma^D
32 x = mydomain.getX()
33 gammaD = whereZero(x[0])+whereZero(x[1])
34 # define PDE and get its solution u
35 mypde = Poisson(domain=mydomain)
36 mypde.setValue(f=1,q=gammaD)
37 u = mypde.getSolution()
38
39 # interpolate u to a matplotlib grid:
40 x_grid = numpy.linspace(0.,1.,50)
41 y_grid = numpy.linspace(0.,1.,50)
42 x=mydomain.getX()[0].toListOfTuples()
43 y=mydomain.getX()[1].toListOfTuples()
44 z=interpolate(u,mydomain.getX().getFunctionSpace()).toListOfTuples()
45 z_grid = matplotlib.mlab.griddata(x,y,z,xi=x_grid,yi=y_grid )
46 # interpolate u to a rectangular grid:
47 matplotlib.pyplot.contourf(x_grid, y_grid, z_grid, 5)
48 matplotlib.pyplot.savefig("u.png")
49 # uncommend this line if you want to interact with a plot window
50 matplotlib.pyplot.show()
51

  ViewVC Help
Powered by ViewVC 1.1.26