From 3f403829605f4ede11859538ba66de87fc00d6a5 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 26 Aug 2019 19:33:28 -0600 Subject: [PATCH] Simplify and clarify the use of std::complex in DataPostprocessor. --- examples/step-29/step-29.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) 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); } } -- 2.39.5