From fbe53934dc6e351c993a664d2e40d5a65c7ab671 Mon Sep 17 00:00:00 2001 From: Randolf Beerwerth <r.beerwerth@fz-juelich.de> Date: Sat, 21 Mar 2020 13:14:44 +0100 Subject: [PATCH] Hide concrete type returned by SpecularScalarStrategy --- Core/Multilayer/ScalarFresnelMap.cpp | 7 +++---- Core/Multilayer/ScalarFresnelMap.h | 5 +++-- Core/Multilayer/SpecularScalarStrategy.cpp | 6 +++--- Core/Multilayer/SpecularScalarStrategy.h | 24 ++++++++++++---------- Tests/UnitTests/Core/Sample/RTTest.cpp | 2 +- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Core/Multilayer/ScalarFresnelMap.cpp b/Core/Multilayer/ScalarFresnelMap.cpp index b8e5bfc9c75..9e433d281f2 100644 --- a/Core/Multilayer/ScalarFresnelMap.cpp +++ b/Core/Multilayer/ScalarFresnelMap.cpp @@ -16,7 +16,6 @@ #include "ScalarRTCoefficients.h" #include "SimulationElement.h" #include "Slice.h" -#include "SpecularScalarStrategy.h" #include "Vectors3D.h" #include <functional> @@ -41,13 +40,13 @@ ScalarFresnelMap::getCoefficients(const kvector_t& kvec, size_t layer_index) con { if (!m_use_cache) { auto coeffs = std::make_unique<SpecularScalarStrategy>()->Execute(m_slices, kvec); - return std::unique_ptr<const ScalarRTCoefficients>(coeffs[layer_index]->clone()); + return SpecularScalarStrategy::single_coeff_t(coeffs[layer_index]->clone()); } const auto& coef_vector = getCoefficientsFromCache(kvec); - return std::unique_ptr<const ScalarRTCoefficients>(coef_vector[layer_index]->clone()); + return SpecularScalarStrategy::single_coeff_t(coef_vector[layer_index]->clone()); } -const std::vector<std::unique_ptr<ScalarRTCoefficients>>& +const SpecularScalarStrategy::coeffs_t& ScalarFresnelMap::getCoefficientsFromCache(kvector_t kvec) const { std::pair<double, double> k2_theta(kvec.mag2(), kvec.theta()); diff --git a/Core/Multilayer/ScalarFresnelMap.h b/Core/Multilayer/ScalarFresnelMap.h index e5f40b23889..4b825bf9571 100644 --- a/Core/Multilayer/ScalarFresnelMap.h +++ b/Core/Multilayer/ScalarFresnelMap.h @@ -17,6 +17,7 @@ #include "IFresnelMap.h" #include "ScalarRTCoefficients.h" +#include "SpecularScalarStrategy.h" #include <cstddef> #include <unordered_map> #include <utility> @@ -48,8 +49,8 @@ private: std::unique_ptr<const ILayerRTCoefficients> getCoefficients(const kvector_t& kvec, size_t layer_index) const override; - const std::vector<std::unique_ptr<ScalarRTCoefficients>>& getCoefficientsFromCache(kvector_t kvec) const; - mutable std::unordered_map<std::pair<double, double>, std::vector<std::unique_ptr<ScalarRTCoefficients>>, + const SpecularScalarStrategy::coeffs_t& getCoefficientsFromCache(kvector_t kvec) const; + mutable std::unordered_map<std::pair<double, double>, SpecularScalarStrategy::coeffs_t, Hash2Doubles> m_cache; }; diff --git a/Core/Multilayer/SpecularScalarStrategy.cpp b/Core/Multilayer/SpecularScalarStrategy.cpp index 0dcd09ec5f6..df6d2d2232f 100644 --- a/Core/Multilayer/SpecularScalarStrategy.cpp +++ b/Core/Multilayer/SpecularScalarStrategy.cpp @@ -42,20 +42,20 @@ const LayerRoughness* GetBottomRoughness(const std::vector<Slice>& slices, const double pi2_15 = std::pow(M_PI_2, 1.5); } // namespace -std::vector<std::unique_ptr<ScalarRTCoefficients>> +SpecularScalarStrategy::coeffs_t SpecularScalarStrategy::Execute(const std::vector<Slice>& slices, kvector_t k) { std::vector<complex_t> kz = KzComputation::computeReducedKz(slices, k); return Execute(slices, kz); } -std::vector<std::unique_ptr<ScalarRTCoefficients>> +SpecularScalarStrategy::coeffs_t SpecularScalarStrategy::Execute(const std::vector<Slice>& slices, const std::vector<complex_t>& kz) { if(slices.size() != kz.size()) throw std::runtime_error("Number of slices does not match the size of the kz-vector"); - std::vector<std::unique_ptr<ScalarRTCoefficients>> result; + SpecularScalarStrategy::coeffs_t result; for(auto& coeff : computeTR(slices, kz)) result.push_back( std::make_unique<ScalarRTCoefficients>(coeff) ); diff --git a/Core/Multilayer/SpecularScalarStrategy.h b/Core/Multilayer/SpecularScalarStrategy.h index a4d1758d5a5..2632a42434b 100644 --- a/Core/Multilayer/SpecularScalarStrategy.h +++ b/Core/Multilayer/SpecularScalarStrategy.h @@ -29,17 +29,19 @@ class Slice; class SpecularScalarStrategy { public: -//! Computes refraction angles and transmission/reflection coefficients -//! for given coherent wave propagation in a multilayer. -//! Roughness is modelled by tanh profile [see e.g. Phys. Rev. B, vol. 47 (8), p. 4385 (1993)]. -BA_CORE_API_ std::vector<std::unique_ptr<ScalarRTCoefficients>> -Execute(const std::vector<Slice>& slices, kvector_t k); - -//! Computes transmission/reflection coefficients -//! for given set of z-components of wave-vectors in a multilayer. -//! Roughness is modelled by tanh profile [see e.g. Phys. Rev. B, vol. 47 (8), p. 4385 (1993)]. -BA_CORE_API_ std::vector<std::unique_ptr<ScalarRTCoefficients>> -Execute(const std::vector<Slice>& slices, const std::vector<complex_t>& kz); + + typedef std::unique_ptr<const ScalarRTCoefficients> single_coeff_t; + typedef std::vector<single_coeff_t> coeffs_t; + + //! Computes refraction angles and transmission/reflection coefficients + //! for given coherent wave propagation in a multilayer. + //! Roughness is modelled by tanh profile [see e.g. Phys. Rev. B, vol. 47 (8), p. 4385 (1993)]. + BA_CORE_API_ coeffs_t Execute(const std::vector<Slice>& slices, kvector_t k); + + //! Computes transmission/reflection coefficients + //! for given set of z-components of wave-vectors in a multilayer. + //! Roughness is modelled by tanh profile [see e.g. Phys. Rev. B, vol. 47 (8), p. 4385 (1993)]. + BA_CORE_API_ coeffs_t Execute(const std::vector<Slice>& slices, const std::vector<complex_t>& kz); }; // namespace SpecularMatrix #endif // SPECULARSCALARSTRATEGY_H diff --git a/Tests/UnitTests/Core/Sample/RTTest.cpp b/Tests/UnitTests/Core/Sample/RTTest.cpp index 68ed43be4b0..eb8597d8f60 100644 --- a/Tests/UnitTests/Core/Sample/RTTest.cpp +++ b/Tests/UnitTests/Core/Sample/RTTest.cpp @@ -32,7 +32,7 @@ protected: EXPECT_NEAR(coeff1.t_r(1).real(), coeff2.t_r(1).real(), 1e-10); EXPECT_NEAR(coeff1.t_r(1).imag(), coeff2.t_r(1).imag(), 1e-10); } - std::vector<ScalarRTCoefficients> getCoeffs(std::vector<std::unique_ptr<ScalarRTCoefficients>>&& inputCoeffs) + std::vector<ScalarRTCoefficients> getCoeffs(SpecularScalarStrategy::coeffs_t&& inputCoeffs) { std::vector<ScalarRTCoefficients> result; for(auto& coeff : inputCoeffs) -- GitLab