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

math 4997 1
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 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.

slide-2
SLIDE 2

Reminder Heat equation Serial implementation Summary References

slide-3
SLIDE 3

Reminder

slide-4
SLIDE 4

Lecture 12

What you should know from last lecture

◮ What is HPX ◮ Asynchronous programming using HPX ◮ Shared memory parallelism using HPX

slide-5
SLIDE 5

Heat equation

slide-6
SLIDE 6

Heat equation

Statement of the heat equation

∂u ∂t = α

  • ∂2u

∂x2 + ∂2u ∂y2 + ∂2u ∂z2

  • where alpha is the difgusivity of the material.

Compact form

˙ u = α∇u The heat equation computes the fmow of heat in a homogeneous and isotropic medium. More details [1].

slide-7
SLIDE 7

Easiest case

1D heat equation

∂u ∂t = α ∂2u ∂x2,

0 ≤ x ≤ L, t > 0

Boundary conditions

The solution of the heat equation requires boundary conditions ◮ u(0, t) = u0 ◮ u(L, t) = uL ◮ u(x, 0) = f0(x)

slide-8
SLIDE 8

Discretization

L x1 x2 x3 x4 x5 x6 h

Discrete mesh

xi = (i − 1)h, i = 1, 2, . . . , N where N is the total number of nodes and h is given by h = L/

N − 1.

slide-9
SLIDE 9

Finite difgerence method

Approximation of the fjrst derivative

∂u ∂x ≈ ui+1−ui 2h

Approximation of the second derivative

∂u ∂x2 ≈ ui−1−2ui+ui+1 h2

Note that a second-order central difgerence scheme is

  • applied. More details [3, 2].
slide-10
SLIDE 10

Discretization in space and time

x1 x2 x3 x4 x5 x6 x t ti−1 ti ti+1 L

slide-11
SLIDE 11

Serial implementation

slide-12
SLIDE 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;

slide-13
SLIDE 13

Discretization scheme

x1 x2 x3 x4 x5 x6 t1 t0 L

Approximation of the heat equation

static double heat(double left, double middle, double right) { return middle + (alpha*dt/(h*h)) * (left - 2*middle + right); }

slide-14
SLIDE 14

Swapping the data

x1 x2 x3 x4 x5 x6 x7 x8 x9 U[0] U[1] U[0] t=0 t=1 t=2

Swapping function

space do_work(std::size_t nx, std::size_t nt) { // U[t][i] is the state of position i at time t. std::vector<space> U(2); for (space& s : U) s.resize(nx); // Return the solution at time-step 'nt'. return U[nt % 2]; }

slide-15
SLIDE 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]); }

slide-16
SLIDE 16

Initial conditions

u(x, 0) = f(i, 0), with f(0, i) = i for i = 1, 2, . . . , N

2 1 1 2 2.0 1.5 1.0 0.5 0.0 0.5 1.0 1.5 2.0 20 40 60 80

u

slide-17
SLIDE 17

Solution

2 1 1 2 2.0 1.5 1.0 0.5 0.0 0.5 1.0 1.5 2.0 20 30 40 50 60 70 80

u

Parameters

◮ heat transfer coeffjcient k = 0.5 ◮ time step size dt = 1.; ◮ grid spacing h = 1.; ◮ time steps nt = 45;

slide-18
SLIDE 18

Summary

slide-19
SLIDE 19

Summary

After this lecture, you should know

◮ One-dimensional heat equation ◮ Serial implementation

slide-20
SLIDE 20

References

slide-21
SLIDE 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.