Book contents
- Frontmatter
- Contents
- Preface
- 1 Introduction
- 2 Getting started with IPython
- 3 A short Python tutorial
- 4 Numpy
- 5 Two-dimensional graphics
- 6 Three-dimensional graphics
- 7 Ordinary differential equations
- 8 Partial differential equations: a pseudospectral approach
- 9 Case study: multigrid
- Appendix A Installing a Python environment
- Appendix B Fortran77 subroutines for pseudospectral methods
- References
- Index
8 - Partial differential equations: a pseudospectral approach
Published online by Cambridge University Press: 05 August 2014
- Frontmatter
- Contents
- Preface
- 1 Introduction
- 2 Getting started with IPython
- 3 A short Python tutorial
- 4 Numpy
- 5 Two-dimensional graphics
- 6 Three-dimensional graphics
- 7 Ordinary differential equations
- 8 Partial differential equations: a pseudospectral approach
- 9 Case study: multigrid
- Appendix A Installing a Python environment
- Appendix B Fortran77 subroutines for pseudospectral methods
- References
- Index
Summary
In this chapter, we present two rather different topics, which we have linked together. First we shall study some initial value problems and initial-boundary value problems, where the forward-in-time integration is handled by the “method of lines”. We can treat the spatial derivatives by one of two methods:
finite differencing, the standard approach, which is discussed in every textbook, and some aspects of which will be treated in the next chapter,
spectral methods which, for smooth solutions, will give near exponential accuracy.
For simplicity, we shall study only scalar partial differential equations in one spatial dimension, but everything can be generalized to systems of equations in two or more dimensions. We look first at Fourier methods capable of handling problems with periodic spatial dependence. Then in Section 8.6 we suggest a promising approach using Chebyshev transforms for spatial dependencies that are more general. Unfortunately, there is no pre-existing Python black box package to implement this, but there is legacy Fortran77 code which we list in Appendix B.
The second main topic of this chapter is to present the numpy f2py tool in Section 8.7, so that we can re-use the legacy code of Appendix B to construct Python functions to implement the ideas of Section 8.6. If you are interested in reusing legacy code, then you should study the ideas presented in Section 8.7, to find out how to do it, even if you have no interest in Chebyshev transforms.
- Type
- Chapter
- Information
- Python for Scientists , pp. 163 - 183Publisher: Cambridge University PressPrint publication year: 2014