From 870db3947d8d5c8f506be68d96fcf6e9683cdf5a Mon Sep 17 00:00:00 2001 From: Elias Pipping <elias.pipping@fu-berlin.de> Date: Mon, 31 Oct 2011 16:23:43 +0100 Subject: [PATCH] Use references --- src/samplefunctional.hh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/samplefunctional.hh b/src/samplefunctional.hh index 7504cb80..a6a2d553 100644 --- a/src/samplefunctional.hh +++ b/src/samplefunctional.hh @@ -78,7 +78,7 @@ template <int dim> class SampleFunctional { // points in direction -x. The projection will then be zero. SmallVector d; smoothGradient(x, d); - ret = negative_projection(d, x); + negative_projection(d, x, ret); dverb << "## Directional derivative (as per scalar product w/ " "semigradient): " << -(ret * ret) << " (coordinates of the restriction)" << std::endl; @@ -111,12 +111,13 @@ template <int dim> class SampleFunctional { y += z; } - // No normalising is done! - SmallVector negative_projection(SmallVector const z, - SmallVector const x) const { - SmallVector y = z; - y.axpy(-(z * x) / x.two_norm2(), x); - return y; + // y = (id - P)(d) where P is the projection onto the line t*x + void negative_projection(SmallVector const &d, SmallVector const &x, + SmallVector &y) const { + double const dx = d * x; + double const xx = x.two_norm2(); + y = d; + y.axpy(-dx / xx, x); } }; -- GitLab