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

Page - 303 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Image of the Page - 303 -

Image of the Page - 303 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Text of the Page - 303 -

9.3 Exercises 303 K[N,N] = (beta/dx**2)*(-2) return K import odespy solver = odespy.BackwardEuler(rhs, f_is_linear=True, jac=K) solver = odespy.ThetaRule(rhs, f_is_linear=True, jac=K, theta=0.5) solver.set_initial_condition(U_0) T = 1*60*60 N_t = int(round(T/dt)) time_points = linspace(0, T, N_t+1) u, t = solver.solve(time_points) The filerod_BE.pyhas all the details and shows a movie of the solution. We can run it withanyΔt wewant, its size just impacts theaccuracyof thefirst steps. Odespysolversapplydense matrices! Lookingat the entriesof theK matrix, we realize that there are at maximum three entries different from zero in each row. Therefore, most of the entries are zeroes. The Odespy solvers expect dense square matrices as input, here with (N + 1)× (N + 1) elements. When solving the linear systems, a lot of storage and work are spent on the zero entries in the matrix. It would be much more efficient to store the matrix as a tridiagonal matrix and apply a specializedGaussianeliminationsolver for tridiagonalsystems.Actually, this reduces thework fromtheorderN3 to the orderN. In one-dimensionaldiffusion problems, the savings of using a tridiagonal matrix are modest in practice, since the matrices are very small anyway. In two-andthree-dimensionalPDEproblems,however,onecannotafforddense squarematrices.Rather,onemust resort tomoreefficient storageformatsand algorithmstailoredtosuchformats,but this isbeyondthescopeof thepresent text. 9.3 Exercises Exercise9.1:SimulateaDiffusion EquationbyHand Consider the problem given by (9.9), (9.10) and (9.14). Set N = 2 and compute u0i , u 1 i and u 2 i by hand for i = 0,1,2. Use these values to construct a test function for checking that the implementation is correct. Copy useful functions from test_diffusion_pde_exact_linear.py and make a new test function test_diffusion_hand_calculation. Filename:test_rod_hand_calculations.py. Exercise9.2:ComputeTemperatureVariations in theGround Thesurface temperatureat thegroundshowsdailyandseasonal oscillations.When the temperature rises at the surface, heat is propagated into the ground, and the coefficientβ in the diffusion equation determines how fast this propagation is. It takessometimebeforethe temperaturerisesdownin theground.At thesurface, the
back to the  book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Title
Programming for Computations – Python
Subtitle
A Gentle Introduction to Numerical Simulations with Python 3.6
Volume
Second Edition
Authors
Svein Linge
Hans Petter Langtangen
Publisher
Springer Open
Date
2020
Language
English
License
CC BY 4.0
ISBN
978-3-319-32428-9
Size
17.8 x 25.4 cm
Pages
356
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