From 8ab415c6d92f9b2c922ddd937100a4729a4b5b98 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 2 May 2024 23:51:18 +0530 Subject: [PATCH] Consistently use a relative solver tolerance. --- examples/step-16/doc/results.dox | 54 ++++++++-------- examples/step-16/step-16.cc | 2 +- examples/step-4/doc/results.dox | 4 +- examples/step-4/step-4.cc | 2 +- examples/step-40/doc/results.dox | 37 +++++------ examples/step-40/step-40.cc | 3 +- examples/step-5/doc/results.dox | 12 ++-- examples/step-5/step-5.cc | 2 +- examples/step-6/doc/results.dox | 28 ++++----- examples/step-6/step-6.cc | 2 +- examples/step-7/doc/results.dox | 102 +++++++++++++++---------------- examples/step-7/step-7.cc | 2 +- examples/step-8/step-8.cc | 6 +- 13 files changed, 130 insertions(+), 126 deletions(-) diff --git a/examples/step-16/doc/results.dox b/examples/step-16/doc/results.dox index 962560ab34..3b1794044b 100644 --- a/examples/step-16/doc/results.dox +++ b/examples/step-16/doc/results.dox @@ -13,48 +13,50 @@ the solver performance. Therefore, here is the textual output: Cycle 0 Number of active cells: 80 Number of degrees of freedom: 89 (by level: 8, 25, 89) - Number of CG iterations: 8 + Number of CG iterations: 5 Cycle 1 - Number of active cells: 158 - Number of degrees of freedom: 183 (by level: 8, 25, 89, 138) - Number of CG iterations: 9 + Number of active cells: 152 + Number of degrees of freedom: 174 (by level: 8, 25, 89, 123) + Number of CG iterations: 5 Cycle 2 - Number of active cells: 302 - Number of degrees of freedom: 352 (by level: 8, 25, 89, 223, 160) - Number of CG iterations: 10 + Number of active cells: 287 + Number of degrees of freedom: 331 (by level: 8, 25, 89, 223, 127) + Number of CG iterations: 6 Cycle 3 - Number of active cells: 578 - Number of degrees of freedom: 649 (by level: 8, 25, 89, 231, 494, 66) - Number of CG iterations: 10 + Number of active cells: 545 + Number of degrees of freedom: 608 (by level: 8, 25, 89, 231, 476, 24) + Number of CG iterations: 6 Cycle 4 - Number of active cells: 1100 - Number of degrees of freedom: 1218 (by level: 8, 25, 89, 274, 764, 417, 126) - Number of CG iterations: 10 + Number of active cells: 1034 + Number of degrees of freedom: 1137 (by level: 8, 25, 89, 274, 756, 417, 15) + Number of CG iterations: 6 Cycle 5 - Number of active cells: 2096 - Number of degrees of freedom: 2317 (by level: 8, 25, 89, 304, 779, 1214, 817) - Number of CG iterations: 11 + Number of active cells: 1964 + Number of degrees of freedom: 2181 (by level: 8, 25, 89, 304, 779, 1030, 817) + Number of CG iterations: 6 Cycle 6 - Number of active cells: 3986 - Number of degrees of freedom: 4366 (by level: 8, 25, 89, 337, 836, 2270, 897, 1617) - Number of CG iterations: 10 + Number of active cells: 3734 + Number of degrees of freedom: 4101 (by level: 8, 25, 89, 337, 779, 2046, 885, 1545) + Number of CG iterations: 6 Cycle 7 - Number of active cells: 7574 - Number of degrees of freedom: 8350 (by level: 8, 25, 89, 337, 1086, 2835, 2268, 1789, 3217) - Number of CG iterations: 11 + Number of active cells: 7094 + Number of degrees of freedom: 7833 (by level: 8, 25, 89, 337, 1056, 2835, 1740, 1765, 3085) + Number of CG iterations: 6 + -That's almost perfect multigrid performance: the linear residual gets reduced by 12 orders of -magnitude in 10 iteration steps, and the results are almost independent of the mesh size. That's -obviously in part due to the simple nature of the problem solved, but -it shows the power of multigrid methods. +That's almost perfect multigrid performance: the linear residual gets +reduced by 6 orders of magnitude in 5 or 6 iterations, and the results +are almost independent of the mesh size. That's obviously in part due +to the simple nature of the problem solved, but it also shows the +power of multigrid methods.

Possibilities for extensions

