From: Wolfgang Bangerth Date: Tue, 27 Aug 2019 01:33:28 +0000 (-0600) Subject: Simplify and clarify the use of std::complex in DataPostprocessor. X-Git-Tag: v9.2.0-rc1~1168^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f403829605f4ede11859538ba66de87fc00d6a5;p=dealii.git Simplify and clarify the use of std::complex in DataPostprocessor. --- diff --git a/examples/step-29/step-29.cc b/examples/step-29/step-29.cc index 7448575008..2cbc7efc06 100644 --- a/examples/step-29/step-29.cc +++ b/examples/step-29/step-29.cc @@ -333,9 +333,15 @@ namespace Step29 ExcDimensionMismatch(computed_quantities.size(), inputs.solution_values.size())); - // The computation itself is straightforward: We iterate over each entry - // in the output vector and compute $|u|$ from the corresponding values of - // $v$ and $w$: + // The computation itself is straightforward: We iterate over each + // entry in the output vector and compute $|u|$ from the + // corresponding values of $v$ and $w$. We do this by creating a + // complex number $u$ and then calling `std::abs()` on the + // result. (One may be tempted to call `std::norm()`, but in a + // historical quirk, the C++ committee decided that `std::norm()` + // should return the square of the absolute value -- + // thereby not satisfying the properties mathematicians require of + // something called a "norm".) for (unsigned int i = 0; i < computed_quantities.size(); i++) { Assert(computed_quantities[i].size() == 1, @@ -343,9 +349,10 @@ namespace Step29 Assert(inputs.solution_values[i].size() == 2, ExcDimensionMismatch(inputs.solution_values[i].size(), 2)); - computed_quantities[i](0) = std::sqrt( - inputs.solution_values[i](0) * inputs.solution_values[i](0) + - inputs.solution_values[i](1) * inputs.solution_values[i](1)); + const std::complex u(inputs.solution_values[i](0), + inputs.solution_values[i](1)); + + computed_quantities[i](0) = std::abs(u); } }