From 419ce8943067100c2e003689fe86905abf4b141d Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (l)" <j.wuttke@fz-juelich.de> Date: Thu, 13 Oct 2016 09:39:04 +0200 Subject: [PATCH] no need to pass member variables m_ff, m_ff_pol as function arguments to member functions. --- .../DecouplingApproximationStrategy.cpp | 8 ++++---- .../Multilayer/DecouplingApproximationStrategy.h | 7 ++----- .../Multilayer/IInterferenceFunctionStrategy.cpp | 8 ++++---- Core/Multilayer/IInterferenceFunctionStrategy.h | 10 ++++------ ...zeSpacingCorrelationApproximationStrategy.cpp | 16 ++++++++-------- ...SizeSpacingCorrelationApproximationStrategy.h | 6 ++---- 6 files changed, 24 insertions(+), 31 deletions(-) diff --git a/Core/Multilayer/DecouplingApproximationStrategy.cpp b/Core/Multilayer/DecouplingApproximationStrategy.cpp index 0fd17cb4421..68ad745bd2c 100644 --- a/Core/Multilayer/DecouplingApproximationStrategy.cpp +++ b/Core/Multilayer/DecouplingApproximationStrategy.cpp @@ -37,14 +37,14 @@ void DecouplingApproximationStrategy::init( //! for one layer (implied by the given particle form factors). //! For each IParticle in the layer layout, the precomputed form factor must be provided. double DecouplingApproximationStrategy::evaluateForList( - const SimulationElement& sim_element, const std::vector<complex_t>& ff_list) const + const SimulationElement& sim_element) const { double intensity = 0.0; complex_t amplitude = complex_t(0.0, 0.0); if (m_total_abundance <= 0.0) return 0.0; for (size_t i = 0; i < m_weighted_ffs.size(); ++i) { - complex_t ff = ff_list[i]; + complex_t ff = m_ff[i]; if (std::isnan(ff.real())) throw Exceptions::RuntimeErrorException( "DecouplingApproximationStrategy::evaluateForList() -> Error! Amplitude is NaN"); @@ -63,7 +63,7 @@ double DecouplingApproximationStrategy::evaluateForList( //! This is the polarized variant of evaluateForList. Each form factor must be //! precomputed for polarized beam and detector. double DecouplingApproximationStrategy::evaluateForMatrixList( - const SimulationElement& sim_element, const matrixFFVector_t& ff_list) const + const SimulationElement& sim_element) const { Eigen::Matrix2cd mean_intensity = Eigen::Matrix2cd::Zero(); Eigen::Matrix2cd mean_amplitude = Eigen::Matrix2cd::Zero(); @@ -71,7 +71,7 @@ double DecouplingApproximationStrategy::evaluateForMatrixList( if (m_total_abundance <= 0.0) return 0.0; for (size_t i = 0; i < m_weighted_ffs.size(); ++i) { - Eigen::Matrix2cd ff = ff_list[i]; + Eigen::Matrix2cd ff = m_ff_pol[i]; if (!ff.allFinite()) throw Exceptions::RuntimeErrorException( "DecouplingApproximationStrategy::evaluateForList() -> " diff --git a/Core/Multilayer/DecouplingApproximationStrategy.h b/Core/Multilayer/DecouplingApproximationStrategy.h index 3ec70aaa537..7efebdcb118 100644 --- a/Core/Multilayer/DecouplingApproximationStrategy.h +++ b/Core/Multilayer/DecouplingApproximationStrategy.h @@ -34,11 +34,8 @@ public: const IInterferenceFunction& iff) final; private: - double evaluateForList(const SimulationElement& sim_element, - const std::vector<complex_t>& ff_list) const final; - - double evaluateForMatrixList(const SimulationElement& sim_element, - const matrixFFVector_t& ff_list) const final; + double evaluateForList(const SimulationElement& sim_element) const final; + double evaluateForMatrixList(const SimulationElement& sim_element) const final; }; #endif // DECOUPLINGAPPROXIMATIONSTRATEGY_H diff --git a/Core/Multilayer/IInterferenceFunctionStrategy.cpp b/Core/Multilayer/IInterferenceFunctionStrategy.cpp index 8d3066804a9..bc3afe4d304 100644 --- a/Core/Multilayer/IInterferenceFunctionStrategy.cpp +++ b/Core/Multilayer/IInterferenceFunctionStrategy.cpp @@ -62,7 +62,7 @@ double IInterferenceFunctionStrategy::evaluate(const SimulationElement& sim_elem if (m_options.isIntegrate() && (sim_element.getSolidAngle() > 0.0)) return MCIntegratedEvaluate(sim_element); calculateFormFactorList(sim_element); - return evaluateForList(sim_element, m_ff); + return evaluateForList(sim_element); } double IInterferenceFunctionStrategy::evaluatePol(const SimulationElement& sim_element) const @@ -70,7 +70,7 @@ double IInterferenceFunctionStrategy::evaluatePol(const SimulationElement& sim_e if (m_options.isIntegrate()) // TODO: consider testing solid angle as in scalar case return MCIntegratedEvaluatePol(sim_element); calculateFormFactorListPol(sim_element); - return evaluateForMatrixList(sim_element, m_ff_pol); + return evaluateForMatrixList(sim_element); } //! Precomputes scalar form factors. @@ -149,7 +149,7 @@ double IInterferenceFunctionStrategy::evaluate_for_fixed_angles( SimulationElement sim_element(*pars, par0, par1); calculateFormFactorList(sim_element); - return pars->getIntegrationFactor(par0, par1) * evaluateForList(sim_element, m_ff); + return pars->getIntegrationFactor(par0, par1) * evaluateForList(sim_element); } double IInterferenceFunctionStrategy::evaluate_for_fixed_angles_pol( @@ -162,5 +162,5 @@ double IInterferenceFunctionStrategy::evaluate_for_fixed_angles_pol( SimulationElement sim_element(*pars, par0, par1); calculateFormFactorListPol(sim_element); - return pars->getIntegrationFactor(par0, par1) * evaluateForMatrixList(sim_element, m_ff_pol); + return pars->getIntegrationFactor(par0, par1) * evaluateForMatrixList(sim_element); } diff --git a/Core/Multilayer/IInterferenceFunctionStrategy.h b/Core/Multilayer/IInterferenceFunctionStrategy.h index f27e61dad48..79c138f4657 100644 --- a/Core/Multilayer/IInterferenceFunctionStrategy.h +++ b/Core/Multilayer/IInterferenceFunctionStrategy.h @@ -58,19 +58,19 @@ public: protected: //! Evaluates the intensity for given list of evaluated form factors - virtual double evaluateForList(const SimulationElement& sim_element, - const std::vector<complex_t>& ff_list) const = 0; + virtual double evaluateForList(const SimulationElement& sim_element) const = 0; //! Evaluates the intensity for given list of evaluated form factors //! in the presence of polarization of beam and detector - virtual double evaluateForMatrixList(const SimulationElement& sim_element, - const matrixFFVector_t& ff_list) const = 0; + virtual double evaluateForMatrixList(const SimulationElement& sim_element) const = 0; double m_total_abundance; //!< cached sum of particle abundances, computed by init() SafePointerVector<WeightedFormFactor> m_weighted_ffs; std::unique_ptr<IInterferenceFunction> mP_iff; SimulationOptions m_options; std::unique_ptr<LayerSpecularInfo> mP_specular_info; //!< R and T coefficients for DWBA + mutable std::vector<complex_t> m_ff; //!< cached form factor evaluations + mutable matrixFFVector_t m_ff_pol; //!< cached polarized form factors private: void calculateFormFactorList (const SimulationElement& sim_element) const; @@ -86,8 +86,6 @@ private: double evaluate_for_fixed_angles (double* fractions, size_t dim, void* params) const; double evaluate_for_fixed_angles_pol(double* fractions, size_t dim, void* params) const; - mutable std::vector<complex_t> m_ff; //!< cached form factor evaluations - mutable matrixFFVector_t m_ff_pol; //!< cached polarized form factors #ifndef SWIG std::unique_ptr<IntegratorMCMiser<IInterferenceFunctionStrategy>> mP_integrator; std::unique_ptr<IntegratorMCMiser<IInterferenceFunctionStrategy>> mP_integrator_pol; diff --git a/Core/Multilayer/SizeSpacingCorrelationApproximationStrategy.cpp b/Core/Multilayer/SizeSpacingCorrelationApproximationStrategy.cpp index 2401fc20ed8..1a07bb882de 100644 --- a/Core/Multilayer/SizeSpacingCorrelationApproximationStrategy.cpp +++ b/Core/Multilayer/SizeSpacingCorrelationApproximationStrategy.cpp @@ -42,19 +42,19 @@ void SizeSpacingCorrelationApproximationStrategy::init( //! for one layer (implied by the given particle form factors). //! For each IParticle in the layer layout, the precomputed form factor must be provided. double SizeSpacingCorrelationApproximationStrategy::evaluateForList( - const SimulationElement& sim_element, const std::vector<complex_t>& ff_list) const + const SimulationElement& sim_element) const { double qp = sim_element.getMeanQ().magxy(); double diffuse_intensity = 0.0; if (m_total_abundance <= 0.0) return 0.0; for (size_t i = 0; i < m_weighted_ffs.size(); ++i) { - complex_t ff = ff_list[i]; + complex_t ff = m_ff[i]; double fraction = m_weighted_ffs[i]->m_abundance / m_total_abundance; diffuse_intensity += fraction * std::norm(ff); } - complex_t mcff = getMeanCharacteristicFF (qp, ff_list); - complex_t mcffc = getMeanConjCharacteristicFF(qp, ff_list); + complex_t mcff = getMeanCharacteristicFF (qp, m_ff); + complex_t mcffc = getMeanConjCharacteristicFF(qp, m_ff); complex_t p2kappa = getCharacteristicSizeCoupling(qp, 2.0 * m_kappa); complex_t omega = getCharacteristicDistribution(qp); double interference_intensity = 2.0 * (mcff * mcffc * omega / (1.0 - p2kappa * omega)).real(); @@ -67,19 +67,19 @@ double SizeSpacingCorrelationApproximationStrategy::evaluateForList( //! This is the polarized variant of evaluateForList. Each form factor must be //! precomputed for polarized beam and detector. double SizeSpacingCorrelationApproximationStrategy::evaluateForMatrixList( - const SimulationElement& sim_element, const matrixFFVector_t& ff_list) const + const SimulationElement& sim_element) const { double qp = sim_element.getMeanQ().magxy(); Eigen::Matrix2cd diffuse_matrix = Eigen::Matrix2cd::Zero(); if (m_total_abundance <= 0.0) return 0.0; for (size_t i = 0; i < m_weighted_ffs.size(); ++i) { - Eigen::Matrix2cd ff = ff_list[i]; + Eigen::Matrix2cd ff = m_ff_pol[i]; double fraction = m_weighted_ffs[i]->m_abundance / m_total_abundance; diffuse_matrix += fraction * (ff * sim_element.getPolarization() * ff.adjoint()); } - Eigen::Matrix2cd mcff = getMeanCharacteristicMatrixFF (sim_element.getMeanQ(), ff_list); - Eigen::Matrix2cd mcffc = getMeanConjCharacteristicMatrixFF(sim_element.getMeanQ(), ff_list); + Eigen::Matrix2cd mcff = getMeanCharacteristicMatrixFF (sim_element.getMeanQ(), m_ff_pol); + Eigen::Matrix2cd mcffc = getMeanConjCharacteristicMatrixFF(sim_element.getMeanQ(), m_ff_pol); complex_t p2kappa = getCharacteristicSizeCoupling(qp, 2.0 * m_kappa); complex_t omega = getCharacteristicDistribution(qp); Eigen::Matrix2cd interference_matrix diff --git a/Core/Multilayer/SizeSpacingCorrelationApproximationStrategy.h b/Core/Multilayer/SizeSpacingCorrelationApproximationStrategy.h index 83bcceefe93..46f72e582a5 100644 --- a/Core/Multilayer/SizeSpacingCorrelationApproximationStrategy.h +++ b/Core/Multilayer/SizeSpacingCorrelationApproximationStrategy.h @@ -33,10 +33,8 @@ public: const IInterferenceFunction& iff) final; private: - double evaluateForList(const SimulationElement& sim_element, - const std::vector<complex_t>& ff_list) const final; - double evaluateForMatrixList(const SimulationElement& sim_element, - const matrixFFVector_t& ff_list) const final; + double evaluateForList(const SimulationElement& sim_element) const final; + double evaluateForMatrixList(const SimulationElement& sim_element) const final; complex_t getMeanCharacteristicFF( double qp, const std::vector<complex_t>& ff_list) const; -- GitLab