From b69d4545815e6f7c517d3d8ae7bec7283f78add5 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Thu, 8 Jul 2021 11:37:47 +0200
Subject: [PATCH 01/13] disambiguate member vars

---
 Resample/Coherence/FFTerm.cpp                | 15 ++++++++-------
 Resample/Coherence/FFTerm.h                  |  2 +-
 Resample/Flux/ScalarFlux.cpp                 |  4 +++-
 Resample/Specular/SpecularScalarStrategy.cpp |  5 ++---
 4 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/Resample/Coherence/FFTerm.cpp b/Resample/Coherence/FFTerm.cpp
index d00be6a365f..bfcd8513250 100644
--- a/Resample/Coherence/FFTerm.cpp
+++ b/Resample/Coherence/FFTerm.cpp
@@ -21,12 +21,13 @@
 #include "Sample/Material/WavevectorInfo.h"
 
 CoherentFFTerm::CoherentFFTerm(IComputeFF* ff, size_t layer_index)
-    : m_ff(ff), m_layer_index(layer_index)
+    : m_computer(ff), m_layer_index(layer_index)
 {
 }
 
 CoherentFFTerm::CoherentFFTerm(const CoherentFFTerm& other)
-    : m_ff(std::unique_ptr<IComputeFF>(other.m_ff->clone())), m_layer_index(other.m_layer_index)
+    : m_computer(std::unique_ptr<IComputeFF>(other.m_computer->clone()))
+    , m_layer_index(other.m_layer_index)
 {
 }
 
@@ -38,8 +39,8 @@ complex_t CoherentFFTerm::coherentFF(const SimulationElement& ele) const
     ASSERT(fresnel_map);
     auto inFlux = fresnel_map->getInFlux(ele.getKi(), m_layer_index);
     auto outFlux = fresnel_map->getOutFlux(ele.getMeanKf(), m_layer_index);
-    m_ff->setFlux(std::move(inFlux), std::move(outFlux));
-    return m_ff->computeFF({ele});
+    m_computer->setFlux(std::move(inFlux), std::move(outFlux));
+    return m_computer->computeFF({ele});
 }
 
 Eigen::Matrix2cd CoherentFFTerm::coherentPolFF(const SimulationElement& ele) const
@@ -48,11 +49,11 @@ Eigen::Matrix2cd CoherentFFTerm::coherentPolFF(const SimulationElement& ele) con
     ASSERT(fresnel_map);
     auto inFlux = fresnel_map->getInFlux(ele.getKi(), m_layer_index);
     auto outFlux = fresnel_map->getOutFlux(ele.getMeanKf(), m_layer_index);
-    m_ff->setFlux(std::move(inFlux), std::move(outFlux));
-    return m_ff->computePolFF({ele});
+    m_computer->setFlux(std::move(inFlux), std::move(outFlux));
+    return m_computer->computePolFF({ele});
 }
 
 double CoherentFFTerm::radialExtension() const
 {
-    return m_ff->radialExtension();
+    return m_computer->radialExtension();
 }
diff --git a/Resample/Coherence/FFTerm.h b/Resample/Coherence/FFTerm.h
index e4fe49bd313..404f9add451 100644
--- a/Resample/Coherence/FFTerm.h
+++ b/Resample/Coherence/FFTerm.h
@@ -43,7 +43,7 @@ public:
     double radialExtension() const;
 
 private:
-    const std::unique_ptr<IComputeFF> m_ff;
+    const std::unique_ptr<IComputeFF> m_computer;
     const size_t m_layer_index;
 };
 
diff --git a/Resample/Flux/ScalarFlux.cpp b/Resample/Flux/ScalarFlux.cpp
index b5ea913e7d9..82cc50995b5 100644
--- a/Resample/Flux/ScalarFlux.cpp
+++ b/Resample/Flux/ScalarFlux.cpp
@@ -15,7 +15,9 @@
 #include "Resample/Flux/ScalarFlux.h"
 
 ScalarFlux::ScalarFlux(complex_t kz, Eigen::Vector2cd TR)
