From f69bf4c7d3a9538c7b9a36f5f8d9996fe12cd25a Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de>
Date: Mon, 5 Sep 2022 17:51:29 +0200
Subject: [PATCH] Decoupling Approximation: more compact notation for
 scalarCalculation

---
 .../Interparticle/DecouplingApproximationStrategy.cpp    | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/Resample/Interparticle/DecouplingApproximationStrategy.cpp b/Resample/Interparticle/DecouplingApproximationStrategy.cpp
index 2039518c184..bb06120604b 100644
--- a/Resample/Interparticle/DecouplingApproximationStrategy.cpp
+++ b/Resample/Interparticle/DecouplingApproximationStrategy.cpp
@@ -33,7 +33,7 @@ DecouplingApproximationStrategy::DecouplingApproximationStrategy(
 double DecouplingApproximationStrategy::scalarCalculation(const DiffuseElement& ele) const
 {
     double intensity = 0.0;
-    complex_t amplitude = complex_t(0.0, 0.0);
+    complex_t amplitude = 0;
     for (const auto& ffw : m_weighted_formfactors) {
         const complex_t ff = ffw->summedFF(ele);
         if (std::isnan(ff.real()))
@@ -43,9 +43,7 @@ double DecouplingApproximationStrategy::scalarCalculation(const DiffuseElement&
         amplitude += fraction * ff;
         intensity += fraction * std::norm(ff);
     }
-    const double amplitude_norm = std::norm(amplitude); // squared magnitude
-    const double coherence_factor = m_iff->structureFactor(ele.meanQ());
-    return intensity + amplitude_norm * (coherence_factor - 1.0);
+    return intensity + (m_iff->structureFactor(ele.meanQ()) - 1) * std::norm(amplitude);
 }
 
 //! This is the polarized version
@@ -70,6 +68,5 @@ double DecouplingApproximationStrategy::polarizedCalculation(const DiffuseElemen
     const SpinMatrix intensity_matrix = polarization_handler.analyzerMatrix() * mean_intensity;
     const double amplitude_trace = std::abs(amplitude_matrix.trace());
     const double intensity_trace = std::abs(intensity_matrix.trace());
-    const double coherence_factor = m_iff->structureFactor(ele.meanQ());
-    return intensity_trace + amplitude_trace * (coherence_factor - 1.0);
+    return intensity_trace + (m_iff->structureFactor(ele.meanQ()) - 1) * amplitude_trace;
 }
-- 
GitLab