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

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

Image of the Page - 180 -

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

Text of the Page - 180 -

180 5 SolvingPartialDifferentialEquations b) TheBackwardEuler,ForwardEuler,andCrank-Nicolsonmethodscanbegiven aunified implementation. For a linearODEu0 Dau this formulation isknown as the rule: unC1 un t D .1 /aunC aunC1 : For D 0we recover the ForwardEulermethod, D 1 gives theBackward Euler scheme, and D 1=2 corresponds to theCrank-Nicolsonmethod. The approximation error in the rule is proportional to t, except for D 1=2 where it isproportional to t2. For 1=2 themethod is stable forall t. Apply the rule to theODEsystem for a one-dimensional diffusion equation. Identify the linear systemtobesolved. c) Implement the rulewithaidof theOdespypackage.Therelevantobjectname isThetaRule: solver = odespy.ThetaRule(rhs, f_is_linear=True, jac=K, theta=0.5) d) Consider thephysicalapplicationfromSect.5.1.4.Runthiscasewith the rule and D1=2 for thefollowingvaluesof t: 0.001,0.01,0.05.Reportwhatyou see. Filename:rod_ThetaRule.py. Remarks Despite the fact that theCrank-Nicolsonmethod, or the rulewith D 1=2, is theoretically more accurate than the Backward Euler and Forward Euler schemes, itmay exhibit non-physical oscillations as in the present example if the solution isvery steep. Theoscillations aredamped in time, anddecreaseswithde- creasing t. Toavoidoscillationsonemusthave t atmaximumtwicethestability limit of the Forward Euler method. This is one reasonwhy the Backward Euler method (or a 2-step backward scheme, seeExercise 5.3) are popular for diffusion equationswithabrupt initial conditions. Exercise5.6:Compute thediffusionofaGaussianpeak Solve the followingdiffusionproblem: @u @t DΛ‡@ 2u @x2 ; x2 . 1;1/; t 2 .0;T (5.34) u.x;0/D 1p 2 exp x 2 2 2 ; x2 Ε’ 1;1 ; (5.35) @ @x u. 1;t/D0 t 2 .0;T ; (5.36) @ @x u.1;t/D0 t 2 .0;T : (5.37) Theinitialconditionis thefamousandwidelyusedGaussianfunctionwithstandard deviation (or β€œwidth”) ,which is here taken to be small, D 0:01, such that the initial condition isapeak.Thispeakwill thendiffuseandbecomelowerandwider. Computeu.x;t/untilubecomesapproximatelyconstantover thedomain. Filename:gaussian_diffusion.py.
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