
Illustrated Guide to Writing a Finite Difference Code for Heat Equation
Explore the step-by-step process of writing a Finite Difference code for solving dynamic heat conduction problems, also known as the diffusion equation. Follow along as we find the temperature distribution for a small problem using a structured grid, initial and boundary conditions, and interior equations involving multiple points.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
2023 EESC W3400 Lec 22: Writing a FD code illustrated with 1D+time heat flow equation Computational Earth Science Bill Menke, Instructor Emily Glazer, Teaching Assistant TR 2:40 3:55
Today Finite Difference Method for Solving Dynamic Heat Conduction Problem a.k.a. the Diffusion Equation
Today I will lead you through writing a FD code assuming small problem that doesn t need sparse matrices
Goal: Find temperature, ? ?,? for ???? ? = 0 0 ? source ? ?,? ? = 0 ???? ? = 0 ? ?? ?? ?2? satisfied in the interior ??2= ?
Finite Difference grid ? ?? 1 0 ? 0 ? ?? 1 ? ?? ?? ?2? satisfied in the interior ??2= ?
initial condition 0 ? 1 ? ?,? = 0 = 0 ?
boundary condition 1 ? ? = 0, ? ? ???? = 0 0 ? ? 1 ? ? = ????, ? ? ???? = 0
interior ?2? ?? ?? ??2 = ? ? ?,? ? ?,? ? ? ? ? ?,? ? 2? ?,? ? + ? ? + ?,? ? x2 ?? ?,? ? x2? ? ?,? ? + = ? ?,? 1 1 ?? ?,? 2 x2? ?,? ? x2? ? + ?,? + ? = ? ?,?
interior ?2? ?? ?? ??2 = ? ? ?,? ? ?,? ? ? ? ? ?,? ? 2? ?,? ? + ? ? + ?,? ? x2 ?? ?,? ? x2? ? ?,? ? + = ? ?,? 1 1 ?? ?,? 2 x2? ?,? ? x2? ? + ?,? + ? = ? ?,?
interior 1 1 2 x2? ?,? ? x2? ? ?,? ? ?? ?,? + ?+ x2? ? ?,? + ? = ? ?,?
interior ? ?? 1 0 ? 0 every interior equation involves 4 points ? ?? 1 1 1 2 x2? ?,? ? x2? ? ?,? ? ? ?? ?,? + ?+ x2? ? ?,? + ? = ? ?,?
Step 1: define x axis 0 ? 2 ? ? = ?? 1 ?
Step 2: define t axis 0 ? 2 ? ? = ?? 1 ?
Step 3: make tables to unwrap temperature matrix to vector ?0 ?? ?? 1 ?00 ?0,?? 1 ???,?? ? = ? = ??? 1,0 ??? 1,?? 1 ? = ?? ??
Step 3: make tables to unwrap temperature matrix to vector ?0 ?? ?? 1 ?00 ?0,?? 1 ???,?? ? = ? = ??? 1,0 ??? 1,?? 1
Step 3: make tables to unwrap temperature matrix to vector ?0 ?? ?? 1 ?00 ?0,?? 1 ???,?? ? = ? = ??? 1,0 ??? 1,?? 1
Steps 4, 5, 6 and 7: set up ? and ??? for ?? = ??? ? initial condition ? left boundary condition ? rt boundary condition ? interior equation ? ???
Step 4: initial conditions ? initial condition ? ???
Step 5: boundary conditions ? left boundary condition ? rt boundary condition ? ???
Steps 6: construct source ? Gaussian in ? impulsive in ? ? ? ???
Step 7: interior equation ? interior equation ? ???
Step 9: construct ? given ? ?0 ?? ?? 1 ?00 ?0,?? 1 ???,?? ? = ? = ??? 1,0 ??? 1,?? 1
trick is to build code incrementally step-by-step and test steps along the way