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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6892 - (hide 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 jfenwick 3981 ##############################################################################
2 gross 2574 #
3 jfenwick 6651 # Copyright (c) 2003-2018 by The University of Queensland
4 jfenwick 3981 # http://www.uq.edu.au
5 gross 2574 #
6     # Primary Business: Queensland, Australia
7 jfenwick 6112 # Licensed under the Apache License, version 2.0
8     # http://www.apache.org/licenses/LICENSE-2.0
9 gross 2574 #
10 jfenwick 3981 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
11 jfenwick 4657 # Development 2012-2013 by School of Earth Sciences
12     # Development from 2014 by Centre for Geoscience Computing (GeoComp)
13 jfenwick 3981 #
14     ##############################################################################
15 sshaw 5707 from __future__ import print_function, division
16 gross 2574
17 jfenwick 6651 __copyright__="""Copyright (c) 2003-2018 by The University of Queensland
18 jfenwick 3981 http://www.uq.edu.au
19 gross 2574 Primary Business: Queensland, Australia"""
20 jfenwick 6112 __license__="""Licensed under the Apache License, version 2.0
21     http://www.apache.org/licenses/LICENSE-2.0"""
22 gross 2574 __url__="https://launchpad.net/escript-finley"
23    
24     import matplotlib
25 sshaw 5375 matplotlib.use('agg') #For interactive use, you can comment out this line
26 jfenwick 2600 #It's just here to make testing easier
27    
28 caltinay 4087 import numpy
29 aellery 6798 import pylab
30 aellery 6892 try:
31     import scipy.interpolate
32     HAVE_SCIPY=True
33     except:
34     HAVE_SCIPY=False
35 gross 2574
36 caltinay 4087 from esys.escript import *
37     from esys.escript.linearPDEs import Poisson
38     from esys.finley import Rectangle
39    
40 jfenwick 2578 #Testing whether we have a late enough version of matplotlib
41 aellery 6892 if HAVE_SCIPY:
42     try:
43     matplotlib.mlab.griddata
44 jfenwick 5355
45 aellery 6892 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 gross 2574
69 aellery 6892 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