From 85a6a28e4f8aeedc235d6aaecc93fa91c2b00d8e Mon Sep 17 00:00:00 2001
From: Randolf Beerwerth <r.beerwerth@fz-juelich.de>
Date: Fri, 21 Aug 2020 13:19:29 +0200
Subject: [PATCH] Move definition of I to complex header

---
 Core/Basics/Complex.h                             | 3 ++-
 Core/HardParticle/FormFactorPolyhedron.cpp        | 1 -
 Core/HardParticle/FormFactorTruncatedSpheroid.cpp | 4 ++--
 Core/HardParticle/Ripples.cpp                     | 2 +-
 Core/Material/MaterialUtils.cpp                   | 2 --
 Core/Multilayer/SpecularMagneticOldStrategy.cpp   | 1 -
 Core/Multilayer/SpecularMagneticStrategy.cpp      | 1 -
 Core/RT/MatrixRTCoefficients_v2.cpp               | 2 --
 Tests/UnitTests/Core/Axes/CVectorTest.cpp         | 2 +-
 9 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/Core/Basics/Complex.h b/Core/Basics/Complex.h
index 13dff4f89e3..5434dce6e47 100644
--- a/Core/Basics/Complex.h
+++ b/Core/Basics/Complex.h
@@ -17,7 +17,8 @@
 
 #include <complex>
 
-typedef std::complex<double> complex_t;
+using complex_t = std::complex<double>;
+constexpr complex_t I = complex_t(0.0, 1.0);
 
 //! Returns product I*z, where I is the imaginary unit.
 inline complex_t mul_I(complex_t z)
diff --git a/Core/HardParticle/FormFactorPolyhedron.cpp b/Core/HardParticle/FormFactorPolyhedron.cpp
index ab3cda4e776..e222907fbe5 100644
--- a/Core/HardParticle/FormFactorPolyhedron.cpp
+++ b/Core/HardParticle/FormFactorPolyhedron.cpp
@@ -26,7 +26,6 @@
 
 namespace
 {
-const complex_t I = {0., 1.};
 const double eps = 2e-16;
 constexpr auto ReciprocalFactorialArray = Precomputed::GenerateReciprocalFactorialArray<171>();
 } // namespace
diff --git a/Core/HardParticle/FormFactorTruncatedSpheroid.cpp b/Core/HardParticle/FormFactorTruncatedSpheroid.cpp
index b7e93ff2092..2f7c2199158 100644
--- a/Core/HardParticle/FormFactorTruncatedSpheroid.cpp
+++ b/Core/HardParticle/FormFactorTruncatedSpheroid.cpp
@@ -70,7 +70,7 @@ complex_t FormFactorTruncatedSpheroid::Integrand(double Z) const
     complex_t qrRz = std::sqrt(m_q.x() * m_q.x() + m_q.y() * m_q.y()) * Rz;
     complex_t J1_qrRz_div_qrRz = MathFunctions::Bessel_J1c(qrRz);
 
-    return Rz * Rz * J1_qrRz_div_qrRz * std::exp(complex_t(0.0, 1.0) * m_q.z() * Z);
+    return Rz * Rz * J1_qrRz_div_qrRz * std::exp(I * m_q.z() * Z);
 }
 
 complex_t FormFactorTruncatedSpheroid::evaluate_for_q(cvector_t q) const
@@ -82,7 +82,7 @@ complex_t FormFactorTruncatedSpheroid::evaluate_for_q(cvector_t q) const
 
     if (std::abs(m_q.mag()) <= std::numeric_limits<double>::epsilon())
         return M_PI / 3. / fp * (H * H * (3. * R - H / fp) - m_dh * m_dh * (3. * R - m_dh / fp));
-    complex_t z_part = std::exp(complex_t(0.0, 1.0) * m_q.z() * (H - fp * R));
+    complex_t z_part = std::exp(I * m_q.z() * (H - fp * R));
     return M_TWOPI * z_part
            * ComplexIntegrator().integrate([&](double Z) { return Integrand(Z); }, fp * R - H,
                                            fp * R - m_dh);