diff --git a/examples/step-16/step-16.cc b/examples/step-16/step-16.cc index 72b51bd0ec..31f1ccdd79 100644 --- a/examples/step-16/step-16.cc +++ b/examples/step-16/step-16.cc @@ -580,7 +580,7 @@ namespace Step16 // With all this together, we can finally get about solving the linear // system in the usual way: - SolverControl solver_control(1000, 1e-12); + SolverControl solver_control(1000, 1e-6 * system_rhs.l2_norm()); SolverCG> solver(solver_control); solution = 0; diff --git a/examples/step-4/doc/results.dox b/examples/step-4/doc/results.dox index ebbb958247..6ce2297c62 100644 --- a/examples/step-4/doc/results.dox +++ b/examples/step-4/doc/results.dox @@ -10,12 +10,12 @@ Solving problem in 2 space dimensions. Number of active cells: 256 Total number of cells: 341 Number of degrees of freedom: 289 - 26 CG iterations needed to obtain convergence. + 19 CG iterations needed to obtain convergence. Solving problem in 3 space dimensions. Number of active cells: 4096 Total number of cells: 4681 Number of degrees of freedom: 4913 - 30 CG iterations needed to obtain convergence. + 20 CG iterations needed to obtain convergence. @endcode It is obvious that in three spatial dimensions the number of cells and therefore also the number of degrees of freedom is diff --git a/examples/step-4/step-4.cc b/examples/step-4/step-4.cc index d0e622d7c6..a049da255e 100644 --- a/examples/step-4/step-4.cc +++ b/examples/step-4/step-4.cc @@ -448,7 +448,7 @@ void Step4::assemble_system() template void Step4::solve() { - SolverControl solver_control(1000, 1e-12); + SolverControl solver_control(1000, 1e-6 * system_rhs.l2_norm()); SolverCG> solver(solver_control); solver.solve(system_matrix, solution, system_rhs, PreconditionIdentity()); diff --git a/examples/step-40/doc/results.dox b/examples/step-40/doc/results.dox index 334ed47525..b5def9afd8 100644 --- a/examples/step-40/doc/results.dox +++ b/examples/step-40/doc/results.dox @@ -3,47 +3,48 @@ When you run the program, on a single processor or with your local MPI installation on a few, you should get output like this: @code +Running with PETSc on 1 MPI rank(s)... Cycle 0: Number of active cells: 1024 Number of degrees of freedom: 4225 - Solved in 10 iterations. + Solved in 7 iterations. +---------------------------------------------+------------+------------+ -| Total wallclock time elapsed since start | 0.176s | | +| Total wallclock time elapsed since start | 0.548s | | | | | | | Section | no. calls | wall time | % of total | +---------------------------------+-----------+------------+------------+ -| assembly | 1 | 0.0209s | 12% | -| output | 1 | 0.0189s | 11% | -| setup | 1 | 0.0299s | 17% | -| solve | 1 | 0.0419s | 24% | +| assembly | 1 | 0.242s | 44% | +| output | 1 | 0.0495s | 9% | +| setup | 1 | 0.102s | 19% | +| solve | 1 | 0.0283s | 5.2% | +---------------------------------+-----------+------------+------------+ Cycle 1: - Number of active cells: 1954 - Number of degrees of freedom: 8399 - Solved in 10 iterations. + Number of active cells: 1963 + Number of degrees of freedom: 8437 + Solved in 7 iterations. +---------------------------------------------+------------+------------+ -| Total wallclock time elapsed since start | 0.327s | | +| Total wallclock time elapsed since start | 1.19s | | | | | | | Section | no. calls | wall time | % of total | +---------------------------------+-----------+------------+------------+ -| assembly | 1 | 0.0368s | 11% | -| output | 1 | 0.0208s | 6.4% | -| refine | 1 | 0.157s | 48% | -| setup | 1 | 0.0452s | 14% | -| solve | 1 | 0.0668s | 20% | +| assembly | 1 | 0.469s | 40% | +| output | 1 | 0.0899s | 7.6% | +| refine | 1 | 0.429s | 36% | +| setup | 1 | 0.177s | 15% | +| solve | 1 | 0.0204s | 1.7% | +---------------------------------+-----------+------------+------------+ Cycle 2: - Number of active cells: 3664 - Number of degrees of freedom: 16183 - Solved in 11 iterations. + Number of active cells: 3670 + Number of degrees of freedom: 16175 + Solved in 7 iterations. ... @endcode diff --git a/examples/step-40/step-40.cc b/examples/step-40/step-40.cc index 622700234b..954781e15a 100644 --- a/examples/step-40/step-40.cc +++ b/examples/step-40/step-40.cc @@ -493,7 +493,8 @@ namespace Step40 LA::MPI::Vector completely_distributed_solution(locally_owned_dofs, mpi_communicator); - SolverControl solver_control(dof_handler.n_dofs(), 1e-12); + SolverControl solver_control(dof_handler.n_dofs(), + 1e-6 * system_rhs.l2_norm()); LA::SolverCG solver(solver_control); diff --git a/examples/step-5/doc/results.dox b/examples/step-5/doc/results.dox index 65eb360255..4446700902 100644 --- a/examples/step-5/doc/results.dox +++ b/examples/step-5/doc/results.dox @@ -7,32 +7,32 @@ Cycle 0: Number of active cells: 20 Total number of cells: 20 Number of degrees of freedom: 25 - 13 CG iterations needed to obtain convergence. + 8 CG iterations needed to obtain convergence. Cycle 1: Number of active cells: 80 Total number of cells: 100 Number of degrees of freedom: 89 - 18 CG iterations needed to obtain convergence. + 12 CG iterations needed to obtain convergence. Cycle 2: Number of active cells: 320 Total number of cells: 420 Number of degrees of freedom: 337 - 29 CG iterations needed to obtain convergence. + 21 CG iterations needed to obtain convergence. Cycle 3: Number of active cells: 1280 Total number of cells: 1700 Number of degrees of freedom: 1313 - 52 CG iterations needed to obtain convergence. + 38 CG iterations needed to obtain convergence. Cycle 4: Number of active cells: 5120 Total number of cells: 6820 Number of degrees of freedom: 5185 - 95 CG iterations needed to obtain convergence. + 70 CG iterations needed to obtain convergence. Cycle 5: Number of active cells: 20480 Total number of cells: 27300 Number of degrees of freedom: 20609 - 182 CG iterations needed to obtain convergence. + 136 CG iterations needed to obtain convergence. @endcode diff --git a/examples/step-5/step-5.cc b/examples/step-5/step-5.cc index bba78459f6..49a4bd5068 100644 --- a/examples/step-5/step-5.cc +++ b/examples/step-5/step-5.cc @@ -258,7 +258,7 @@ void Step5::assemble_system() template void Step5::solve() { - SolverControl solver_control(1000, 1e-12); + SolverControl solver_control(1000, 1e-6 * system_rhs.l2_norm()); SolverCG> solver(solver_control); PreconditionSSOR> preconditioner; diff --git a/examples/step-6/doc/results.dox b/examples/step-6/doc/results.dox index 650280da53..dd55215632 100644 --- a/examples/step-6/doc/results.dox +++ b/examples/step-6/doc/results.dox @@ -7,26 +7,26 @@ Cycle 0: Number of active cells: 20 Number of degrees of freedom: 89 Cycle 1: - Number of active cells: 44 - Number of degrees of freedom: 209 + Number of active cells: 38 + Number of degrees of freedom: 183 Cycle 2: - Number of active cells: 92 - Number of degrees of freedom: 449 + Number of active cells: 71 + Number of degrees of freedom: 325 Cycle 3: - Number of active cells: 200 - Number of degrees of freedom: 921 + Number of active cells: 146 + Number of degrees of freedom: 689 Cycle 4: - Number of active cells: 440 - Number of degrees of freedom: 2017 + Number of active cells: 284 + Number of degrees of freedom: 1373 Cycle 5: - Number of active cells: 956 - Number of degrees of freedom: 4425 + Number of active cells: 599 + Number of degrees of freedom: 2769 Cycle 6: - Number of active cells: 1916 - Number of degrees of freedom: 8993 + Number of active cells: 1241 + Number of degrees of freedom: 5833 Cycle 7: - Number of active cells: 3860 - Number of degrees of freedom: 18353 + Number of active cells: 2507 + Number of degrees of freedom: 11916 @endcode diff --git a/examples/step-6/step-6.cc b/examples/step-6/step-6.cc index 3dd3c7153c..6b6c5ad947 100644 --- a/examples/step-6/step-6.cc +++ b/examples/step-6/step-6.cc @@ -332,7 +332,7 @@ void Step6::assemble_system() template void Step6::solve() { - SolverControl solver_control(1000, 1e-12); + SolverControl solver_control(1000, 1e-6 * system_rhs.l2_norm()); SolverCG> solver(solver_control); PreconditionSSOR> preconditioner; diff --git a/examples/step-7/doc/results.dox b/examples/step-7/doc/results.dox index de8f65c895..20253b246c 100644 --- a/examples/step-7/doc/results.dox +++ b/examples/step-7/doc/results.dox @@ -28,40 +28,40 @@ Cycle 0: Number of active cells: 64 Number of degrees of freedom: 81 Cycle 1: - Number of active cells: 124 - Number of degrees of freedom: 157 + Number of active cells: 121 + Number of degrees of freedom: 154 Cycle 2: Number of active cells: 280 Number of degrees of freedom: 341 Cycle 3: - Number of active cells: 577 - Number of degrees of freedom: 690 + Number of active cells: 565 + Number of degrees of freedom: 678 Cycle 4: - Number of active cells: 1099 - Number of degrees of freedom: 1264 + Number of active cells: 1075 + Number of degrees of freedom: 1240 Cycle 5: - Number of active cells: 2191 - Number of degrees of freedom: 2452 + Number of active cells: 2041 + Number of degrees of freedom: 2306 Cycle 6: - Number of active cells: 4165 - Number of degrees of freedom: 4510 + Number of active cells: 3913 + Number of degrees of freedom: 4216 Cycle 7: - Number of active cells: 7915 - Number of degrees of freedom: 8440 + Number of active cells: 7432 + Number of degrees of freedom: 7909 Cycle 8: - Number of active cells: 15196 - Number of degrees of freedom: 15912 + Number of active cells: 14203 + Number of degrees of freedom: 14870 cycle cells dofs L2 H1 Linfty 0 64 81 1.840e+00 2.858e+00 1.835e+00 - 1 124 157 5.190e-02 1.200e+00 1.344e-01 + 1 121 154 5.336e-02 1.200e+00 1.354e-01 2 280 341 1.439e-02 7.892e-01 7.554e-02 - 3 577 690 8.627e-03 5.061e-01 2.805e-02 - 4 1099 1264 3.217e-03 3.030e-01 1.073e-02 - 5 2191 2452 1.445e-03 2.097e-01 5.073e-03 - 6 4165 4510 8.387e-04 1.460e-01 2.013e-03 - 7 7915 8440 7.051e-04 1.053e-01 1.804e-03 - 8 15196 15912 2.774e-04 7.463e-02 6.911e-04 + 3 565 678 8.696e-03 5.086e-01 2.843e-02 + 4 1075 1240 3.245e-03 3.059e-01 1.072e-02 + 5 2041 2306 2.407e-03 2.147e-01 5.156e-03 + 6 3913 4216 8.501e-04 1.503e-01 2.033e-03 + 7 7432 7909 7.113e-04 1.086e-01 1.808e-03 + 8 14203 14870 3.140e-04 7.671e-02 7.181e-04 Solving with Q1 elements, global refinement =========================================== @@ -119,15 +119,15 @@ cycle cells dofs L2 H1 Linfty 0 64 289 1.606e-01 1.278e+00 3.029e-01 1 256 1089 7.638e-03 5.248e-01 4.816e-02 2 1024 4225 8.601e-04 1.086e-01 4.827e-03 - 3 4096 16641 1.107e-04 2.756e-02 7.802e-04 - 4 16384 66049 1.393e-05 6.915e-03 9.971e-05 + 3 4096 16641 1.107e-04 2.756e-02 7.804e-04 + 4 16384 66049 1.394e-05 6.915e-03 9.991e-05 n cells H1 L2 0 64 1.278e+00 - - 1.606e-01 - - 1 256 5.248e-01 2.43 1.28 7.638e-03 21.03 4.39 2 1024 1.086e-01 4.83 2.27 8.601e-04 8.88 3.15 3 4096 2.756e-02 3.94 1.98 1.107e-04 7.77 2.96 -4 16384 6.915e-03 3.99 1.99 1.393e-05 7.94 2.99 +4 16384 6.915e-03 3.99 1.99 1.394e-05 7.94 2.99 Solving with Q2 elements, adaptive refinement =========================================== @@ -136,40 +136,40 @@ Cycle 0: Number of active cells: 64 Number of degrees of freedom: 289 Cycle 1: - Number of active cells: 124 - Number of degrees of freedom: 577 + Number of active cells: 121 + Number of degrees of freedom: 569 Cycle 2: - Number of active cells: 289 - Number of degrees of freedom: 1353 + Number of active cells: 280 + Number of degrees of freedom: 1317 Cycle 3: - Number of active cells: 547 - Number of degrees of freedom: 2531 + Number of active cells: 529 + Number of degrees of freedom: 2459 Cycle 4: - Number of active cells: 1057 - Number of degrees of freedom: 4919 + Number of active cells: 1015 + Number of degrees of freedom: 4719 Cycle 5: - Number of active cells: 2059 - Number of degrees of freedom: 9223 + Number of active cells: 1963 + Number of degrees of freedom: 9039 Cycle 6: - Number of active cells: 3913 - Number of degrees of freedom: 17887 + Number of active cells: 3727 + Number of degrees of freedom: 17143 Cycle 7: - Number of active cells: 7441 - Number of degrees of freedom: 33807 + Number of active cells: 7081 + Number of degrees of freedom: 32343 Cycle 8: - Number of active cells: 14212 - Number of degrees of freedom: 64731 + Number of active cells: 13525 + Number of degrees of freedom: 60895 cycle cells dofs L2 H1 Linfty 0 64 289 1.606e-01 1.278e+00 3.029e-01 - 1 124 577 7.891e-03 5.256e-01 4.852e-02 - 2 289 1353 1.070e-03 1.155e-01 4.868e-03 - 3 547 2531 5.962e-04 5.101e-02 1.876e-03 - 4 1057 4919 1.977e-04 3.094e-02 7.923e-04 - 5 2059 9223 7.738e-05 1.974e-02 7.270e-04 - 6 3913 17887 2.925e-05 8.772e-03 1.463e-04 - 7 7441 33807 1.024e-05 4.121e-03 8.567e-05 - 8 14212 64731 3.761e-06 2.108e-03 2.167e-05 + 1 121 569 7.916e-03 5.257e-01 4.857e-02 + 2 280 1317 1.092e-03 1.165e-01 4.832e-03 + 3 529 2459 5.999e-04 5.177e-02 1.873e-03 + 4 1015 4719 2.100e-04 3.245e-02 7.938e-04 + 5 1963 9039 7.821e-05 1.990e-02 7.261e-04 + 6 3727 17143 2.868e-05 8.498e-03 1.462e-04 + 7 7081 32343 1.146e-05 4.360e-03 8.576e-05 + 8 13525 60895 3.747e-06 2.123e-03 2.174e-05 @endcode @@ -195,7 +195,7 @@ because we were interested in testing that our solutions *converge*. But from an engineering perspective, the question is often more practical: How fine do I have to make my mesh so that the error is "small enough"? In other words, if in the table above the $H^1$ -semi-norm has been reduced to `4.121e-03`, is this good enough for me +semi-norm has been reduced to `2.123e-03`, is this good enough for me to sign the blueprint and declare that our numerical simulation showed that the bridge is strong enough? @@ -203,12 +203,12 @@ In practice, we are rarely in this situation because I can not typically compare the numerical solution $u_h$ against the exact solution $u$ in situations that matter -- if I knew $u$, I would not have to compute $u_h$. But even if I could, the question to ask in -general is then: `4.121e-03` *what*? The solution will have physical +general is then: `2.123e-03` *what*? The solution will have physical units, say kg-times-meter-squared, and I'm integrating a function with units square of the above over the domain, and then take the square root. So if the domain is two-dimensional, the units of $\|u-u_h\|_{L_2}$ are kg-times-meter-cubed. The question is then: Is -$4.121\times 10^{-3}$ kg-times-meter-cubed small? That depends on what +$2.123\times 10^{-3}$ kg-times-meter-cubed small? That depends on what you're trying to simulate: If you're an astronomer used to masses measured in solar masses and distances in light years, then yes, this is a fantastically small number. But if you're doing atomic physics, diff --git a/examples/step-7/step-7.cc b/examples/step-7/step-7.cc index b13c306c5c..16857e13c7 100644 --- a/examples/step-7/step-7.cc +++ b/examples/step-7/step-7.cc @@ -704,7 +704,7 @@ namespace Step7 template void HelmholtzProblem::solve() { - SolverControl solver_control(1000, 1e-12); + SolverControl solver_control(1000, 1e-6 * system_rhs.l2_norm()); SolverCG> cg(solver_control); PreconditionSSOR> preconditioner; diff --git a/examples/step-8/step-8.cc b/examples/step-8/step-8.cc index 517f37bda5..8ad98d4555 100644 --- a/examples/step-8/step-8.cc +++ b/examples/step-8/step-8.cc @@ -434,14 +434,14 @@ namespace Step8 // @sect4{ElasticProblem::solve} - // The solver does not care about where the system of equations comes, as - // long as it stays positive definite and symmetric (which are the + // The solver does not care about where the system of equations comes from, as + // long as it is positive definite and symmetric (which are the // requirements for the use of the CG solver), which the system indeed // is. Therefore, we need not change anything. template void ElasticProblem::solve() { - SolverControl solver_control(1000, 1e-12); + SolverControl solver_control(1000, 1e-6 * system_rhs.l2_norm()); SolverCG> cg(solver_control); PreconditionSSOR> preconditioner; -- 2.39.5