From 02bcf1ba35580a9ae366639faea43132429bf849 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 7 Jan 2022 12:28:55 -0700 Subject: [PATCH] Replace use of 'long double' by 'double' in step-10. --- examples/step-10/doc/results.dox | 98 ++++++++++++++++---------------- examples/step-10/step-10.cc | 45 ++++----------- 2 files changed, 61 insertions(+), 82 deletions(-) diff --git a/examples/step-10/doc/results.dox b/examples/step-10/doc/results.dox index 95c88c008b..628bfc69d2 100644 --- a/examples/step-10/doc/results.dox +++ b/examples/step-10/doc/results.dox @@ -119,81 +119,81 @@ Computation of Pi by the area: ============================== Degree = 1 cells eval.pi error - 5 1.9999999999999991 1.1416e+00 - - 20 2.8284271247461890 3.1317e-01 1.87 - 80 3.0614674589207174 8.0125e-02 1.97 - 320 3.1214451522580515 2.0148e-02 1.99 - 1280 3.1365484905459380 5.0442e-03 2.00 - 5120 3.1403311569547516 1.2615e-03 2.00 + 5 1.9999999999999984 1.1416e+00 - + 20 2.8284271247461947 3.1317e-01 1.87 + 80 3.0614674589207289 8.0125e-02 1.97 + 320 3.1214451522579965 2.0148e-02 1.99 + 1280 3.1365484905461294 5.0442e-03 2.00 + 5120 3.1403311569547410 1.2615e-03 2.00 Degree = 2 cells eval.pi error - 5 3.1045694996615860 3.7023e-02 - - 20 3.1391475703122267 2.4451e-03 3.92 - 80 3.1414377167038294 1.5494e-04 3.98 - 320 3.1415829366419010 9.7169e-06 4.00 - 1280 3.1415920457576911 6.0783e-07 4.00 - 5120 3.1415926155921130 3.7998e-08 4.00 + 5 3.1045694996615865 3.7023e-02 - + 20 3.1391475703122351 2.4451e-03 3.92 + 80 3.1414377167038401 1.5494e-04 3.98 + 320 3.1415829366418513 9.7169e-06 4.00 + 1280 3.1415920457578785 6.0783e-07 4.00 + 5120 3.1415926155920988 3.7998e-08 4.00 Degree = 3 cells eval.pi error - 5 3.1410033851499310 5.8927e-04 - - 20 3.1415830393583857 9.6142e-06 5.94 - 80 3.1415925017363828 1.5185e-07 5.98 - 320 3.1415926512106704 2.3791e-09 6.00 - 1280 3.1415926535525944 3.7199e-11 6.00 - 5120 3.1415926535892122 5.8117e-13 6.00 + 5 3.1410033851499315 5.8927e-04 - + 20 3.1415830393583946 9.6142e-06 5.94 + 80 3.1415925017363939 1.5185e-07 5.98 + 320 3.1415926512106185 2.3792e-09 6.00 + 1280 3.1415926535527783 3.7015e-11 6.01 + 5120 3.1415926535891936 5.9952e-13 5.95 Degree = 4 cells eval.pi error - 5 3.1415871927401136 5.4608e-06 - - 20 3.1415926314742446 2.2116e-08 7.95 - 80 3.1415926535026215 8.7172e-11 7.99 - 320 3.1415926535894516 3.4157e-13 8.00 - 1280 3.1415926535897918 1.5339e-15 7.80 - 5120 3.1415926535897927 5.2649e-16 1.54 + 5 3.1415871927401144 5.4608e-06 - + 20 3.1415926314742491 2.2116e-08 7.95 + 80 3.1415926535026268 8.7166e-11 7.99 + 320 3.1415926535894005 3.9257e-13 7.79 + 1280 3.1415926535899774 1.8430e-13 1.09 + 5120 3.1415926535897669 2.6201e-14 2.81 Computation of Pi by the perimeter: =================================== Degree = 1 cells eval.pi error - 5 2.8284271247461898 3.1317e-01 - - 20 3.0614674589207178 8.0125e-02 1.97 - 80 3.1214451522580520 2.0148e-02 1.99 - 320 3.1365484905459389 5.0442e-03 2.00 - 1280 3.1403311569547525 1.2615e-03 2.00 - 5120 3.1412772509327724 3.1540e-04 2.00 + 5 2.8284271247461903 3.1317e-01 - + 20 3.0614674589207187 8.0125e-02 1.97 + 80 3.1214451522580493 2.0148e-02 1.99 + 320 3.1365484905459371 5.0442e-03 2.00 + 1280 3.1403311569547530 1.2615e-03 2.00 + 5120 3.1412772509327755 3.1540e-04 2.00 Degree = 2 cells eval.pi error - 5 3.1248930668550594 1.6700e-02 - - 20 3.1404050605605449 1.1876e-03 3.81 - 80 3.1415157631807009 7.6890e-05 3.95 - 320 3.1415878042798613 4.8493e-06 3.99 - 1280 3.1415923498174529 3.0377e-07 4.00 - 5120 3.1415926345931995 1.8997e-08 4.00 + 5 3.1248930668550590 1.6700e-02 - + 20 3.1404050605605454 1.1876e-03 3.81 + 80 3.1415157631807005 7.6890e-05 3.95 + 320 3.1415878042798600 4.8493e-06 3.99 + 1280 3.1415923498174543 3.0377e-07 4.00 + 5120 3.1415926345931982 1.8997e-08 4.00 Degree = 3 cells eval.pi error - 5 3.1414940401456048 9.8613e-05 - + 5 3.1414940401456053 9.8613e-05 - 20 3.1415913432549156 1.3103e-06 6.23 - 80 3.1415926341726910 1.9417e-08 6.08 - 320 3.1415926532906897 2.9910e-10 6.02 - 1280 3.1415926535851364 4.6570e-12 6.01 - 5120 3.1415926535897190 7.4157e-14 5.97 + 80 3.1415926341726905 1.9417e-08 6.08 + 320 3.1415926532906924 2.9910e-10 6.02 + 1280 3.1415926535851346 4.6585e-12 6.00 + 5120 3.1415926535897158 7.7272e-14 5.91 Degree = 4 cells eval.pi error - 5 3.1415921029432572 5.5065e-07 - - 20 3.1415926513737595 2.2160e-09 7.96 - 80 3.1415926535810703 8.7230e-12 7.99 - 320 3.1415926535897576 3.5705e-14 7.93 - 1280 3.1415926535897918 1.3785e-15 4.70 - 5120 3.1415926535897944 1.3798e-15 -0.00 -@endcode + 5 3.1415921029432572 5.5065e-07 - + 20 3.1415926513737582 2.2160e-09 7.96 + 80 3.1415926535810699 8.7232e-12 7.99 + 320 3.1415926535897576 3.5527e-14 7.94 + 1280 3.1415926535897896 3.5527e-15 3.32 + 5120 3.1415926535897940 8.8818e-16 2.00 + @endcode @note Once the error reaches a level on the - order of $10^{-14}$ or $10^{-15}$, it is essentially dominated by + order of $10^{-13}$ to $10^{-15}$, it is essentially dominated by round-off and consequently dominated by what precisely the library is doing in internal computations. Since these things change, the precise values and errors change from release to release at these round-off levels, diff --git a/examples/step-10/step-10.cc b/examples/step-10/step-10.cc index 71fa00ba45..88bb451ee3 100644 --- a/examples/step-10/step-10.cc +++ b/examples/step-10/step-10.cc @@ -48,17 +48,6 @@ namespace Step10 { using namespace dealii; - // Now, as we want to compute the value of $\pi$, we have to compare to - // something. These are the first few digits of $\pi$, which we define - // beforehand for later use. Since we would like to compute the difference - // between two numbers which are quite accurate, with the accuracy of the - // computed approximation to $\pi$ being in the range of the number of - // digits which a double variable can hold, we rather declare the reference - // value as a long double and give it a number of extra digits: - const long double pi = 3.141592653589793238462643L; - - - // Then, the first task will be to generate some output. Since this program // is so small, we do not employ object oriented techniques in it and do not // declare classes (although, of course, we use the object oriented features @@ -258,31 +247,21 @@ namespace Step10 // function below. dof_handler.distribute_dofs(fe); - // We define the variable area as `long double` like we did for - // the `pi` variable before. - long double area = 0; - // Now we loop over all cells, reinitialize the FEValues object // for each cell, and add up all the `JxW` values for this cell to // `area`... + double area = 0; for (const auto &cell : dof_handler.active_cell_iterators()) { fe_values.reinit(cell); for (unsigned int i = 0; i < fe_values.n_quadrature_points; ++i) - area += static_cast(fe_values.JxW(i)); + area += fe_values.JxW(i); } // ...and store the resulting area values and the errors in the - // table. We need a static cast to double as there is no - // add_value(string, long double) function implemented. Note that - // this also concerns the second call as the fabs - // function in the std namespace is overloaded on its - // argument types, so there exists a version taking and returning - // a long double, in contrast to the global namespace - // where only one such function is declared (which takes and - // returns a double). - table.add_value("eval.pi", static_cast(area)); - table.add_value("error", static_cast(std::fabs(area - pi))); + // table: + table.add_value("eval.pi", area); + table.add_value("error", std::fabs(area - numbers::PI)); } // We want to compute the convergence rates of the `error` @@ -354,8 +333,8 @@ namespace Step10 // Now we run over all cells and over all faces of each cell. Only // the contributions of the `JxW` values on boundary faces are - // added to the long double variable `perimeter`. - long double perimeter = 0; + // added to the variable `perimeter`. + double perimeter = 0; for (const auto &cell : dof_handler.active_cell_iterators()) for (const auto &face : cell->face_iterators()) if (face->at_boundary()) @@ -366,13 +345,13 @@ namespace Step10 for (unsigned int i = 0; i < fe_face_values.n_quadrature_points; ++i) - perimeter += - static_cast(fe_face_values.JxW(i)); + perimeter += fe_face_values.JxW(i); } // Then store the evaluated values in the table... - table.add_value("eval.pi", static_cast(perimeter / 2.0L)); - table.add_value( - "error", static_cast(std::fabs(perimeter / 2.0L - pi))); + table.add_value("eval.pi", static_cast(perimeter / 2.0)); + table.add_value("error", + static_cast( + std::fabs(perimeter / 2.0 - numbers::PI))); } // ...and end this function as we did in the previous one: -- 2.39.5