diff --git a/Core/HardParticle/Ripples.cpp b/Core/HardParticle/Ripples.cpp
index f4b677e2c50..f1e301c7967 100644
--- a/Core/HardParticle/Ripples.cpp
+++ b/Core/HardParticle/Ripples.cpp
@@ -60,7 +60,7 @@ complex_t ripples::profile_yz_cosine(complex_t qy, complex_t qz, double width, d
 
     // numerical integration otherwise
     const complex_t ay = qy * width / M_TWOPI;
-    const complex_t az = complex_t(0, 1) * qz * (height / 2);
+    const complex_t az = I * qz * (height / 2);
 
     const auto integrand = [&](double u) -> complex_t {
         return sin(u) * exp(az * std::cos(u)) * (ay == 0. ? u : sin(ay * u) / ay);
diff --git a/Core/Material/MaterialUtils.cpp b/Core/Material/MaterialUtils.cpp
index 82d5dccb246..206c75ac156 100644
--- a/Core/Material/MaterialUtils.cpp
+++ b/Core/Material/MaterialUtils.cpp
@@ -29,8 +29,6 @@ const Eigen::Matrix2cd Unit_Matrix(Eigen::Matrix2cd::Identity());
 // Imaginary unit
 namespace
 {
-const complex_t I(0, 1);
-
 // Pauli matrices
 const Eigen::Matrix2cd Pauli_X((Eigen::Matrix2cd() << 0, 1, 1, 0).finished());
 const Eigen::Matrix2cd Pauli_Y((Eigen::Matrix2cd() << 0, -I, I, 0).finished());
diff --git a/Core/Multilayer/SpecularMagneticOldStrategy.cpp b/Core/Multilayer/SpecularMagneticOldStrategy.cpp
index 2727c0903e1..35cad226571 100644
--- a/Core/Multilayer/SpecularMagneticOldStrategy.cpp
+++ b/Core/Multilayer/SpecularMagneticOldStrategy.cpp
@@ -28,7 +28,6 @@ void CalculateTransferAndBoundary(const std::vector<Slice>& slices,
                                   std::vector<MatrixRTCoefficients>& coeff);
 void SetForNoTransmission(std::vector<MatrixRTCoefficients>& coeff);
 complex_t GetImExponential(complex_t exponent);
-const complex_t I(0, 1);
 } // namespace
 
 ISpecularStrategy::coeffs_t SpecularMagneticOldStrategy::Execute(const std::vector<Slice>& slices,
diff --git a/Core/Multilayer/SpecularMagneticStrategy.cpp b/Core/Multilayer/SpecularMagneticStrategy.cpp
index c66b7c84075..f58c2bb910d 100644
--- a/Core/Multilayer/SpecularMagneticStrategy.cpp
+++ b/Core/Multilayer/SpecularMagneticStrategy.cpp
@@ -27,7 +27,6 @@ complex_t GetImExponential(complex_t exponent);
 // The factor 1e-18 is here to have unit: 1/T*nm^-2
 constexpr double magnetic_prefactor = PhysConsts::m_n * PhysConsts::g_factor_n * PhysConsts::mu_N
                                       / PhysConsts::h_bar / PhysConsts::h_bar * 1e-18;
-constexpr complex_t I(0.0, 1.0);
 } // namespace
 
 ISpecularStrategy::coeffs_t SpecularMagneticStrategy::Execute(const std::vector<Slice>& slices,
diff --git a/Core/RT/MatrixRTCoefficients_v2.cpp b/Core/RT/MatrixRTCoefficients_v2.cpp
index 9dee9413842..b82e825e548 100644
--- a/Core/RT/MatrixRTCoefficients_v2.cpp
+++ b/Core/RT/MatrixRTCoefficients_v2.cpp
@@ -18,8 +18,6 @@ namespace
 {
 Eigen::Vector2cd waveVector(const Eigen::Matrix4cd& frob_matrix,
                             const Eigen::Vector4cd& boundary_cond);
-
-constexpr complex_t I = complex_t(0.0, 1.0);
 } // namespace
 
 MatrixRTCoefficients_v2::MatrixRTCoefficients_v2(double kz_sign, Eigen::Vector2cd eigenvalues,
diff --git a/Tests/UnitTests/Core/Axes/CVectorTest.cpp b/Tests/UnitTests/Core/Axes/CVectorTest.cpp
index 2c9f32e5f6e..28d4b8ef3cb 100644
--- a/Tests/UnitTests/Core/Axes/CVectorTest.cpp
+++ b/Tests/UnitTests/Core/Axes/CVectorTest.cpp
@@ -37,6 +37,6 @@ TEST_F(CVectorTest, BasicArithmetics)
     // f = f_re + j*f_im
     cvector_t vec_e(1., 2., 3.);
     cvector_t vec_f(5., 6., 7.);
-    EXPECT_EQ(vec_e + complex_t(0, 1) * vec_f,
+    EXPECT_EQ(vec_e + I * vec_f,
               cvector_t(complex_t(1., 5.), complex_t(2., 6), complex_t(3, 7)));
 }
-- 
GitLab