/[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 6892 - (show annotations)
Tue Oct 15 04:55:57 2019 UTC (11 months ago) by aellery
File MIME type: text/x-python
File size: 2623 byte(s)
- Updated the jupyter dockerfile
- Fixed the problem that John was having with the examples


1 ##############################################################################
2 #
3 # Copyright (c) 2003-2018 by The University of Queensland
4 # http://www.uq.edu.au
5 #
6 # Primary Business: Queensland, Australia
7 # Licensed under the Apache License, version 2.0
8 # http://www.apache.org/licenses/LICENSE-2.0
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-2018 by The University of Queensland
18 http://www.uq.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Apache License, version 2.0
21 http://www.apache.org/licenses/LICENSE-2.0"""
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 try:
31 import scipy.interpolate
32 HAVE_SCIPY=True
33 except:
34 HAVE_SCIPY=False
35
36 from esys.escript import *
37 from esys.escript.linearPDEs import Poisson
38 from esys.finley import Rectangle
39
40 #Testing whether we have a late enough version of matplotlib
41 if HAVE_SCIPY:
42 try:
43 matplotlib.mlab.griddata
44
45 interp = 'linear'
46 # generate domain:
47 mydomain = Rectangle(l0=1.,l1=1.,n0=40, n1=20)
48 # define characteristic function of Gamma^D
49 x = mydomain.getX()
50 gammaD = whereZero(x[0])+whereZero(x[1])
51 # define PDE and get its solution u
52 mypde = Poisson(domain=mydomain)
53 mypde.setValue(f=1,q=gammaD)
54 u = mypde.getSolution()
55
56 # interpolate u to a matplotlib grid:
57 x_grid = numpy.linspace(0.,1.,50)
58 y_grid = numpy.linspace(0.,1.,50)
59 x=mydomain.getX()[0].toListOfTuples()
60 y=mydomain.getX()[1].toListOfTuples()
61 z=interpolate(u,mydomain.getX().getFunctionSpace()).toListOfTuples()
62 z_grid = scipy.interpolate.griddata((x,y),z,(x_grid[None,:],y_grid[:,None]),interp)
63 # interpolate u to a rectangular grid:
64 matplotlib.pyplot.contourf(x_grid, y_grid, z_grid, 5)
65 matplotlib.pyplot.savefig("u.png")
66 # uncomment this line if you want to interact with a plot window
67 #matplotlib.pyplot.show()
68
69 except AttributeError:
70 print("Your version of matplotlib does not provide the griddata method.\nSkipping example.\n")
71 else:
72 print("This example requires scipy")

  ViewVC Help
Powered by ViewVC 1.1.26