From 4743b09e0c8e1a1b3a41233e399a11c2e95c3920 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Sun, 12 Mar 2017 19:58:57 +0100 Subject: [PATCH] Substitute multiplications by 2 by additions (strength reduction). --- include/deal.II/base/symmetric_tensor.h | 37 ++++++++++++++++--------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/include/deal.II/base/symmetric_tensor.h b/include/deal.II/base/symmetric_tensor.h index b4a3d9f038..f83ff04cab 100644 --- a/include/deal.II/base/symmetric_tensor.h +++ b/include/deal.II/base/symmetric_tensor.h @@ -1215,17 +1215,15 @@ namespace internal { case 1: return data[0] * sdata[0]; - case 2: - return (data[0] * sdata[0] + - data[1] * sdata[1] + - NumberType::value(2.0) * data[2] * sdata[2]); default: // Start with the non-diagonal part to avoid some multiplications by // 2. Number sum = data[dim] * sdata[dim]; for (unsigned int d=dim+1; d<(dim*(dim+1)/2); ++d) sum += data[d] * sdata[d]; - sum *= NumberType::value(2.0); + sum += sum; // sum = sum * 2.; + + // Now add the contributions from the diagonal for (unsigned int d=0; d::base_tensor_type tmp; for (unsigned int i=0; i &t) case 2: return (t.data[0] * t.data[1] - t.data[2]*t.data[2]); case 3: + { // in analogy to general tensors, but // there's something to be simplified for // the present case - return ( t.data[0]*t.data[1]*t.data[2] + const Number tmp = t.data[3]*t.data[4]*t.data[5]; + return ( tmp + tmp + +t.data[0]*t.data[1]*t.data[2] -t.data[0]*t.data[5]*t.data[5] -t.data[1]*t.data[4]*t.data[4] - -t.data[2]*t.data[3]*t.data[3] - +internal::NumberType::value(2.0) * t.data[3]*t.data[4]*t.data[5] ); + -t.data[2]*t.data[3]*t.data[3]); + } default: Assert (false, ExcNotImplemented()); return 0; -- 2.39.5