4. Homework #3ΒΆ

For all programming assignments, please turn in your code along with your solution. Submissions should be made on Sakai.

Problem 1

Consider a uniform \(N\times N\) grid whose bottom left node is at the point \((-0.5,-0.5)\) and top right node is at the point \((0.5,0.5)\). Define a circle \(C\) centered at \((0,0)\) and with radius \(0.25\). Label all voxels inside \(C\) as Interior, and all other voxels as Dirichlet. Use the analytic function \(\phi=x^2 + y^2 - r^2\) to define the Dirichlet values. However, as pointed out in class, for each Dirichlet voxel, project its cell center to the nearest point on the circle, compute the \(\phi\)-value at that point, and use this as the Dirichlet value for the cell. In other words, if \(p\) is the location of the cell center of a Dirichlet voxel, compute the point \(q=0.25*p\), and use the \(\phi\)-value at \(q\) for the Dirichlet value at \(p\). Set the right hand side to be the constant \(4\) for each voxel.

Using the methology discussed in class, write a \(\textsf{CG_System}\) class and a \(\textsf{CG_Vector}\) class, and solve the Poisson equation for the setup described above using \(\textsf{Conjugate Gradients}\). Report the \(L_\infty\)-norm for the error computed as \(|\phi_\texttt{cell} - x^2 - y^2 + r^2|\) for each voxel, for grids \(16\times16\), \(32\times32\), \(64\times64\), \(128\times128\) and \(256\times256\). If your solution is correct, you should see the error decrease approximately by a factor of \(2\) each time you double the grid resolution. Compute the order of convergence, defined as \(\log_2(e_{N\times N}/e_{2N\times2N})\), where \(e_{N\times N}\) is the \(L_\infty\)-norm of the error for an \(N\times N\) grid.

Note: Please follow the implementation of \(\textsf{Conjugate_Gradient}\) as described here to make use of the \(\textsf{CG_System}\) and \(\textsf{CG_Vector}\) classes.