math 4997 1
play

Math 4997-1 Lecture 12: One-dimensional heat equation Patrick Diehl - PowerPoint PPT Presentation

Math 4997-1 Lecture 12: One-dimensional heat equation Patrick Diehl https://www.cct.lsu.edu/~pdiehl/teaching/2020/4997/ This work is licensed under a Creative Commons Attribution-NonCommercial- NoDerivatives 4.0 International


  1. Math 4997-1 Lecture 12: One-dimensional heat equation Patrick Diehl https://www.cct.lsu.edu/~pdiehl/teaching/2020/4997/ This work is licensed under a Creative Commons “Attribution-NonCommercial- NoDerivatives 4.0 International” license.

  2. Reminder Heat equation Serial implementation Summary References

  3. Reminder

  4. Lecture 12 What you should know from last lecture ◮ What is HPX ◮ Asynchronous programming using HPX ◮ Shared memory parallelism using HPX

  5. Heat equation

  6. Heat equation Statement of the heat equation homogeneous and isotropic medium. The heat equation computes the fmow of heat in a Compact form where alpha is the difgusivity of the material. More details [1]. � � ∂ x 2 + ∂ 2 u ∂ 2 u ∂ y 2 + ∂ 2 u ∂ u ∂ t = α ∂ z 2 ˙ u = α ∇ u

  7. Easiest case 1D heat equation Boundary conditions The solution of the heat equation requires boundary conditions ∂ t = α ∂ 2 u ∂ u 0 ≤ x ≤ L , t > 0 ∂ x 2 , ◮ u (0 , t ) = u 0 ◮ u ( L , t ) = u L ◮ u ( x , 0) = f 0 ( x )

  8. Discretization L h Discrete mesh where N is the total number of nodes and h is given by x 1 x 2 x 3 x 4 x 5 x 6 0 x i = ( i − 1) h , i = 1 , 2 , . . . , N h = L / N − 1 .

  9. Finite difgerence method Approximation of the fjrst derivative Approximation of the second derivative Note that a second-order central difgerence scheme is applied. More details [3, 2]. ∂ u ∂ x ≈ u i +1 − u i 2 h ∂ x 2 ≈ u i − 1 − 2 u i + u i +1 ∂ u h 2

  10. Discretization in space and time x t t i L t i +1 t i − 1 x 1 x 2 x 3 x 4 x 5 x 6 0

  11. Serial implementation

  12. Time measurement and system information Time measurement std::uint64_t t = hpx::util::high_resolution_clock::now(); // Do work std::uint64_t elapsed = hpx::util::high_resolution_clock::now() - t; Accessing system information std::uint64_t const os_thread_count = hpx::get_os_thread_count(); std::cout << "Computation took " << elapsed << " on " << os_thread_count << " threads" << std::endl;

  13. Discretization scheme L (alpha*dt/(h*h)) * (left - 2*middle + right); return middle + { double right) double middle, static double heat(double left, Approximation of the heat equation } t 1 t 0 x 1 x 2 x 3 x 4 x 5 x 6 0

  14. Swapping the data t=1 return U[nt % 2]; // Return the solution at time-step 'nt'. s.resize(nx); for (space& s : U) std::vector<space> U(2); // U[t][i] is the state of position i at time t. { space do_work(std::size_t nx, std::size_t nt) Swapping function t=2 t=0 U[0] U[1] U[0] } x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9

  15. Do the actual work // Actual time step loop for (std::size_t t = 0; t != nt; ++t) { space const& current = U[t % 2]; space& next = U[(t + 1) % 2]; next[0] = heat(current[nx-1], current[0], current[1]); for (std::size_t i = 1; i != nx-1; ++i) next[i] = heat(current[i-1], current[i], current[i+1]); next[nx-1] = heat(current[nx-2], current[nx-1], current[0]); }

  16. Initial conditions u ( x , 0) = f ( i , 0) , with f (0 , i ) = i for i = 1 , 2 , . . . , N u 2.0 1.5 80 1.0 0.5 60 0.0 40 0.5 1.0 20 1.5 2.0 0 2 1 0 1 2

  17. Solution Parameters u 2.0 80 1.5 70 1.0 60 0.5 50 0.0 0.5 40 1.0 30 1.5 20 2.0 2 1 0 1 2 ◮ heat transfer coeffjcient k = 0.5 ◮ time step size dt = 1.; ◮ grid spacing h = 1.; ◮ time steps nt = 45;

  18. Summary

  19. Summary After this lecture, you should know ◮ One-dimensional heat equation ◮ Serial implementation

  20. References

  21. References I [1] John Rozier Cannon. The one-dimensional heat equation . Number 23. Cambridge University Press, 1984. [2] Randall J LeVeque. Finite difgerence methods for ordinary and partial difgerential equations: steady-state and time-dependent problems , volume 98. Siam, 2007. [3] John C Strikwerda. Finite difgerence schemes and partial difgerential equations , volume 88. Siam, 2004.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend