Web-Books
in the Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Page - 174 -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

Page - 174 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Image of the Page - 174 -

Image of the Page - 174 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Text of the Page - 174 -

174 5 SolvingPartialDifferentialEquations Fig.5.4 Time steps used by theRunge-Kutta-Fehlbergmethod: error tolerance 10 3 (left) and 10 6 (right) # Check how many time steps are required by adaptive vs # fixed-step methods if hasattr(solver, ’t_all’): print ’# time steps:’, len(solver.t_all) else: print ’# time steps:’, len(t) The very nice thing is that we can now easily experimentwithmany different integrationmethods. Tryingout some simple onesfirst, likeRK2 andRK4, quickly reveals that the time step limitation of the Forward Euler scheme also applies to thesemore sophisticatedRunge-Kuttamethods, but their accuracy is better. How- ever, theOdespypackageoffersalsoadaptivemethods.Wecanthenspecifyamuch larger time step in time_points, and the solver will figure out the appropriate step.AboveweindicatedhowtousetheadaptiveRunge-Kutta-Fehlberg4–5solver. While the t corresponding to theForwardEulermethod requiresover8000steps for a simulation,westarted theRKFehlbergmethodwith 100 times this timestep and in the end it required just slightlymore than 2500 steps, using the default tol- erance parameters. Lowering the tolerance did not save any significant amount of computationalwork. Figure 5.4 shows a comparison of the length of all the time stepsfortwovaluesofthetolerance.Weseethattheinfluenceofthetoleranceismi- nor in this computationalexample, so it seems that theblow-updue to instability is whatgoverns the timestep size. Thenice featureof this adaptivemethod is thatwe can just specifywhenwewant thesolution tobecomputed,and themethodfigures outon its ownwhat timestep thathas tobeusedbecauseof stability restrictions. We have seen how easy it is to apply sophisticatedmethods for ODEs to this PDEexample.Weshall take theuseofOdespyonestep further in thenext section. 5.1.7 ImplicitMethods Amajor problemwith the stability criterion (5.15) is that the time step becomes very small if x is small. For example, halving x requires four times asmany time steps and eight times thework. Now, withN D 40, which is a reasonable resolution for the test problemabove, the computations are very fast. What takes
back to the  book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python
Title
Programming for Computations – Python
Subtitle
A Gentle Introduction to Numerical Simulations with Python
Authors
Svein Linge
Hans Petter Langtangen
Publisher
Springer Open
Date
2016
Language
English
License
CC BY-NC 4.0
ISBN
978-3-319-32428-9
Size
17.8 x 25.4 cm
Pages
248
Keywords
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Category
Informatik
Web-Books
Library
Privacy
Imprint
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python