-    : m_kz(kz), m_TR(TR), m_plus(1, 0), m_min(0, 1) {}
+    : m_kz(kz), m_TR(TR), m_plus(1, 0), m_min(0, 1)
+{
+}
 
 ScalarFlux* ScalarFlux::clone() const
 {
diff --git a/Resample/Specular/SpecularScalarStrategy.cpp b/Resample/Specular/SpecularScalarStrategy.cpp
index 7f2f0a53071..ad3a88a62c2 100644
--- a/Resample/Specular/SpecularScalarStrategy.cpp
+++ b/Resample/Specular/SpecularScalarStrategy.cpp
@@ -49,7 +49,7 @@ ISpecularStrategy::coeffs_t SpecularScalarStrategy::Execute(const SliceStack& sl
     const std::vector<Eigen::Vector2cd> TR = computeTR(slices, kz);
 
     ISpecularStrategy::coeffs_t result;
-    for (size_t i = 0; i <  kz.size(); ++i)
+    for (size_t i = 0; i < kz.size(); ++i)
         result.emplace_back(std::make_unique<ScalarFlux>(kz[i], TR[i]));
     return result;
 }
@@ -88,8 +88,7 @@ SpecularScalarStrategy::computeTopLayerR(const SliceStack& slices,
 }
 
 std::vector<Eigen::Vector2cd>
-SpecularScalarStrategy::computeTR(const SliceStack& slices,
-                                  const std::vector<complex_t>& kz) const
+SpecularScalarStrategy::computeTR(const SliceStack& slices, const std::vector<complex_t>& kz) const
 {
     const size_t N = slices.size();
     std::vector<Eigen::Vector2cd> TR(N, {1., 0.});
-- 
GitLab


From 123937c061042aa82e59dc30203c7610f0e6fe00 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Thu, 8 Jul 2021 12:06:05 +0200
Subject: [PATCH 02/13] improve errmsg

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

diff --git a/Resample/Interparticle/DecouplingApproximationStrategy.cpp b/Resample/Interparticle/DecouplingApproximationStrategy.cpp
index 9bce8600860..2bfd4979f94 100644
--- a/Resample/Interparticle/DecouplingApproximationStrategy.cpp
+++ b/Resample/Interparticle/DecouplingApproximationStrategy.cpp
@@ -39,7 +39,7 @@ DecouplingApproximationStrategy::scalarCalculation(const SimulationElement& sim_
         const complex_t ff = ffw.summedFF(sim_element);
         if (std::isnan(ff.real()))
             throw std::runtime_error(
-                "DecouplingApproximationStrategy::scalarCalculation() -> Error! Amplitude is NaN");
+                "numerical error in coherent sum (scalar, DA): amplitude is NaN");
         double fraction = ffw.relativeAbundance();
         amplitude += fraction * ff;
         intensity += fraction * std::norm(ff);
@@ -60,8 +60,8 @@ DecouplingApproximationStrategy::polarizedCalculation(const SimulationElement& s
     for (const auto& ffw : m_weighted_formfactors) {
         const Eigen::Matrix2cd ff = ffw.summedPolFF(sim_element);
         if (!ff.allFinite())
-            throw std::runtime_error("DecouplingApproximationStrategy::polarizedCalculation() -> "
-                                     "Error! Form factor contains NaN or infinite");
+            throw std::runtime_error(
+                "numerical error in coherent sum (polarized, DA): amplitude is NaN");
         const double fraction = ffw.relativeAbundance();
         mean_amplitude += fraction * ff;
         mean_intensity += fraction * (ff * polarization_handler.getPolarization() * ff.adjoint());
-- 
GitLab


From b98582a7998661a88cd103a674d469bdc0a13ebb Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Thu, 8 Jul 2021 12:07:18 +0200
Subject: [PATCH 03/13] rename local var

---
 Resample/Processed/ProcessedLayout.cpp | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/Resample/Processed/ProcessedLayout.cpp b/Resample/Processed/ProcessedLayout.cpp
index 190a266f323..81cb12bffec 100644
--- a/Resample/Processed/ProcessedLayout.cpp
+++ b/Resample/Processed/ProcessedLayout.cpp
@@ -105,25 +105,25 @@ CoherentFFSum ProcessedLayout::processParticle(const IParticle& particle, const
     std::vector<CoherentFFTerm> coherentParts;
     for (size_t i = 0; i < sliced_ffs.size(); ++i) { // TODO provide slices_ffs.cbegin() etc
         const auto ff_pair = sliced_ffs[i];
-        std::unique_ptr<IComputeFF> ff_framework;
+        std::unique_ptr<IComputeFF> computer;
         if (slices.size() > 1) {
             if (m_polarized)
-                ff_framework = std::make_unique<ComputeDWBAPol>(*ff_pair.first);
+                computer = std::make_unique<ComputeDWBAPol>(*ff_pair.first);
             else
-                ff_framework = std::make_unique<ComputeDWBA>(*ff_pair.first);
+                computer = std::make_unique<ComputeDWBA>(*ff_pair.first);
         } else {
             // no need for DWBA, use BA
             if (m_polarized)
-                ff_framework = std::make_unique<ComputeBAPol>(*ff_pair.first);
+                computer = std::make_unique<ComputeBAPol>(*ff_pair.first);
             else
-                ff_framework = std::make_unique<ComputeBA>(*ff_pair.first);
+                computer = std::make_unique<ComputeBA>(*ff_pair.first);
         }
 
         const size_t slice_index = ff_pair.second;
         const Material& slice_material = slices[slice_index].material();
-        ff_framework->setAmbientMaterial(slice_material);
+        computer->setAmbientMaterial(slice_material);
 
-        coherentParts.emplace_back(CoherentFFTerm(ff_framework.release(), slice_index));
+        coherentParts.emplace_back(CoherentFFTerm(computer.release(), slice_index));
     }
     return CoherentFFSum(abundance, coherentParts);
 }
-- 
GitLab


From ccb4f93294357d2663e2d750476a49a00b5fe9b3 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Thu, 8 Jul 2021 12:08:07 +0200
Subject: [PATCH 04/13] rename local var

---
 Resample/Processed/ProcessedLayout.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Resample/Processed/ProcessedLayout.cpp b/Resample/Processed/ProcessedLayout.cpp
index 81cb12bffec..332859e7e21 100644
--- a/Resample/Processed/ProcessedLayout.cpp
+++ b/Resample/Processed/ProcessedLayout.cpp
@@ -102,7 +102,7 @@ CoherentFFSum ProcessedLayout::processParticle(const IParticle& particle, const
                                          regions.end());
     }
 
-    std::vector<CoherentFFTerm> coherentParts;
+    std::vector<CoherentFFTerm> terms;
     for (size_t i = 0; i < sliced_ffs.size(); ++i) { // TODO provide slices_ffs.cbegin() etc
         const auto ff_pair = sliced_ffs[i];
         std::unique_ptr<IComputeFF> computer;
@@ -123,7 +123,7 @@ CoherentFFSum ProcessedLayout::processParticle(const IParticle& particle, const
         const Material& slice_material = slices[slice_index].material();
         computer->setAmbientMaterial(slice_material);
 
-        coherentParts.emplace_back(CoherentFFTerm(computer.release(), slice_index));
+        terms.emplace_back(CoherentFFTerm(computer.release(), slice_index));
     }
-    return CoherentFFSum(abundance, coherentParts);
+    return CoherentFFSum(abundance, terms);
 }
-- 
GitLab


From 4fcb234d49f6c1f2ba7c54e0f056a057b5ff9aa1 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Thu, 8 Jul 2021 12:14:35 +0200
Subject: [PATCH 05/13] rm unused

---
 Sample/Material/MaterialFactoryFuncs.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/Sample/Material/MaterialFactoryFuncs.h b/Sample/Material/MaterialFactoryFuncs.h
index 7a1f875437b..599ca90806e 100644
--- a/Sample/Material/MaterialFactoryFuncs.h
+++ b/Sample/Material/MaterialFactoryFuncs.h
@@ -17,8 +17,6 @@
 
 #include "Sample/Material/Material.h"
 
-struct HomogeneousRegion;
-
 //! @ingroup materials
 
 Material HomogeneousMaterial();
-- 
GitLab


From 9e6f4981925751da99bfbfee9bddf41705eba23f Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Thu, 8 Jul 2021 12:19:45 +0200
Subject: [PATCH 06/13] rename local var

---
 Resample/Coherence/FFSum.cpp | 10 +++++-----
 Resample/Coherence/FFSum.h   |  4 ++--
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/Resample/Coherence/FFSum.cpp b/Resample/Coherence/FFSum.cpp
index 76c04b791c8..e6b798aa0bd 100644
--- a/Resample/Coherence/FFSum.cpp
+++ b/Resample/Coherence/FFSum.cpp
@@ -14,15 +14,15 @@
 
 #include "Resample/Coherence/FFSum.h"
 
-CoherentFFSum::CoherentFFSum(double abundance, const std::vector<CoherentFFTerm>& parts)
-    : m_abundance(abundance), m_parts(parts)
+CoherentFFSum::CoherentFFSum(double abundance, const std::vector<CoherentFFTerm>& terms)
+    : m_abundance(abundance), m_terms(terms)
 {
 }
 
 complex_t CoherentFFSum::summedFF(const SimulationElement& sim_element) const
 {
     complex_t result = 0.;
-    for (const auto& part : m_parts)
+    for (const auto& part : m_terms)
         result += part.coherentFF(sim_element);
     return result;
 }
@@ -30,7 +30,7 @@ complex_t CoherentFFSum::summedFF(const SimulationElement& sim_element) const
 Eigen::Matrix2cd CoherentFFSum::summedPolFF(const SimulationElement& sim_element) const
 {
     Eigen::Matrix2cd result = Eigen::Matrix2cd::Zero();
-    for (const auto& part : m_parts)
+    for (const auto& part : m_terms)
         result += part.coherentPolFF(sim_element);
     return result;
 }
@@ -44,5 +44,5 @@ void CoherentFFSum::scaleRelativeAbundance(double total_abundance)
 
 double CoherentFFSum::radialExtension() const
 {
-    return m_parts[0].radialExtension();
+    return m_terms[0].radialExtension();
 }
diff --git a/Resample/Coherence/FFSum.h b/Resample/Coherence/FFSum.h
index e4aac16925e..c882b7e72bb 100644
--- a/Resample/Coherence/FFSum.h
+++ b/Resample/Coherence/FFSum.h
@@ -30,7 +30,7 @@ class SimulationElement;
 
 class CoherentFFSum {
 public:
-    CoherentFFSum(double abundance, const std::vector<CoherentFFTerm>& parts);
+    CoherentFFSum(double abundance, const std::vector<CoherentFFTerm>& terms);
 
     complex_t summedFF(const SimulationElement& sim_element) const;
     Eigen::Matrix2cd summedPolFF(const SimulationElement& sim_element) const;
@@ -41,7 +41,7 @@ public:
 
 private:
     double m_abundance;
-    const std::vector<CoherentFFTerm> m_parts;
+    const std::vector<CoherentFFTerm> m_terms;
 };
 
 #endif // BORNAGAIN_RESAMPLE_COHERENCE_FFSUM_H
-- 
GitLab


From 85ba5e1fc2d68b8a2217b6b8b5de8d0b9b094739 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Thu, 8 Jul 2021 12:44:40 +0200
Subject: [PATCH 07/13] rename local var

---
 Resample/Coherence/FFSum.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/Resample/Coherence/FFSum.cpp b/Resample/Coherence/FFSum.cpp
index e6b798aa0bd..58525a02a0b 100644
--- a/Resample/Coherence/FFSum.cpp
+++ b/Resample/Coherence/FFSum.cpp
@@ -22,16 +22,16 @@ CoherentFFSum::CoherentFFSum(double abundance, const std::vector<CoherentFFTerm>
 complex_t CoherentFFSum::summedFF(const SimulationElement& sim_element) const
 {
     complex_t result = 0.;
-    for (const auto& part : m_terms)
-        result += part.coherentFF(sim_element);
+    for (const auto& term : m_terms)
+        result += term.coherentFF(sim_element);
     return result;
 }
 
 Eigen::Matrix2cd CoherentFFSum::summedPolFF(const SimulationElement& sim_element) const
 {
     Eigen::Matrix2cd result = Eigen::Matrix2cd::Zero();
-    for (const auto& part : m_terms)
-        result += part.coherentPolFF(sim_element);
+    for (const auto& term : m_terms)
+        result += term.coherentPolFF(sim_element);
     return result;
 }
 
-- 
GitLab


From 1264de8f621ce649bca8953aeea972c3088632a8 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Thu, 8 Jul 2021 13:55:14 +0200
Subject: [PATCH 08/13] replace counterintuitive operator[]

---
 Resample/Coherence/FFTerm.cpp           | 4 ++--
 Resample/Coherence/FFTerm.h             | 2 +-
 Resample/Processed/ProcessedLayout.cpp  | 2 +-
 Resample/Slice/SlicedFormFactorList.cpp | 5 +++--
 Resample/Slice/SlicedFormFactorList.h   | 2 +-
 5 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/Resample/Coherence/FFTerm.cpp b/Resample/Coherence/FFTerm.cpp
index bfcd8513250..8d447ccfacd 100644
--- a/Resample/Coherence/FFTerm.cpp
+++ b/Resample/Coherence/FFTerm.cpp
@@ -20,8 +20,8 @@
 #include "Resample/Fresnel/IFresnelMap.h"
 #include "Sample/Material/WavevectorInfo.h"
 
-CoherentFFTerm::CoherentFFTerm(IComputeFF* ff, size_t layer_index)
-    : m_computer(ff), m_layer_index(layer_index)
+CoherentFFTerm::CoherentFFTerm(IComputeFF* computer, size_t layer_index)
+    : m_computer(computer), m_layer_index(layer_index)
 {
 }
 
diff --git a/Resample/Coherence/FFTerm.h b/Resample/Coherence/FFTerm.h
index 404f9add451..75cbd34970b 100644
--- a/Resample/Coherence/FFTerm.h
+++ b/Resample/Coherence/FFTerm.h
@@ -32,7 +32,7 @@ class SimulationElement;
 
 class CoherentFFTerm {
 public:
-    CoherentFFTerm(IComputeFF* ff, size_t layer_index);
+    CoherentFFTerm(IComputeFF* computer, size_t layer_index);
     CoherentFFTerm(const CoherentFFTerm& other);
     CoherentFFTerm& operator=(const CoherentFFTerm& other) = delete;
     ~CoherentFFTerm();
diff --git a/Resample/Processed/ProcessedLayout.cpp b/Resample/Processed/ProcessedLayout.cpp
index 332859e7e21..3d11b99cf33 100644
--- a/Resample/Processed/ProcessedLayout.cpp
+++ b/Resample/Processed/ProcessedLayout.cpp
@@ -104,7 +104,7 @@ CoherentFFSum ProcessedLayout::processParticle(const IParticle& particle, const
 
     std::vector<CoherentFFTerm> terms;
     for (size_t i = 0; i < sliced_ffs.size(); ++i) { // TODO provide slices_ffs.cbegin() etc
-        const auto ff_pair = sliced_ffs[i];
+        const auto ff_pair = sliced_ffs.getPair(i);
         std::unique_ptr<IComputeFF> computer;
         if (slices.size() > 1) {
             if (m_polarized)
diff --git a/Resample/Slice/SlicedFormFactorList.cpp b/Resample/Slice/SlicedFormFactorList.cpp
index ff255a792fa..fcabcc6669c 100644
--- a/Resample/Slice/SlicedFormFactorList.cpp
+++ b/Resample/Slice/SlicedFormFactorList.cpp
@@ -67,8 +67,9 @@ void ScaleRegions(std::vector<HomogeneousRegion>& regions, double factor)
 
 } // namespace
 
+
 //  ************************************************************************************************
-//  class SlicedFormFactorList
+//  class implementation
 //  ************************************************************************************************
 
 SlicedFormFactorList::SlicedFormFactorList(const IParticle& particle, const SliceStack& slices,
@@ -111,7 +112,7 @@ size_t SlicedFormFactorList::size() const
     return m_ff_list.size();
 }
 
-std::pair<const IFormFactor*, size_t> SlicedFormFactorList::operator[](size_t index) const
+std::pair<const IFormFactor*, size_t> SlicedFormFactorList::getPair(size_t index) const
 {
     if (index >= size())
         throw std::out_of_range("SlicedFormFactorList::operator[] error: "
diff --git a/Resample/Slice/SlicedFormFactorList.h b/Resample/Slice/SlicedFormFactorList.h
index faf7f483833..4f9b78be086 100644
--- a/Resample/Slice/SlicedFormFactorList.h
+++ b/Resample/Slice/SlicedFormFactorList.h
@@ -42,7 +42,7 @@ public:
 
     size_t size() const;
 
-    std::pair<const IFormFactor*, size_t> operator[](size_t index) const;
+    std::pair<const IFormFactor*, size_t> getPair(size_t index) const;
 
     const std::map<size_t, std::vector<HomogeneousRegion>>& regionMap() const;
 
-- 
GitLab


From 24516321f86eb1fb9945f0528de0a7b826bc1511 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Thu, 8 Jul 2021 14:21:14 +0200
Subject: [PATCH 09/13] mv member variable

---
 Core/Export/SampleToPython.cpp                | 12 +++++------
 GUI/Models/GUIDomainSampleVisitor.cpp         |  4 ++--
 Resample/Coherence/FFTerm.cpp                 | 15 ++++++-------
 Resample/Coherence/FFTerm.h                   |  3 +--
 Resample/FFCompute/ComputeBA.cpp              |  4 ++--
 Resample/FFCompute/ComputeBA.h                |  2 +-
 Resample/FFCompute/ComputeBAPol.cpp           |  4 ++--
 Resample/FFCompute/ComputeBAPol.h             |  2 +-
 Resample/FFCompute/ComputeDWBA.cpp            |  4 ++--
 Resample/FFCompute/ComputeDWBA.h              |  2 +-
 Resample/FFCompute/ComputeDWBAPol.cpp         |  7 +++++--
 Resample/FFCompute/ComputeDWBAPol.h           |  2 +-
 Resample/FFCompute/IComputeFF.cpp             |  3 ++-
 Resample/FFCompute/IComputeFF.h               |  5 ++++-
 Resample/Fresnel/IFresnelMap.h                |  4 ++--
 Resample/Fresnel/MatrixFresnelMap.cpp         | 14 ++++++-------
 Resample/Fresnel/MatrixFresnelMap.h           |  6 +++---
 Resample/Fresnel/ScalarFresnelMap.cpp         | 10 ++++-----
 Resample/Fresnel/ScalarFresnelMap.h           |  4 ++--
 Resample/Processed/ParticleRegions.cpp        | 12 +++++------
 Resample/Processed/ProcessedLayout.cpp        | 21 ++++++++++---------
 Sample/Multilayer/MultiLayer.cpp              |  4 ++--
 Sample/Multilayer/MultiLayer.h                |  2 +-
 .../Core/Sample/FormFactorCoherentSumTest.cpp |  2 +-
 mvvm/tests/testviewmodel/TestToyLayerItem.cpp | 16 +++++++-------
 .../testviewmodel/topitemsviewmodel.test.cpp  | 20 +++++++++---------
 26 files changed, 96 insertions(+), 88 deletions(-)

diff --git a/Core/Export/SampleToPython.cpp b/Core/Export/SampleToPython.cpp
index 7ac385260f4..607b37c131b 100644
--- a/Core/Export/SampleToPython.cpp
+++ b/Core/Export/SampleToPython.cpp
@@ -556,17 +556,17 @@ std::string SampleToPython::defineMultiLayers() const
         if (numberOfLayers) {
             result << indent() << key << ".addLayer(" << m_objs->obj2key(s->layer(0)) << ")\n";
 
-            size_t layerIndex = 1;
-            while (layerIndex != numberOfLayers) {
-                const LayerInterface* layerInterface = s->layerInterface(layerIndex - 1);
+            size_t iLayer = 1;
+            while (iLayer != numberOfLayers) {
+                const LayerInterface* layerInterface = s->layerInterface(iLayer - 1);
                 if (const LayerRoughness* rough = layerInterface->getRoughness())
                     result << indent() << key << ".addLayerWithTopRoughness("
-                           << m_objs->obj2key(s->layer(layerIndex)) << ", "
+                           << m_objs->obj2key(s->layer(iLayer)) << ", "
                            << m_objs->obj2key(rough) << ")\n";
                 else
                     result << indent() << key << ".addLayer("
-                           << m_objs->obj2key(s->layer(layerIndex)) << ")\n";
-                layerIndex++;
+                           << m_objs->obj2key(s->layer(iLayer)) << ")\n";
+                iLayer++;
             }
         }
         result << "\n" << indent() << "return " << key << "\n";
diff --git a/GUI/Models/GUIDomainSampleVisitor.cpp b/GUI/Models/GUIDomainSampleVisitor.cpp
index edaf34d5ce0..f01dd644c0e 100644
--- a/GUI/Models/GUIDomainSampleVisitor.cpp
+++ b/GUI/Models/GUIDomainSampleVisitor.cpp
@@ -109,9 +109,9 @@ void GUIDomainSampleVisitor::visit(const Layer* sample)
 
     const auto* multilayer = dynamic_cast<const MultiLayer*>(m_itemToSample[parent]);
     ASSERT(multilayer);
-    size_t layer_index = SampleUtils::Multilayer::IndexOfLayer(*multilayer, sample);
+    size_t iLayer = SampleUtils::Multilayer::IndexOfLayer(*multilayer, sample);
     const LayerInterface* top_interface =
-        layer_index == 0 ? nullptr : multilayer->layerInterface(layer_index - 1);
+        iLayer == 0 ? nullptr : multilayer->layerInterface(iLayer - 1);
 
     LayerItem* layer_item = m_sampleModel->insertItem<LayerItem>(parent);
     layer_item->setMaterial(createMaterialFromDomain(sample->material()));
diff --git a/Resample/Coherence/FFTerm.cpp b/Resample/Coherence/FFTerm.cpp
index 8d447ccfacd..628a1f0bd19 100644
--- a/Resample/Coherence/FFTerm.cpp
+++ b/Resample/Coherence/FFTerm.cpp
@@ -20,14 +20,13 @@
 #include "Resample/Fresnel/IFresnelMap.h"
 #include "Sample/Material/WavevectorInfo.h"
 
-CoherentFFTerm::CoherentFFTerm(IComputeFF* computer, size_t layer_index)
-    : m_computer(computer), m_layer_index(layer_index)
+CoherentFFTerm::CoherentFFTerm(IComputeFF* computer)
+    : m_computer(computer)
 {
 }
 
 CoherentFFTerm::CoherentFFTerm(const CoherentFFTerm& other)
     : m_computer(std::unique_ptr<IComputeFF>(other.m_computer->clone()))
-    , m_layer_index(other.m_layer_index)
 {
 }
 
@@ -37,8 +36,9 @@ complex_t CoherentFFTerm::coherentFF(const SimulationElement& ele) const
 {
     const IFresnelMap* const fresnel_map = ele.fresnelMap();
     ASSERT(fresnel_map);
-    auto inFlux = fresnel_map->getInFlux(ele.getKi(), m_layer_index);
-    auto outFlux = fresnel_map->getOutFlux(ele.getMeanKf(), m_layer_index);
+    const size_t iLayer = m_computer->iLayer();
+    auto inFlux = fresnel_map->getInFlux(ele.getKi(), iLayer);
+    auto outFlux = fresnel_map->getOutFlux(ele.getMeanKf(), iLayer);
     m_computer->setFlux(std::move(inFlux), std::move(outFlux));
     return m_computer->computeFF({ele});
 }
@@ -47,8 +47,9 @@ Eigen::Matrix2cd CoherentFFTerm::coherentPolFF(const SimulationElement& ele) con
 {
     const IFresnelMap* const fresnel_map = ele.fresnelMap();
     ASSERT(fresnel_map);
-    auto inFlux = fresnel_map->getInFlux(ele.getKi(), m_layer_index);
-    auto outFlux = fresnel_map->getOutFlux(ele.getMeanKf(), m_layer_index);
+    const size_t iLayer = m_computer->iLayer();
+    auto inFlux = fresnel_map->getInFlux(ele.getKi(), iLayer);
+    auto outFlux = fresnel_map->getOutFlux(ele.getMeanKf(), iLayer);
     m_computer->setFlux(std::move(inFlux), std::move(outFlux));
     return m_computer->computePolFF({ele});
 }
diff --git a/Resample/Coherence/FFTerm.h b/Resample/Coherence/FFTerm.h
index 75cbd34970b..7d6e3770eea 100644
--- a/Resample/Coherence/FFTerm.h
+++ b/Resample/Coherence/FFTerm.h
@@ -32,7 +32,7 @@ class SimulationElement;
 
 class CoherentFFTerm {
 public:
-    CoherentFFTerm(IComputeFF* computer, size_t layer_index);
+    CoherentFFTerm(IComputeFF* computer);
     CoherentFFTerm(const CoherentFFTerm& other);
     CoherentFFTerm& operator=(const CoherentFFTerm& other) = delete;
     ~CoherentFFTerm();
@@ -44,7 +44,6 @@ public:
 
 private:
     const std::unique_ptr<IComputeFF> m_computer;
-    const size_t m_layer_index;
 };
 
 #endif // BORNAGAIN_RESAMPLE_COHERENCE_FFTERM_H
diff --git a/Resample/FFCompute/ComputeBA.cpp b/Resample/FFCompute/ComputeBA.cpp
index 507049659b4..028b556ebdd 100644
--- a/Resample/FFCompute/ComputeBA.cpp
+++ b/Resample/FFCompute/ComputeBA.cpp
@@ -16,13 +16,13 @@
 #include "Sample/Material/WavevectorInfo.h"
 #include "Sample/Scattering/IFormFactor.h"
 
-ComputeBA::ComputeBA(const IFormFactor& ff) : IComputeFF(ff) {}
+ComputeBA::ComputeBA(const IFormFactor& ff, size_t iLayer) : IComputeFF(ff, iLayer) {}
 
 ComputeBA::~ComputeBA() = default;
 
 ComputeBA* ComputeBA::clone() const
 {
-    return new ComputeBA(*m_ff);
+    return new ComputeBA(*m_ff, m_iLayer);
 }
 
 complex_t ComputeBA::computeFF(const WavevectorInfo& wavevectors) const
diff --git a/Resample/FFCompute/ComputeBA.h b/Resample/FFCompute/ComputeBA.h
index ffd58c6c743..7f8ccc572f3 100644
--- a/Resample/FFCompute/ComputeBA.h
+++ b/Resample/FFCompute/ComputeBA.h
@@ -29,7 +29,7 @@
 
 class ComputeBA : public IComputeFF {
 public:
-    ComputeBA(const IFormFactor& ff);
+    ComputeBA(const IFormFactor& ff, size_t iLayer);
     ~ComputeBA() override;
 
     ComputeBA* clone() const override;
diff --git a/Resample/FFCompute/ComputeBAPol.cpp b/Resample/FFCompute/ComputeBAPol.cpp
index 18459c67f3a..13ccfa43e25 100644
--- a/Resample/FFCompute/ComputeBAPol.cpp
+++ b/Resample/FFCompute/ComputeBAPol.cpp
@@ -16,13 +16,13 @@
 #include "Sample/Material/WavevectorInfo.h"
 #include <stdexcept>
 
-ComputeBAPol::ComputeBAPol(const IFormFactor& ff) : IComputeFF(ff) {}
+ComputeBAPol::ComputeBAPol(const IFormFactor& ff, size_t iLayer) : IComputeFF(ff, iLayer) {}
 
 ComputeBAPol::~ComputeBAPol() = default;
 
 ComputeBAPol* ComputeBAPol::clone() const
 {
-    return new ComputeBAPol(*m_ff);
+    return new ComputeBAPol(*m_ff, m_iLayer);
 }
 
 complex_t ComputeBAPol::computeFF(const WavevectorInfo&) const
diff --git a/Resample/FFCompute/ComputeBAPol.h b/Resample/FFCompute/ComputeBAPol.h
index 9643a1175f1..13b27e64306 100644
--- a/Resample/FFCompute/ComputeBAPol.h
+++ b/Resample/FFCompute/ComputeBAPol.h
@@ -30,7 +30,7 @@
 
 class ComputeBAPol : public IComputeFF {
 public:
-    ComputeBAPol(const IFormFactor& ff);
+    ComputeBAPol(const IFormFactor& ff, size_t iLayer);
     ~ComputeBAPol() override;
 
     ComputeBAPol* clone() const override;
diff --git a/Resample/FFCompute/ComputeDWBA.cpp b/Resample/FFCompute/ComputeDWBA.cpp
index 2703478d773..83381a5a980 100644
--- a/Resample/FFCompute/ComputeDWBA.cpp
+++ b/Resample/FFCompute/ComputeDWBA.cpp
@@ -17,13 +17,13 @@
 #include "Sample/Material/WavevectorInfo.h"
 #include "Sample/Scattering/IFormFactor.h"
 
-ComputeDWBA::ComputeDWBA(const IFormFactor& ff) : IComputeFF(ff) {}
+ComputeDWBA::ComputeDWBA(const IFormFactor& ff, size_t iLayer) : IComputeFF(ff, iLayer) {}
 
 ComputeDWBA::~ComputeDWBA() = default;
 
 ComputeDWBA* ComputeDWBA::clone() const
 {
-    ComputeDWBA* result = new ComputeDWBA(*m_ff);
+    ComputeDWBA* result = new ComputeDWBA(*m_ff, m_iLayer);
     auto in_coefs = std::unique_ptr<const IFlux>(m_inFlux ? m_inFlux->clone() : nullptr);
     auto out_coefs = std::unique_ptr<const IFlux>(m_outFlux ? m_outFlux->clone() : nullptr);
     result->setFlux(std::move(in_coefs), std::move(out_coefs));
diff --git a/Resample/FFCompute/ComputeDWBA.h b/Resample/FFCompute/ComputeDWBA.h
index f57cb1e6e8c..bf6910ffb2e 100644
--- a/Resample/FFCompute/ComputeDWBA.h
+++ b/Resample/FFCompute/ComputeDWBA.h
@@ -31,7 +31,7 @@ class IFlux;
 
 class ComputeDWBA : public IComputeFF {
 public:
-    ComputeDWBA(const IFormFactor& ff);
+    ComputeDWBA(const IFormFactor& ff, size_t iLayer);
     ~ComputeDWBA() override;
 
     ComputeDWBA* clone() const override;
diff --git a/Resample/FFCompute/ComputeDWBAPol.cpp b/Resample/FFCompute/ComputeDWBAPol.cpp
index b0f999e9627..9de9bc273d9 100644
--- a/Resample/FFCompute/ComputeDWBAPol.cpp
+++ b/Resample/FFCompute/ComputeDWBAPol.cpp
@@ -18,20 +18,23 @@
 #include "Sample/Scattering/IFormFactor.h"
 
 namespace {
+
 complex_t VecMatVecProduct(const Eigen::Vector2cd& vec1, const Eigen::Matrix2cd& ff,
                            const Eigen::Vector2cd& vec2)
 {
     return vec1.transpose() * ff * vec2;
 }
+
 } // namespace
 
-ComputeDWBAPol::ComputeDWBAPol(const IFormFactor& ff) : IComputeFF(ff) {}
+
+ComputeDWBAPol::ComputeDWBAPol(const IFormFactor& ff, size_t iLayer) : IComputeFF(ff, iLayer) {}
 
 ComputeDWBAPol::~ComputeDWBAPol() = default;
 
 ComputeDWBAPol* ComputeDWBAPol::clone() const
 {
-    ComputeDWBAPol* result = new ComputeDWBAPol(*m_ff);
+    ComputeDWBAPol* result = new ComputeDWBAPol(*m_ff, m_iLayer);
     std::unique_ptr<const IFlux> in_coefs =
         m_inFlux ? std::unique_ptr<const IFlux>(m_inFlux->clone()) : nullptr;
     std::unique_ptr<const IFlux> out_coefs =
diff --git a/Resample/FFCompute/ComputeDWBAPol.h b/Resample/FFCompute/ComputeDWBAPol.h
index f340059e431..d8524d080d6 100644
--- a/Resample/FFCompute/ComputeDWBAPol.h
+++ b/Resample/FFCompute/ComputeDWBAPol.h
@@ -31,7 +31,7 @@ class IFlux;
 
 class ComputeDWBAPol : public IComputeFF {
 public:
-    ComputeDWBAPol(const IFormFactor& ff);
+    ComputeDWBAPol(const IFormFactor& ff, size_t iLayer);
     ~ComputeDWBAPol() override;
 
     ComputeDWBAPol* clone() const override;
diff --git a/Resample/FFCompute/IComputeFF.cpp b/Resample/FFCompute/IComputeFF.cpp
index a4185d1b4fb..3caf368c4c3 100644
--- a/Resample/FFCompute/IComputeFF.cpp
+++ b/Resample/FFCompute/IComputeFF.cpp
@@ -17,7 +17,8 @@
 #include "Sample/Scattering/IFormFactor.h"
 #include <stdexcept>
 
-IComputeFF::IComputeFF(const IFormFactor& ff) : m_ff(ff.clone()) {}
+IComputeFF::IComputeFF(const IFormFactor& ff, size_t iLayer)
+    : m_ff(ff.clone()), m_iLayer(iLayer) {}
 
 IComputeFF::~IComputeFF() = default;
 
diff --git a/Resample/FFCompute/IComputeFF.h b/Resample/FFCompute/IComputeFF.h
index 582b32f21de..ae36e0bd548 100644
--- a/Resample/FFCompute/IComputeFF.h
+++ b/Resample/FFCompute/IComputeFF.h
@@ -43,6 +43,8 @@ public:
 
     virtual void setAmbientMaterial(const Material& material);
 
+    size_t iLayer() const { return m_iLayer; }
+
     virtual double volume() const;
     virtual double radialExtension() const;
     virtual double bottomZ(const IRotation& rotation) const;
@@ -54,9 +56,10 @@ public:
     virtual void setFlux(std::unique_ptr<const IFlux>, std::unique_ptr<const IFlux>);
 
 protected:
-    IComputeFF(const IFormFactor&);
+    IComputeFF(const IFormFactor& ff, size_t iLayer);
 
     std::unique_ptr<IFormFactor> m_ff;
+    const size_t m_iLayer;
 };
 
 #endif // BORNAGAIN_RESAMPLE_FFCOMPUTE_ICOMPUTEFF_H
diff --git a/Resample/Fresnel/IFresnelMap.h b/Resample/Fresnel/IFresnelMap.h
index 483cb71b943..4e6e26355f7 100644
--- a/Resample/Fresnel/IFresnelMap.h
+++ b/Resample/Fresnel/IFresnelMap.h
@@ -41,11 +41,11 @@ public:
 
     //! Retrieves the amplitude coefficients for given wavevector and layer.
     virtual std::unique_ptr<const IFlux> getInFlux(const kvector_t& kvec,
-                                                   size_t layer_index) const = 0;
+                                                   size_t iLayer) const = 0;
 
     //! Retrieves the amplitude coefficients for a (time-reversed) outgoing wavevector.
     virtual std::unique_ptr<const IFlux> getOutFlux(const kvector_t& kvec,
-                                                    size_t layer_index) const = 0;
+                                                    size_t iLayer) const = 0;
 
     const SliceStack& slices() const;
 
diff --git a/Resample/Fresnel/MatrixFresnelMap.cpp b/Resample/Fresnel/MatrixFresnelMap.cpp
index 07a2a523193..e6c8a5524a8 100644
--- a/Resample/Fresnel/MatrixFresnelMap.cpp
+++ b/Resample/Fresnel/MatrixFresnelMap.cpp
@@ -39,30 +39,30 @@ size_t MatrixFresnelMap::HashKVector::operator()(const kvector_t& kvec) const no
 }
 
 std::unique_ptr<const IFlux> MatrixFresnelMap::getOutFlux(const kvector_t& kvec,
-                                                          size_t layer_index) const
+                                                          size_t iLayer) const
 {
-    return computeFlux(-kvec, layer_index, m_inverted_slices, m_hash_table_out);
+    return computeFlux(-kvec, iLayer, m_inverted_slices, m_hash_table_out);
 }
 
 std::unique_ptr<const IFlux> MatrixFresnelMap::getInFlux(const kvector_t& kvec,
-                                                         size_t layer_index) const
+                                                         size_t iLayer) const
 {
-    return computeFlux(kvec, layer_index, m_slices, m_hash_table_in);
+    return computeFlux(kvec, iLayer, m_slices, m_hash_table_in);
 }
 
 std::unique_ptr<const IFlux> MatrixFresnelMap::computeFlux(const kvector_t& kvec,
-                                                           size_t layer_index,
+                                                           size_t iLayer,
                                                            const SliceStack& slices,
                                                            CoefficientHash& hash_table) const
 {
     if (!m_use_cache) {
         const auto coeffs = m_strategy->Execute(slices, kvec);
-        return std::unique_ptr<const IFlux>(coeffs[layer_index]->clone());
+        return std::unique_ptr<const IFlux>(coeffs[iLayer]->clone());
     }
     // from cache
     auto it = hash_table.find(kvec);
     if (it == hash_table.end())
         it = hash_table.emplace(kvec, m_strategy->Execute(slices, kvec)).first;
     const auto& coef_vector = it->second;
-    return std::unique_ptr<const IFlux>(coef_vector[layer_index]->clone());
+    return std::unique_ptr<const IFlux>(coef_vector[iLayer]->clone());
 }
diff --git a/Resample/Fresnel/MatrixFresnelMap.h b/Resample/Fresnel/MatrixFresnelMap.h
index 432275b88e7..5985232c847 100644
--- a/Resample/Fresnel/MatrixFresnelMap.h
+++ b/Resample/Fresnel/MatrixFresnelMap.h
@@ -49,13 +49,13 @@ private:
     };
 
     std::unique_ptr<const IFlux> getInFlux(const kvector_t& kvec,
-                                           size_t layer_index) const override;
+                                           size_t iLayer) const override;
     std::unique_ptr<const IFlux> getOutFlux(const kvector_t& kvec,
-                                            size_t layer_index) const override;
+                                            size_t iLayer) const override;
 
     using CoefficientHash = std::unordered_map<kvector_t, ISpecularStrategy::coeffs_t, HashKVector>;
 
-    std::unique_ptr<const IFlux> computeFlux(const kvector_t& kvec, size_t layer_index,
+    std::unique_ptr<const IFlux> computeFlux(const kvector_t& kvec, size_t iLayer,
                                              const SliceStack& slices,
                                              CoefficientHash& hash_table) const;
     SliceStack m_inverted_slices;
diff --git a/Resample/Fresnel/ScalarFresnelMap.cpp b/Resample/Fresnel/ScalarFresnelMap.cpp
index 29b12a9a157..c3cc474e02c 100644
--- a/Resample/Fresnel/ScalarFresnelMap.cpp
+++ b/Resample/Fresnel/ScalarFresnelMap.cpp
@@ -32,17 +32,17 @@ ScalarFresnelMap::Hash2Doubles::operator()(const std::pair<double, double>& doub
 }
 
 std::unique_ptr<const IFlux> ScalarFresnelMap::getOutFlux(const kvector_t& kvec,
-                                                          size_t layer_index) const
+                                                          size_t iLayer) const
 {
-    return getInFlux(-kvec, layer_index);
+    return getInFlux(-kvec, iLayer);
 }
 
 std::unique_ptr<const IFlux> ScalarFresnelMap::getInFlux(const kvector_t& kvec,
-                                                         size_t layer_index) const
+                                                         size_t iLayer) const
 {
     if (!m_use_cache) {
         auto coeffs = m_strategy->Execute(m_slices, kvec);
-        return std::unique_ptr<const IFlux>(coeffs[layer_index]->clone());
+        return std::unique_ptr<const IFlux>(coeffs[iLayer]->clone());
     }
     // from cache
     std::pair<double, double> k2_theta(kvec.mag2(), kvec.theta());
@@ -50,5 +50,5 @@ std::unique_ptr<const IFlux> ScalarFresnelMap::getInFlux(const kvector_t& kvec,
     if (it == m_cache.end())
         it = m_cache.emplace(k2_theta, m_strategy->Execute(m_slices, kvec)).first;
     const auto& coef_vector = it->second;
-    return std::unique_ptr<const IFlux>(coef_vector[layer_index]->clone());
+    return std::unique_ptr<const IFlux>(coef_vector[iLayer]->clone());
 }
diff --git a/Resample/Fresnel/ScalarFresnelMap.h b/Resample/Fresnel/ScalarFresnelMap.h
index acf3059209c..fb42c647f2b 100644
--- a/Resample/Fresnel/ScalarFresnelMap.h
+++ b/Resample/Fresnel/ScalarFresnelMap.h
@@ -49,9 +49,9 @@ private:
     };
 
     std::unique_ptr<const IFlux> getInFlux(const kvector_t& kvec,
-                                           size_t layer_index) const override;
+                                           size_t iLayer) const override;
     std::unique_ptr<const IFlux> getOutFlux(const kvector_t& kvec,
-                                            size_t layer_index) const override;
+                                            size_t iLayer) const override;
 
     mutable std::unordered_map<std::pair<double, double>, ISpecularStrategy::coeffs_t, Hash2Doubles>
         m_cache;
diff --git a/Resample/Processed/ParticleRegions.cpp b/Resample/Processed/ParticleRegions.cpp
index d85e19bf56f..1c91f80a233 100644
--- a/Resample/Processed/ParticleRegions.cpp
+++ b/Resample/Processed/ParticleRegions.cpp
@@ -45,8 +45,8 @@ public:
     std::vector<ZLimits> layerZLimits() const;
 
 private:
-    size_t layerIndexTop(double top_z) const;
-    size_t layerIndexBottom(double bottom_z) const;
+    size_t iLayerTop(double top_z) const;
+    size_t iLayerBottom(double bottom_z) const;
     void updateLayerLimits(size_t i_layer, ZLimits limits);
     std::vector<double> m_layers_bottomz;
     std::vector<ZLimits> m_layer_fill_limits;
@@ -99,8 +99,8 @@ void LayerFillLimits::update(ZLimits particle_limits, double offset)
         throw std::runtime_error("LayerFillLimits::update: lower_limit > upper_limit.");
     if (bottom == top) // zero-size particle
         return;
-    size_t top_index = layerIndexTop(top);
-    size_t bottom_index = layerIndexBottom(bottom);
+    size_t top_index = iLayerTop(top);
+    size_t bottom_index = iLayerBottom(bottom);
     for (size_t i_layer = top_index; i_layer < bottom_index + 1; ++i_layer) {
         ZLimits limits(bottom, top);
         updateLayerLimits(i_layer, limits);
@@ -112,7 +112,7 @@ std::vector<ZLimits> LayerFillLimits::layerZLimits() const
     return m_layer_fill_limits;
 }
 
-size_t LayerFillLimits::layerIndexTop(double top_z) const
+size_t LayerFillLimits::iLayerTop(double top_z) const
 {
     if (m_layers_bottomz.empty())
         return 0;
@@ -122,7 +122,7 @@ size_t LayerFillLimits::layerIndexTop(double top_z) const
     return static_cast<size_t>(m_layers_bottomz.rend() - index_above);
 }
 
-size_t LayerFillLimits::layerIndexBottom(double bottom_z) const
+size_t LayerFillLimits::iLayerBottom(double bottom_z) const
 {
     if (m_layers_bottomz.empty())
         return 0;
diff --git a/Resample/Processed/ProcessedLayout.cpp b/Resample/Processed/ProcessedLayout.cpp
index 3d11b99cf33..9fbbd006605 100644
--- a/Resample/Processed/ProcessedLayout.cpp
+++ b/Resample/Processed/ProcessedLayout.cpp
@@ -96,34 +96,35 @@ CoherentFFSum ProcessedLayout::processParticle(const IParticle& particle, const
         for (auto& region : entry.second)
             region.m_volume *= abundance * intensity_factor;
     for (const auto& entry : region_map) {
-        const size_t layer_index = entry.first;
+        const size_t iLayer = entry.first;
         const auto& regions = entry.second;
-        m_region_map[layer_index].insert(m_region_map[layer_index].begin(), regions.begin(),
+        m_region_map[iLayer].insert(m_region_map[iLayer].begin(), regions.begin(),
                                          regions.end());
     }
 
     std::vector<CoherentFFTerm> terms;
     for (size_t i = 0; i < sliced_ffs.size(); ++i) { // TODO provide slices_ffs.cbegin() etc
-        const auto ff_pair = sliced_ffs.getPair(i);
+        const auto pair = sliced_ffs.getPair(i);
+        const IFormFactor& ff = *pair.first;
+        const size_t iLayer = pair.second;
         std::unique_ptr<IComputeFF> computer;
         if (slices.size() > 1) {
             if (m_polarized)
-                computer = std::make_unique<ComputeDWBAPol>(*ff_pair.first);
+                computer = std::make_unique<ComputeDWBAPol>(ff, iLayer);
             else
-                computer = std::make_unique<ComputeDWBA>(*ff_pair.first);
+                computer = std::make_unique<ComputeDWBA>(ff, iLayer);
         } else {
             // no need for DWBA, use BA
             if (m_polarized)
-                computer = std::make_unique<ComputeBAPol>(*ff_pair.first);
+                computer = std::make_unique<ComputeBAPol>(ff, iLayer);
             else
-                computer = std::make_unique<ComputeBA>(*ff_pair.first);
+                computer = std::make_unique<ComputeBA>(ff, iLayer);
         }
 
-        const size_t slice_index = ff_pair.second;
-        const Material& slice_material = slices[slice_index].material();
+        const Material& slice_material = slices[iLayer].material();
         computer->setAmbientMaterial(slice_material);
 
-        terms.emplace_back(CoherentFFTerm(computer.release(), slice_index));
+        terms.emplace_back(CoherentFFTerm(computer.release()));
     }
     return CoherentFFSum(abundance, terms);
 }
diff --git a/Sample/Multilayer/MultiLayer.cpp b/Sample/Multilayer/MultiLayer.cpp
index 5aeceba786f..fcd7d32fc29 100644
--- a/Sample/Multilayer/MultiLayer.cpp
+++ b/Sample/Multilayer/MultiLayer.cpp
@@ -87,7 +87,7 @@ void MultiLayer::addLayerWithTopRoughness(const Layer& layer, const LayerRoughne
 
 const Layer* MultiLayer::layer(size_t i_layer) const
 {
-    return m_layers[check_layer_index(i_layer)];
+    return m_layers[check_iLayer(i_layer)];
 }
 
 const LayerInterface* MultiLayer::layerInterface(size_t i_interface) const
@@ -139,7 +139,7 @@ void MultiLayer::addInterface(LayerInterface* child)
     registerChild(child);
 }
 
-size_t MultiLayer::check_layer_index(size_t i_layer) const
+size_t MultiLayer::check_iLayer(size_t i_layer) const
 {
     if (i_layer >= m_layers.size())
         throw std::runtime_error("Layer index is out of bounds");
diff --git a/Sample/Multilayer/MultiLayer.h b/Sample/Multilayer/MultiLayer.h
index 596e28d70a6..842b84924b8 100644
--- a/Sample/Multilayer/MultiLayer.h
+++ b/Sample/Multilayer/MultiLayer.h
@@ -79,7 +79,7 @@ private:
     void addInterface(LayerInterface* child);
 
     //! Checks index of layer w.r.t. vector length
-    size_t check_layer_index(size_t i_layer) const;
+    size_t check_iLayer(size_t i_layer) const;
 
     //! Checks index of interface w.r.t. vector length
     size_t check_interface_index(size_t i_interface) const;
diff --git a/Tests/UnitTests/Core/Sample/FormFactorCoherentSumTest.cpp b/Tests/UnitTests/Core/Sample/FormFactorCoherentSumTest.cpp
index e244d22e871..da133730a61 100644
--- a/Tests/UnitTests/Core/Sample/FormFactorCoherentSumTest.cpp
+++ b/Tests/UnitTests/Core/Sample/FormFactorCoherentSumTest.cpp
@@ -10,7 +10,7 @@ TEST_F(CoherentFFSumTest, RelAbundance)
 {
     const double epsilon = 1e-12;
     FormFactorFullSphere ff(5.0);
-    CoherentFFTerm part(new ComputeBA(ff), 1.);
+    CoherentFFTerm part(new ComputeBA(ff, 0));
     CoherentFFSum ffw(1.0, {part});
     EXPECT_EQ(1.0, ffw.relativeAbundance());
     EXPECT_EQ(5.0, ffw.radialExtension());
diff --git a/mvvm/tests/testviewmodel/TestToyLayerItem.cpp b/mvvm/tests/testviewmodel/TestToyLayerItem.cpp
index 3888c808b24..59a8a758231 100644
--- a/mvvm/tests/testviewmodel/TestToyLayerItem.cpp
+++ b/mvvm/tests/testviewmodel/TestToyLayerItem.cpp
@@ -67,22 +67,22 @@ TEST_F(ToyLayerItemTest, inViewModel)
     EXPECT_EQ(viewModel.columnCount(), 2);
 
     // accessing to viewItem representing layerItem
-    QModelIndex layerIndex = viewModel.index(0, 0);
-    auto viewItem = dynamic_cast<ViewLabelItem*>(viewModel.itemFromIndex(layerIndex));
+    QModelIndex iLayer = viewModel.index(0, 0);
+    auto viewItem = dynamic_cast<ViewLabelItem*>(viewModel.itemFromIndex(iLayer));
     EXPECT_TRUE(viewItem != nullptr);
     EXPECT_EQ(viewItem->item(), layerItem);
 
     // it has two rows and two columns, corresponding to our "thickness" and "color" properties
-    EXPECT_EQ(viewModel.rowCount(layerIndex), 2);
-    EXPECT_EQ(viewModel.columnCount(layerIndex), 2);
+    EXPECT_EQ(viewModel.rowCount(iLayer), 2);
+    EXPECT_EQ(viewModel.columnCount(iLayer), 2);
 
     // accessing to views representing label and value of thickness property
-    QModelIndex thicknessLabelIndex = viewModel.index(0, 0, layerIndex);
+    QModelIndex thicknessLabelIndex = viewModel.index(0, 0, iLayer);
     auto thicknessLabelView =
         dynamic_cast<ViewLabelItem*>(viewModel.itemFromIndex(thicknessLabelIndex));
     EXPECT_TRUE(thicknessLabelView != nullptr);
 
-    QModelIndex thicknessValueIndex = viewModel.index(0, 1, layerIndex);
+    QModelIndex thicknessValueIndex = viewModel.index(0, 1, iLayer);
     auto thicknessValueView =
         dynamic_cast<ViewDataItem*>(viewModel.itemFromIndex(thicknessValueIndex));
     EXPECT_TRUE(thicknessValueView != nullptr);
@@ -104,8 +104,8 @@ TEST_F(ToyLayerItemTest, layerItemDataChanged)
     // constructing viewModel from sample model
     DefaultViewModel viewModel(&model);
 
-    QModelIndex layerIndex = viewModel.index(0, 0);
-    QModelIndex thicknessIndex = viewModel.index(0, 1, layerIndex);
+    QModelIndex iLayer = viewModel.index(0, 0);
+    QModelIndex thicknessIndex = viewModel.index(0, 1, iLayer);
 
     QSignalSpy spyDataChanged(&viewModel, &DefaultViewModel::dataChanged);
 
diff --git a/mvvm/tests/testviewmodel/topitemsviewmodel.test.cpp b/mvvm/tests/testviewmodel/topitemsviewmodel.test.cpp
index 099849ece26..03f327569f0 100644
--- a/mvvm/tests/testviewmodel/topitemsviewmodel.test.cpp
+++ b/mvvm/tests/testviewmodel/topitemsviewmodel.test.cpp
@@ -95,23 +95,23 @@ TEST_F(TopItemsViewModelTest, insertLayerInMultiLayerThenRemove)
     EXPECT_EQ(spyInsert.count(), 2);
 
     // checking their indices
-    auto multilayer_index = viewmodel.index(0, 0, QModelIndex());
-    auto layer_index = viewmodel.index(0, 0, multilayer_index);
-    EXPECT_EQ(viewmodel.sessionItemFromIndex(multilayer_index), multilayer);
-    EXPECT_EQ(viewmodel.sessionItemFromIndex(layer_index), layer);
+    auto multiiLayer = viewmodel.index(0, 0, QModelIndex());
+    auto iLayer = viewmodel.index(0, 0, multiiLayer);
+    EXPECT_EQ(viewmodel.sessionItemFromIndex(multiiLayer), multilayer);
+    EXPECT_EQ(viewmodel.sessionItemFromIndex(iLayer), layer);
 
     // checking row and columns
-    EXPECT_EQ(viewmodel.rowCount(multilayer_index), 1);
-    EXPECT_EQ(viewmodel.columnCount(multilayer_index), 2);
-    EXPECT_EQ(viewmodel.rowCount(layer_index), 0);
-    EXPECT_EQ(viewmodel.columnCount(layer_index), 0);
+    EXPECT_EQ(viewmodel.rowCount(multiiLayer), 1);
+    EXPECT_EQ(viewmodel.columnCount(multiiLayer), 2);
+    EXPECT_EQ(viewmodel.rowCount(iLayer), 0);
+    EXPECT_EQ(viewmodel.columnCount(iLayer), 0);
 
     // removing layer
     model.removeItem(multilayer, {"", 0});
     EXPECT_EQ(spyRemove.count(), 1);
     EXPECT_EQ(spyInsert.count(), 2);
-    EXPECT_EQ(viewmodel.rowCount(multilayer_index), 0);
-    EXPECT_EQ(viewmodel.columnCount(multilayer_index), 0);
+    EXPECT_EQ(viewmodel.rowCount(multiiLayer), 0);
+    EXPECT_EQ(viewmodel.columnCount(multiiLayer), 0);
 }
 
 //! Insert LayerItem in MultiLayer while multilayer is root item. Then deleting multilayer.
-- 
GitLab


From d50da79177208008130afa894d3e7709e42c9982 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Thu, 8 Jul 2021 14:27:42 +0200
Subject: [PATCH 10/13] clone fct in other class

---
 Resample/Coherence/FFTerm.cpp     | 21 ++-------------------
 Resample/FFCompute/IComputeFF.cpp | 24 ++++++++++++++++++++++++
 Resample/FFCompute/IComputeFF.h   |  4 ++++
 3 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/Resample/Coherence/FFTerm.cpp b/Resample/Coherence/FFTerm.cpp
index 628a1f0bd19..540490ba58a 100644
--- a/Resample/Coherence/FFTerm.cpp
+++ b/Resample/Coherence/FFTerm.cpp
@@ -13,12 +13,7 @@
 //  ************************************************************************************************
 
 #include "Resample/Coherence/FFTerm.h"
-#include "Base/Pixel/SimulationElement.h"
-#include "Base/Utils/Assert.h"
 #include "Resample/FFCompute/IComputeFF.h"
-#include "Resample/Flux/IFlux.h"
-#include "Resample/Fresnel/IFresnelMap.h"
-#include "Sample/Material/WavevectorInfo.h"
 
 CoherentFFTerm::CoherentFFTerm(IComputeFF* computer)
     : m_computer(computer)
@@ -34,24 +29,12 @@ CoherentFFTerm::~CoherentFFTerm() = default;
 
 complex_t CoherentFFTerm::coherentFF(const SimulationElement& ele) const
 {
-    const IFresnelMap* const fresnel_map = ele.fresnelMap();
-    ASSERT(fresnel_map);
-    const size_t iLayer = m_computer->iLayer();
-    auto inFlux = fresnel_map->getInFlux(ele.getKi(), iLayer);
-    auto outFlux = fresnel_map->getOutFlux(ele.getMeanKf(), iLayer);
-    m_computer->setFlux(std::move(inFlux), std::move(outFlux));
-    return m_computer->computeFF({ele});
+    return m_computer->coherentFF(ele);
 }
 
 Eigen::Matrix2cd CoherentFFTerm::coherentPolFF(const SimulationElement& ele) const
 {
-    const IFresnelMap* const fresnel_map = ele.fresnelMap();
-    ASSERT(fresnel_map);
-    const size_t iLayer = m_computer->iLayer();
-    auto inFlux = fresnel_map->getInFlux(ele.getKi(), iLayer);
-    auto outFlux = fresnel_map->getOutFlux(ele.getMeanKf(), iLayer);
-    m_computer->setFlux(std::move(inFlux), std::move(outFlux));
-    return m_computer->computePolFF({ele});
+    return m_computer->coherentPolFF(ele);
 }
 
 double CoherentFFTerm::radialExtension() const
diff --git a/Resample/FFCompute/IComputeFF.cpp b/Resample/FFCompute/IComputeFF.cpp
index 3caf368c4c3..e13c607f6db 100644
--- a/Resample/FFCompute/IComputeFF.cpp
+++ b/Resample/FFCompute/IComputeFF.cpp
@@ -13,7 +13,11 @@
 //  ************************************************************************************************
 
 #include "Resample/FFCompute/IComputeFF.h"
+#include "Base/Pixel/SimulationElement.h"
+#include "Base/Utils/Assert.h"
 #include "Resample/Flux/IFlux.h" // required by VS19 compiler
+#include "Resample/Fresnel/IFresnelMap.h"
+#include "Sample/Material/WavevectorInfo.h"
 #include "Sample/Scattering/IFormFactor.h"
 #include <stdexcept>
 
@@ -53,3 +57,23 @@ Eigen::Matrix2cd IComputeFF::computePolFF(const WavevectorInfo&) const
 }
 
 void IComputeFF::setFlux(std::unique_ptr<const IFlux>, std::unique_ptr<const IFlux>) {}
+
+complex_t IComputeFF::coherentFF(const SimulationElement& ele)
+{
+    const IFresnelMap* const fresnel_map = ele.fresnelMap();
+    ASSERT(fresnel_map);
+    auto inFlux = fresnel_map->getInFlux(ele.getKi(), m_iLayer);
+    auto outFlux = fresnel_map->getOutFlux(ele.getMeanKf(), m_iLayer);
+    setFlux(std::move(inFlux), std::move(outFlux));
+    return computeFF({ele});
+}
+
+Eigen::Matrix2cd IComputeFF::coherentPolFF(const SimulationElement& ele)
+{
+    const IFresnelMap* const fresnel_map = ele.fresnelMap();
+    ASSERT(fresnel_map);
+    auto inFlux = fresnel_map->getInFlux(ele.getKi(), m_iLayer);
+    auto outFlux = fresnel_map->getOutFlux(ele.getMeanKf(), m_iLayer);
+    setFlux(std::move(inFlux), std::move(outFlux));
+    return computePolFF({ele});
+}
diff --git a/Resample/FFCompute/IComputeFF.h b/Resample/FFCompute/IComputeFF.h
index ae36e0bd548..23347ae4651 100644
--- a/Resample/FFCompute/IComputeFF.h
+++ b/Resample/FFCompute/IComputeFF.h
@@ -28,6 +28,7 @@ class IFormFactor;
 class IFlux;
 class IRotation;
 class Material;
+class SimulationElement;
 class WavevectorInfo;
 
 //! Abstract base class for form factor evaluations.
@@ -55,6 +56,9 @@ public:
     //! Sets reflection/transmission info
     virtual void setFlux(std::unique_ptr<const IFlux>, std::unique_ptr<const IFlux>);
 
+    complex_t coherentFF(const SimulationElement& sim_element); // TODO make const
+    Eigen::Matrix2cd coherentPolFF(const SimulationElement& sim_element);
+
 protected:
     IComputeFF(const IFormFactor& ff, size_t iLayer);
 
-- 
GitLab


From e89014b7a0e93542ea87e2bcc702e45790b8c0a9 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Thu, 8 Jul 2021 15:22:47 +0200
Subject: [PATCH 11/13] simplify handling of abundance

---
 Resample/Coherence/FFSum.cpp                    |  7 -------
 Resample/Coherence/FFSum.h                      |  1 -
 Resample/Processed/ProcessedLayout.cpp          | 17 +++++++++--------
 Resample/Processed/ProcessedLayout.h            |  2 +-
 .../Core/Sample/FormFactorCoherentSumTest.cpp   |  5 -----
 5 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/Resample/Coherence/FFSum.cpp b/Resample/Coherence/FFSum.cpp
index 58525a02a0b..422a5fb0200 100644
--- a/Resample/Coherence/FFSum.cpp
+++ b/Resample/Coherence/FFSum.cpp
@@ -35,13 +35,6 @@ Eigen::Matrix2cd CoherentFFSum::summedPolFF(const SimulationElement& sim_element
     return result;
 }
 
-void CoherentFFSum::scaleRelativeAbundance(double total_abundance)
-{
-    if (total_abundance <= 0.0)
-        throw std::runtime_error("bug or invalid API call: nonpositiv particle abundance");
-    m_abundance /= total_abundance;
-}
-
 double CoherentFFSum::radialExtension() const
 {
     return m_terms[0].radialExtension();
diff --git a/Resample/Coherence/FFSum.h b/Resample/Coherence/FFSum.h
index c882b7e72bb..8e2e33934b7 100644
--- a/Resample/Coherence/FFSum.h
+++ b/Resample/Coherence/FFSum.h
@@ -36,7 +36,6 @@ public:
     Eigen::Matrix2cd summedPolFF(const SimulationElement& sim_element) const;
 
     double relativeAbundance() const { return m_abundance; }
-    void scaleRelativeAbundance(double total_abundance);
     double radialExtension() const;
 
 private:
diff --git a/Resample/Processed/ProcessedLayout.cpp b/Resample/Processed/ProcessedLayout.cpp
index 9fbbd006605..90b2346d3aa 100644
--- a/Resample/Processed/ProcessedLayout.cpp
+++ b/Resample/Processed/ProcessedLayout.cpp
@@ -13,6 +13,7 @@
 //  ************************************************************************************************
 
 #include "Resample/Processed/ProcessedLayout.h"
+#include "Base/Utils/Assert.h"
 #include "Resample/Coherence/FFSum.h"
 #include "Resample/FFCompute/ComputeBA.h"
 #include "Resample/FFCompute/ComputeBAPol.h"
@@ -34,12 +35,11 @@ ProcessedLayout::ProcessedLayout(const ParticleLayout& layout, const SliceStack&
     , m_surface_density(layout.weightedParticleSurfaceDensity())
 {
     const double layout_abundance = layout.getTotalAbundance();
-    for (const auto* particle : layout.particles()) {
-        CoherentFFSum ff_coh =
-            processParticle(*particle, slices, z_ref, m_surface_density / layout_abundance);
-        ff_coh.scaleRelativeAbundance(layout_abundance);
-        m_formfactors.emplace_back(ff_coh);
-    }
+    ASSERT(layout_abundance > 0);
+    for (const auto* particle : layout.particles())
+        m_formfactors.emplace_back(
+            processParticle(*particle, slices, z_ref, m_surface_density / layout_abundance,
+                            layout_abundance));
 
     if (const auto* iff = layout.interferenceFunction())
         m_iff.reset(iff->clone());
@@ -85,7 +85,8 @@ ProcessedLayout::~ProcessedLayout() = default;
 //! Returns a contribution to m_formfactors, and modifies m_region_map.
 
 CoherentFFSum ProcessedLayout::processParticle(const IParticle& particle, const SliceStack& slices,
-                                               double z_ref, double intensity_factor)
+                                               double z_ref, double intensity_factor,
+                                               double total_abundance)
 {
     const double abundance = particle.abundance();
     const SlicedFormFactorList sliced_ffs(particle, slices, z_ref);
@@ -126,5 +127,5 @@ CoherentFFSum ProcessedLayout::processParticle(const IParticle& particle, const
 
         terms.emplace_back(CoherentFFTerm(computer.release()));
     }
-    return CoherentFFSum(abundance, terms);
+    return CoherentFFSum(abundance / total_abundance, terms);
 }
diff --git a/Resample/Processed/ProcessedLayout.h b/Resample/Processed/ProcessedLayout.h
index 7dc754b1f9a..fdbb0539976 100644
--- a/Resample/Processed/ProcessedLayout.h
+++ b/Resample/Processed/ProcessedLayout.h
@@ -54,7 +54,7 @@ public:
 
 private:
     CoherentFFSum processParticle(const IParticle& particle, const SliceStack& slices, double z_ref,
-                                  double intensity_factor);
+                                  double intensity_factor, double total_abundance);
 
     const bool m_polarized;
     const size_t m_n_slices;
diff --git a/Tests/UnitTests/Core/Sample/FormFactorCoherentSumTest.cpp b/Tests/UnitTests/Core/Sample/FormFactorCoherentSumTest.cpp
index da133730a61..191471ca8a0 100644
--- a/Tests/UnitTests/Core/Sample/FormFactorCoherentSumTest.cpp
+++ b/Tests/UnitTests/Core/Sample/FormFactorCoherentSumTest.cpp
@@ -8,14 +8,9 @@ class CoherentFFSumTest : public ::testing::Test {
 
 TEST_F(CoherentFFSumTest, RelAbundance)
 {
-    const double epsilon = 1e-12;
     FormFactorFullSphere ff(5.0);
     CoherentFFTerm part(new ComputeBA(ff, 0));
     CoherentFFSum ffw(1.0, {part});
     EXPECT_EQ(1.0, ffw.relativeAbundance());
     EXPECT_EQ(5.0, ffw.radialExtension());
-    ffw.scaleRelativeAbundance(2.0);
-    EXPECT_NEAR(0.5, ffw.relativeAbundance(), epsilon);
-    EXPECT_THROW(ffw.scaleRelativeAbundance(0.0), std::runtime_error);
-    EXPECT_EQ(5.0, ffw.radialExtension());
 }
-- 
GitLab


From bf7132f971befc5196397746cc59feb8f6774a4f Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Thu, 8 Jul 2021 15:23:11 +0200
Subject: [PATCH 12/13] +const

---
 Resample/Coherence/FFSum.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Resample/Coherence/FFSum.h b/Resample/Coherence/FFSum.h
index 8e2e33934b7..100e38bf159 100644
--- a/Resample/Coherence/FFSum.h
+++ b/Resample/Coherence/FFSum.h
@@ -39,7 +39,7 @@ public:
     double radialExtension() const;
 
 private:
-    double m_abundance;
+    const double m_abundance;
     const std::vector<CoherentFFTerm> m_terms;
 };
 
-- 
GitLab


From afe8a72d8c80165c37a52001ce8016a555306200 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Thu, 8 Jul 2021 15:23:37 +0200
Subject: [PATCH 13/13] namespace -> top

---
 Resample/Flux/MatrixFlux.cpp | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/Resample/Flux/MatrixFlux.cpp b/Resample/Flux/MatrixFlux.cpp
index 05b297c0185..5dea672e3b4 100644
--- a/Resample/Flux/MatrixFlux.cpp
+++ b/Resample/Flux/MatrixFlux.cpp
@@ -16,10 +16,19 @@
 #include "Base/Utils/Assert.h"
 
 namespace {
-complex_t GetImExponential(complex_t exponent);
+
 const auto eps = std::numeric_limits<double>::epsilon() * 10.;
+
+complex_t GetImExponential(complex_t exponent)
+{
+    if (exponent.imag() > -std::log(std::numeric_limits<double>::min()))
+        return 0.0;
+    return std::exp(I * exponent);
+}
+
 } // namespace
 
+
 MatrixFlux::MatrixFlux(double kz_sign, Eigen::Vector2cd eigenvalues, kvector_t b,
                        double magnetic_SLD)
     : m_kz_sign(kz_sign)
@@ -164,12 +173,3 @@ Eigen::Matrix2cd MatrixFlux::computeDeltaMatrix(double thickness)
 
     throw std::runtime_error("Broken magnetic field vector");
 }
-
-namespace {
-complex_t GetImExponential(complex_t exponent)
-{
-    if (exponent.imag() > -std::log(std::numeric_limits<double>::min()))
-        return 0.0;
-    return std::exp(I * exponent);
-}
-} // namespace
-- 
GitLab