From f9c9e2649bbb51fa8bdf8e2024af8e68e2dced7d Mon Sep 17 00:00:00 2001 From: Oliver Sander <oliver.sander@tu-dresden.de> Date: Thu, 3 Jan 2019 14:18:11 +0100 Subject: [PATCH] Move norm computation out of a loop --- dune/gfe/unitvector.hh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dune/gfe/unitvector.hh b/dune/gfe/unitvector.hh index a1145af4..73418848 100644 --- a/dune/gfe/unitvector.hh +++ b/dune/gfe/unitvector.hh @@ -413,10 +413,13 @@ public: static DerivativeOfProjection derivativeOfProjection(const Dune::FieldVector<T,N>& p) { + auto normSquared = p.two_norm2(); + auto norm = std::sqrt(normSquared); + Dune::FieldMatrix<T,N,N> result; for (int i=0; i<N; i++) for (int j=0; j<N; j++) - result[i][j] = ( (i==j) - p[i]*p[j] / p.two_norm2() ) / p.two_norm(); + result[i][j] = ( (i==j) - p[i]*p[j] / normSquared ) / norm; return result; } -- GitLab