From 4100bd1f1714732c54135587ada196fa2dee1fa3 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de>
Date: Thu, 30 Mar 2023 15:22:12 +0200
Subject: [PATCH] SpecularComputation now a namespace

---
 Sim/Computation/SpecularComputation.cpp | 21 ++++++---------------
 Sim/Computation/SpecularComputation.h   | 24 +++++-------------------
 Sim/Simulation/SpecularSimulation.cpp   |  3 +--
 3 files changed, 12 insertions(+), 36 deletions(-)

diff --git a/Sim/Computation/SpecularComputation.cpp b/Sim/Computation/SpecularComputation.cpp
index 563cacac62a..0e733c660bb 100644
--- a/Sim/Computation/SpecularComputation.cpp
+++ b/Sim/Computation/SpecularComputation.cpp
@@ -20,29 +20,20 @@
 #include "Resample/Specular/ComputeFluxMagnetic.h"
 #include "Resample/Specular/ComputeFluxScalar.h"
 
-SpecularComputation::SpecularComputation(const ReSample& re_sample,
-                                         const SimulationOptions& options,
-                                         ProgressHandler& progress)
-    : m_re_sample(std::move(re_sample))
-    , m_options(options)
-    , m_progress(progress)
-{
-}
-
-SpecularComputation::~SpecularComputation() = default;
-
 //! Performs the actual simulation, and sets intensity, for given range of SpecularElement%s.
-double SpecularComputation::simulatedIntensity(SpecularElement& ele)
+double SpecularComputation::simulatedIntensity(const ReSample& re_sample,
+                                               ProgressHandler& progress,
+                                               SpecularElement& ele)
 {
     if (!ele.isCalculated())
         return 0;
 
-    const SliceStack& slices = m_re_sample.averageSlices();
+    const SliceStack& slices = re_sample.averageSlices();
     std::vector<complex_t> kz_stack = ele.produceKz(slices);
 
     double refl;
 
-    if (m_re_sample.polarizing()) {
+    if (re_sample.polarizing()) {
         const SpinMatrix R = Compute::SpecularMagnetic::topLayerR(slices, kz_stack, true);
 
         const SpinMatrix& polMatrix = ele.polarizer();
@@ -58,7 +49,7 @@ double SpecularComputation::simulatedIntensity(SpecularElement& ele)
         refl = std::norm(R);
     }
 
-    m_progress.incrementDone(1);
+    progress.incrementDone(1);
 
     return ele.footprint() * refl;
 }
diff --git a/Sim/Computation/SpecularComputation.h b/Sim/Computation/SpecularComputation.h
index ab1b95eeab0..f61d675e603 100644
--- a/Sim/Computation/SpecularComputation.h
+++ b/Sim/Computation/SpecularComputation.h
@@ -18,31 +18,17 @@
 #ifndef BORNAGAIN_SIM_COMPUTATION_SPECULARCOMPUTATION_H
 #define BORNAGAIN_SIM_COMPUTATION_SPECULARCOMPUTATION_H
 
-#include <vector>
-
 class ProgressHandler;
 class ReSample;
-class SimulationOptions;
 class SpecularElement;
 
-//! Performs a single-threaded specular computation with given sample.
-//!
-//! Controlled by the multi-threading machinery in ISimulation::runSingleSimulation().
-
-class SpecularComputation {
-public:
-    SpecularComputation(const ReSample& re_sample, const SimulationOptions& options,
-                        ProgressHandler& progress);
-    ~SpecularComputation();
+//! Returns reflected intensity.
 
-    double simulatedIntensity(SpecularElement& ele);
+namespace SpecularComputation {
 
-private:
-    void stepProgress() const;
+double simulatedIntensity(const ReSample& re_sample, ProgressHandler& progress,
+                          SpecularElement& ele);
 
-    const ReSample& m_re_sample;
-    const SimulationOptions& m_options;
-    ProgressHandler& m_progress;
-};
+} // namespace SpecularComputation
 
 #endif // BORNAGAIN_SIM_COMPUTATION_SPECULARCOMPUTATION_H
diff --git a/Sim/Simulation/SpecularSimulation.cpp b/Sim/Simulation/SpecularSimulation.cpp
index 78a96db1461..c3e96193f42 100644
--- a/Sim/Simulation/SpecularSimulation.cpp
+++ b/Sim/Simulation/SpecularSimulation.cpp
@@ -53,8 +53,7 @@ void SpecularSimulation::initElementVector()
 void SpecularSimulation::runComputation(const ReSample& re_sample, size_t iElement, double weight)
 {
     SpecularElement& ele = *(m_eles.begin() + static_cast<long>(iElement));
-    double intensity =
-        SpecularComputation(re_sample, options(), progress()).simulatedIntensity(ele);
+    double intensity = SpecularComputation::simulatedIntensity(re_sample, progress(), ele);
 
     if (background())
         intensity = background()->addBackground(intensity);
-- 
GitLab