Numerical Solver for the 2D Heat Equation
Solving the 2D heat equation with explicit, implicit, and multi grid solvers on complex geometry.
Solving the 2D Heat Equation Using Finite Differencing on Complex Geometry¶
Completed as a requirement for CS 555 with Professor Andreas Kloeckner, this project solves the heat equation
on a complex two-dimentional domain; a room with with walls (Neumann boundary condition), windows (Dirichlet boundary condition) and radiators (heat sources).
In Part 1, we build up our grid, develope a scheme to handle boundary conditions, preform von Neumann stability analysis to choose a time step for our forward Euler solver, and then use an explicit time integrator to solve our equation.
In Part 2, we use a second-order accurate diagonally implicit time integrator, solve for a steady state solution, and implement the Jacobi and damped Jacobi method to solve for our steady state solution.
In Part 3, we implemet a V-Cycle Geometric Multigrid up to a 4-factor coarsening of our mesh, using restriction, prolongation, and Laplace matrices.
Part 1: An Explicit Solver¶
Setting up the grid¶
Building the Laplacian Matrix using with second order centered finite differences¶
Interior Regions¶
The finite difference scheme for the inerior region of the domain can be written as
Nuemann Boundary Conditions¶
The Nuemann boundary conditions give us that
When is in the wall, we use the left stencil D[0] = [-1.5 2. -0.5]
and we solve for such that
Similarly, when is in the wall, we use the right stencil D[-1] = [ 0.5 -2. 1.5]
and we solve for such that
Dirichlet boundary condition¶
This is simple enought to implement, we just do nothing to the neighbor when it is at a window
Testing Convergence of the Laplacian¶
Testing boundary conditions¶
To find the error in the infinity norm, we first create a test equation using the method of manufactured solutions. We do this on a square domain such that the the sides are Dirchle and the top and bottom are both Neumann. The we get the following boundary conditions: on the grid
We use as our manufatured solution, and solving for and on with our boudary equations yeilds . From here, we compute
We take the error of (the max absolute value of our numerical solution minus our true solution) on coarser and coarser grids, keeping fixed and arbitrary, plotting against .
The results of this plot show that our Laplacian error has tuncation error, which is what we were aiming for.
Forward Euler on the system¶
Foreward Euler is given by We preform Von Neummann stability analysis where and thus It is clear to see that this equation is at a maximum when Thus,
We now asses any benefit to using an explicit time integrator that has an order of accuracy higher than first. Take a time itterator, noting that with the timestep taken above. But has trucation error, and thus any explicit time intergrator would suffer from truncation error, and an explicit scheme would never achive more that first order accuracy.
Part 2: Implicit Solver, Steady-State Solution¶
second-order accurate diagonally implicit time integrator: the diagonaly implicit midpoint method which can be written as the solveable system
Steady State Solution¶
Our equation enters a steady state when . Thus, our equation becomes From here, we can use a sparse solver such as scipy.linalg.factorized
to solve for the steady state
Running Jacobi for 300 itterations gives a solution with bounded and rappid occilations between values. First, we notice that has negative eigenvalues, as is positive definite. When we view Jacobi as an explicit time integrator, this begins to make sence. First, we justify that Jacobi CAN, in fact, be viewed as an explicit time integrator. Take a general explicit time inegrator for the heat equation and take Jacobi Where . Thus, our equation becomes Which is an explicit time integrator. We know that has negative eigenvalues from above. We know from stability analysis that our system is stable within the range of on the real axis of the imaginary plane. But we also have that the closer our eigenvalues get to , the more our solution occilates (while remaining stable). This occilation seems to be exactly the occilation we see in our Jacobi solution.
Damped Jacobi Method¶
Let be the iterate computed by jacobi, then let
This damped Jacobi seems to act as a smoother on the overall output od the jacobi function. This may result from the fact that we are only applying a small percentage of jacobi at every step, so the osscialtions we see in undamped jacobi do not come into play. From imperical tests, it seems to me that the more I decrease the alpha term, the less-smoth the immage gets, as more jacobi is being applied.
Part 3: Geometric Multigrid¶
Constructing the restriction operator: picking values off the fine mesh a certian points¶
Constructing the prolongation operator¶
Let be a point on the fine grid and be a point on the coasrse grid. We now define how to construct the prolongation opperator.
The easiest case to deal with is when corresponds to , and no interpolation is nessasary.
Next, we consider a point that is on one of the coarse grid axes shuch that and is on the coarse grid. We interpolate to second order such that
We now consider when is not on any coarse axis. We again interpolate in the second order such that
where is the north-west neighbor.
Prolongation boundary condition handeling¶
As with the leplacian, the Dirichlet boundary conditions are easy to handle. If is in a wall, set .
For the Neumann boundary conditions, we first consider a point that is on a coarse axis. WLOG, assume is in a wall. Then we use the second order first derivative edge stencil
and our interpolation becomes
We now consider the case where we interpolate a point that is not on any coarse axis. WLOG, assume is in the wall. Then
and our interpolation becomes
Now we consider the diagnoal case where two neighbors are in the wall. WLOG, let and be in the wall. Then we have
and
thus
Finaly, we consider the case where only one neighbor is in the domain. WLOG, assume is the only neighbor in the domain. We use the diagonal line interpolation
Then we take the edge stencil
and we get
Testing convergence of the prolongation opperator¶
We test convergence using the same test domain and solution as with the Leplacian convergence test, with Dirichlet boundary's on top and Neumann boundaries on the side
We will plot versus where is the prolongation matrix.
Multigrid¶
Error and Blow-Up¶
In the calculations bellow, the multigrid proccess blows-up. I believe that this is a resul of the prolongation opperator failing to interpolate along the wall and window that is not 90 degrees. The plot bellow shows the error in in the steady state solution after one cycle of prolongation and restriction. The error seems to be localized to the stair-step window boundary. I am not quite sure what could be the cause of this error, as I do not believe that wall moving could happen after one interpolation cycle, though I am not sure that I have exausted every scenario on my test grid. Additionaly, I do not believe that my corner stencil is wrong as my other corners do not have error. My method to begug this would be to more extensivly exaust all possible scenarios on a test domain and extract the results to my problem.
As noted above, my residual does not decrease in the expected manner. Again, I believe that this is do to error in my interpolation near the stair-step boundary.