{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Results of Multigrid for Reaction-Diffusion" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Imports" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "slideshow": { "slide_type": "slide" } }, "outputs": [], "source": [ "from main import inputParameters, runDemo\n", "import logging\n", "logging.basicConfig(level=logging.INFO , format='[%(asctime)s] - [%(levelname)s] - %(message)s')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Set parameters" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "==================\n", "* DEFAULT VALUES *\n", "==================\n", "LEVELS = 5\n", "SHOW_GRIDS = False\n", "DEGREE = 1\n", "CYCLE = W\n", "MAX_ITER = 100\n", "SMOOTHING_STEPS = 2\n", "SMOOTHER = Jacobi\n", "OMEGA = 0.8\n", "\n", "Would you like to change some values? (Y/N): y\n", "Number of MG levels (default: 5) = 10\n", "Plot grids (default: False) = \n", "Degree of FE (default: 1) = \n", "Multigrid cycle (default: W; supported: 'V','W') = \n", "Maximum number of MG iterations (default: 100) = \n", "Number of smoothing steps (default: 2) = \n", "Smoother type (default: Jacobi; supported: 'Jacobi','GaussSeidel') = \n", "Relaxation parameter omega (default: 0.8) = \n", "\n", "=================\n", "* CUSTOM VALUES *\n", "=================\n", "LEVELS = 10\n", "SHOW_GRIDS = False\n", "DEGREE = 1\n", "CYCLE = W\n", "MAX_ITER = 100\n", "SMOOTHING_STEPS = 2\n", "SMOOTHER = Jacobi\n", "OMEGA = 0.8\n", "\n" ] } ], "source": [ "inputParameters()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Demo" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now that the user has inserted the parameters of the multigrid algorithm,\n", "we start by solving the two-grid method, refine the grid, solve the three-grid method, etc." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2020-06-21 21:33:27,249] - [INFO] - +-----------------------------------------+\n", "[2020-06-21 21:33:27,250] - [INFO] - + MULTIGRID (LEVELS = 2) +\n", "[2020-06-21 21:33:27,250] - [INFO] - +-----------------------------------------+\n", "[2020-06-21 21:33:27,518] - [INFO] - Number of DoFs: 21 (by level: 8,21)\n", "[2020-06-21 21:33:27,563] - [INFO] - Defect: 5.43e-13\n", "[2020-06-21 21:33:27,564] - [INFO] - GMG iterations: 14\n", "[2020-06-21 21:33:27,564] - [INFO] - Multigrid time: 0.044 s\n", "[2020-06-21 21:33:27,565] - [INFO] - Convergence rate: 1.0005\n", "[2020-06-21 21:33:27,567] - [INFO] - Total time: 318 ms\n", "[2020-06-21 21:33:27,567] - [INFO] - \n", "[2020-06-21 21:33:27,568] - [INFO] - +-----------------------------------------+\n", "[2020-06-21 21:33:27,568] - [INFO] - + MULTIGRID (LEVELS = 3) +\n", "[2020-06-21 21:33:27,569] - [INFO] - +-----------------------------------------+\n", "[2020-06-21 21:33:27,847] - [INFO] - Number of DoFs: 65 (by level: 8,21,65)\n", "[2020-06-21 21:33:27,938] - [INFO] - Defect: 4.54e-13\n", "[2020-06-21 21:33:27,938] - [INFO] - GMG iterations: 15\n", "[2020-06-21 21:33:27,939] - [INFO] - Multigrid time: 0.089 s\n", "[2020-06-21 21:33:27,940] - [INFO] - Convergence rate: 0.9929\n", "[2020-06-21 21:33:27,941] - [INFO] - Total time: 374 ms\n", "[2020-06-21 21:33:27,942] - [INFO] - \n", "[2020-06-21 21:33:27,942] - [INFO] - +-----------------------------------------+\n", "[2020-06-21 21:33:27,943] - [INFO] - + MULTIGRID (LEVELS = 4) +\n", "[2020-06-21 21:33:27,943] - [INFO] - +-----------------------------------------+\n", "[2020-06-21 21:33:28,226] - [INFO] - Number of DoFs: 225 (by level: 8,21,65,225)\n", "[2020-06-21 21:33:28,405] - [INFO] - Defect: 8.66e-13\n", "[2020-06-21 21:33:28,406] - [INFO] - GMG iterations: 14\n", "[2020-06-21 21:33:28,407] - [INFO] - Multigrid time: 0.173 s\n", "[2020-06-21 21:33:28,407] - [INFO] - Convergence rate: 0.9927\n", "[2020-06-21 21:33:28,410] - [INFO] - Total time: 468 ms\n", "[2020-06-21 21:33:28,411] - [INFO] - \n", "[2020-06-21 21:33:28,412] - [INFO] - +-----------------------------------------+\n", "[2020-06-21 21:33:28,412] - [INFO] - + MULTIGRID (LEVELS = 5) +\n", "[2020-06-21 21:33:28,413] - [INFO] - +-----------------------------------------+\n", "[2020-06-21 21:33:28,841] - [INFO] - Number of DoFs: 833 (by level: 8,21,65,225,833)\n", "[2020-06-21 21:33:29,227] - [INFO] - Defect: 6.6e-13\n", "[2020-06-21 21:33:29,228] - [INFO] - GMG iterations: 14\n", "[2020-06-21 21:33:29,228] - [INFO] - Multigrid time: 0.371 s\n", "[2020-06-21 21:33:29,228] - [INFO] - Convergence rate: 0.9986\n", "[2020-06-21 21:33:29,233] - [INFO] - Total time: 822 ms\n", "[2020-06-21 21:33:29,234] - [INFO] - \n", "[2020-06-21 21:33:29,235] - [INFO] - +-----------------------------------------+\n", "[2020-06-21 21:33:29,235] - [INFO] - + MULTIGRID (LEVELS = 6) +\n", "[2020-06-21 21:33:29,236] - [INFO] - +-----------------------------------------+\n", "[2020-06-21 21:33:30,104] - [INFO] - Number of DoFs: 3201 (by level: 8,21,65,225,833,3201)\n", "[2020-06-21 21:33:30,897] - [INFO] - Defect: 6.57e-13\n", "[2020-06-21 21:33:30,897] - [INFO] - GMG iterations: 13\n", "[2020-06-21 21:33:30,898] - [INFO] - Multigrid time: 0.73 s\n", "[2020-06-21 21:33:30,899] - [INFO] - Convergence rate: 1.0079\n", "[2020-06-21 21:33:30,914] - [INFO] - Total time: 1 s 680 ms\n", "[2020-06-21 21:33:30,915] - [INFO] - \n", "[2020-06-21 21:33:30,916] - [INFO] - +-----------------------------------------+\n", "[2020-06-21 21:33:30,917] - [INFO] - + MULTIGRID (LEVELS = 7) +\n", "[2020-06-21 21:33:30,917] - [INFO] - +-----------------------------------------+\n", "[2020-06-21 21:33:33,536] - [INFO] - Number of DoFs: 12545 (by level: 8,21,65,225,833,3201,12545)\n", "[2020-06-21 21:33:35,531] - [INFO] - Defect: 4.27e-13\n", "[2020-06-21 21:33:35,532] - [INFO] - GMG iterations: 13\n", "[2020-06-21 21:33:35,533] - [INFO] - Multigrid time: 1.786 s\n", "[2020-06-21 21:33:35,535] - [INFO] - Convergence rate: 1.0163\n", "[2020-06-21 21:33:35,625] - [INFO] - Total time: 4 s 710 ms\n", "[2020-06-21 21:33:35,626] - [INFO] - \n", "[2020-06-21 21:33:35,626] - [INFO] - +-----------------------------------------+\n", "[2020-06-21 21:33:35,627] - [INFO] - + MULTIGRID (LEVELS = 8) +\n", "[2020-06-21 21:33:35,627] - [INFO] - +-----------------------------------------+\n", "[2020-06-21 21:33:45,121] - [INFO] - Number of DoFs: 49665 (by level: 8,21,65,225,833,3201,12545,49665)\n", "[2020-06-21 21:33:49,748] - [INFO] - Defect: 9.59e-13\n", "[2020-06-21 21:33:49,748] - [INFO] - GMG iterations: 12\n", "[2020-06-21 21:33:49,750] - [INFO] - Multigrid time: 3.791 s\n", "[2020-06-21 21:33:49,751] - [INFO] - Convergence rate: 1.0314\n", "[2020-06-21 21:33:50,001] - [INFO] - Total time: 14 s 374 ms\n", "[2020-06-21 21:33:50,002] - [INFO] - \n", "[2020-06-21 21:33:50,003] - [INFO] - +-----------------------------------------+\n", "[2020-06-21 21:33:50,003] - [INFO] - + MULTIGRID (LEVELS = 9) +\n", "[2020-06-21 21:33:50,004] - [INFO] - +-----------------------------------------+\n", "[2020-06-21 21:34:27,930] - [INFO] - Number of DoFs: 197633 (by level: 8,21,65,225,833,3201,12545,49665,197633)\n", "[2020-06-21 21:34:41,596] - [INFO] - Defect: 4.53e-13\n", "[2020-06-21 21:34:41,597] - [INFO] - GMG iterations: 12\n", "[2020-06-21 21:34:41,598] - [INFO] - Multigrid time: 10.005 s\n", "[2020-06-21 21:34:41,598] - [INFO] - Convergence rate: 1.0361\n", "[2020-06-21 21:34:42,537] - [INFO] - Total time: 52 s 535 ms\n", "[2020-06-21 21:34:42,538] - [INFO] - \n", "[2020-06-21 21:34:42,539] - [INFO] - +-----------------------------------------+\n", "[2020-06-21 21:34:42,539] - [INFO] - + MULTIGRID (LEVELS = 10) +\n", "[2020-06-21 21:34:42,540] - [INFO] - +-----------------------------------------+\n", "[2020-06-21 21:37:07,533] - [INFO] - Number of DoFs: 788481 (by level: 8,21,65,225,833,3201,12545,49665,197633,788481)\n", "[2020-06-21 21:37:45,600] - [INFO] - Defect: 8.76e-13\n", "[2020-06-21 21:37:45,601] - [INFO] - GMG iterations: 11\n", "[2020-06-21 21:37:45,601] - [INFO] - Multigrid time: 25.034 s\n", "[2020-06-21 21:37:45,602] - [INFO] - Convergence rate: 1.045\n", "[2020-06-21 21:37:49,246] - [INFO] - Total time: 3 min 6 s 707 ms\n", "[2020-06-21 21:37:49,247] - [INFO] - \n" ] } ], "source": [ "runDemo()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Results\n", "\n", "| Refinements | DoFs | Iterations | Computation time | Convergence rate |\n", "| :---: | ------ | :---: | --- | :---: |\n", "| 1 | 21 | 14 | 0.044 | 1.0005 |\n", "| 2 | 65 | 14 | 0.089 | 0.9929 |\n", "| 3 | 225 | 14 | 0.173 | 0.9927 |\n", "| 4 | 833 | 14 | 0.371 | 0.9986 |\n", "| 5 | 3201 | 13 | 0.730| 1.0079 |\n", "| 6 | 12545 | 13 | 1.786 | 1.0163 |\n", "| 7 | 49665 | 12 | 3.791 |1.0314 |\n", "| 8 | 197633 | 12 | 10.005 | 1.0361 |\n", "| 9 |788481 | 11 | 25.034 | 1.0450 |" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We would expect from the theory that the number of multigrid iterations needed should be constant and thus independent of the number of levels. This property is approximately fulfilled in our simulation. Furthermore, the computation time should depend linearly on the number of DoFs. In the table above, we can see that the computation time doubles as a rule of thumb after each refinement and the number of DoFs quadruples. Thus the time of the multigrid solver depends linearly on the number of degrees of freedom. Note that for us the assembly is a big bottleneck, since it hasn't been optimized yet." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "From the theory of the multigrid algorithm it is known that for an $H^1/H^1_0$-elliptic boundary value problem with an $H^2$-regular boundary and conformig finite elements on uniformly refined triangulations, the multigrid convergence rate in the energy norm $\\rho_l \\leq \\rho < 1$ is mesh independent. Therefore with each approximation step, we get a more accurate solution, independent of the number of uniform refinements: $$\\| u^{(k+1)} - u^\\ast \\| \\leq \\rho \\| u^{(k)} - u^\\ast \\|.$$\n", "Thus it is being ensured that the multigrid algorithm converges in a certain number of steps, which does not depend on the number of DoFs. In our numerical tests, we didn't have an $H^2$-regular boundary, but it still could be observed that the multigrid algorithm terminated in at most 14 iterations. Hence, there was no real dependence on the number of refinements." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.5" } }, "nbformat": 4, "nbformat_minor": 4 }