1 |
gross |
2574 |
|
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 |
jfenwick |
2600 |
matplotlib.use('agg') #For interactive use, you can comment out this line |
29 |
|
|
#It's just here to make testing easier |
30 |
|
|
|
31 |
gross |
2574 |
import pylab |
32 |
|
|
|
33 |
jfenwick |
2578 |
#Testing whether we have a late enough version of matplotlib |
34 |
|
|
try: |
35 |
|
|
matplotlib.mlab.griddata |
36 |
|
|
# generate domain: |
37 |
|
|
mydomain = Rectangle(l0=1.,l1=1.,n0=40, n1=20) |
38 |
|
|
# define characteristic function of Gamma^D |
39 |
|
|
x = mydomain.getX() |
40 |
|
|
gammaD = whereZero(x[0])+whereZero(x[1]) |
41 |
|
|
# define PDE and get its solution u |
42 |
|
|
mypde = Poisson(domain=mydomain) |
43 |
|
|
mypde.setValue(f=1,q=gammaD) |
44 |
|
|
u = mypde.getSolution() |
45 |
|
|
|
46 |
|
|
# interpolate u to a matplotlib grid: |
47 |
|
|
x_grid = numpy.linspace(0.,1.,50) |
48 |
|
|
y_grid = numpy.linspace(0.,1.,50) |
49 |
|
|
x=mydomain.getX()[0].toListOfTuples() |
50 |
|
|
y=mydomain.getX()[1].toListOfTuples() |
51 |
|
|
z=interpolate(u,mydomain.getX().getFunctionSpace()).toListOfTuples() |
52 |
|
|
z_grid = matplotlib.mlab.griddata(x,y,z,xi=x_grid,yi=y_grid ) |
53 |
|
|
# interpolate u to a rectangular grid: |
54 |
|
|
matplotlib.pyplot.contourf(x_grid, y_grid, z_grid, 5) |
55 |
|
|
matplotlib.pyplot.savefig("u.png") |
56 |
|
|
# uncommend this line if you want to interact with a plot window |
57 |
jfenwick |
2600 |
#matplotlib.pyplot.show() |
58 |
gross |
2574 |
|
59 |
jfenwick |
2578 |
except AttributeError: |
60 |
|
|
print "Your version of matplotlib does not provide the griddata method.\nSkipping example.\n" |