From c0eeb47abb706b26f448530d4aadeba2c3ad0579 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de> Date: Thu, 13 Oct 2016 11:23:49 +0200 Subject: [PATCH] merge IInterferenceFunctionStrategy::setSpecularInfo into init; make init non-virtual at base class level, and call virtual strategy_specific_post_init. --- .../DecouplingApproximationStrategy.cpp | 10 ---------- .../DecouplingApproximationStrategy.h | 3 --- .../IInterferenceFunctionStrategy.cpp | 14 +++++++++----- .../IInterferenceFunctionStrategy.h | 19 ++++++++++++------- Core/Multilayer/LayerStrategyBuilder.cpp | 3 +-- ...pacingCorrelationApproximationStrategy.cpp | 8 +------- ...eSpacingCorrelationApproximationStrategy.h | 4 +--- 7 files changed, 24 insertions(+), 37 deletions(-) diff --git a/Core/Multilayer/DecouplingApproximationStrategy.cpp b/Core/Multilayer/DecouplingApproximationStrategy.cpp index 68ad745bd2c..dbe3f5cc36e 100644 --- a/Core/Multilayer/DecouplingApproximationStrategy.cpp +++ b/Core/Multilayer/DecouplingApproximationStrategy.cpp @@ -23,16 +23,6 @@ #include <cassert> #include <iostream> -void DecouplingApproximationStrategy::init( - const SafePointerVector<WeightedFormFactor>& weighted_formfactors, - const IInterferenceFunction& iff) -{ - IInterferenceFunctionStrategy::init(weighted_formfactors, iff); - if (m_weighted_ffs.size()==0) - throw Exceptions::ClassInitializationException( - "No formfactors for Decoupling Approximation."); -} - //! Returns the total incoherent and coherent scattering intensity for given kf and //! for one layer (implied by the given particle form factors). //! For each IParticle in the layer layout, the precomputed form factor must be provided. diff --git a/Core/Multilayer/DecouplingApproximationStrategy.h b/Core/Multilayer/DecouplingApproximationStrategy.h index 7efebdcb118..5643946f8a4 100644 --- a/Core/Multilayer/DecouplingApproximationStrategy.h +++ b/Core/Multilayer/DecouplingApproximationStrategy.h @@ -30,9 +30,6 @@ public: : IInterferenceFunctionStrategy(sim_params) {} ~DecouplingApproximationStrategy() final {} - void init(const SafePointerVector<WeightedFormFactor>& weighted_formfactors, - const IInterferenceFunction& iff) final; - private: double evaluateForList(const SimulationElement& sim_element) const final; double evaluateForMatrixList(const SimulationElement& sim_element) const final; diff --git a/Core/Multilayer/IInterferenceFunctionStrategy.cpp b/Core/Multilayer/IInterferenceFunctionStrategy.cpp index 39db0850d12..0a3beabb328 100644 --- a/Core/Multilayer/IInterferenceFunctionStrategy.cpp +++ b/Core/Multilayer/IInterferenceFunctionStrategy.cpp @@ -40,21 +40,25 @@ IInterferenceFunctionStrategy::IInterferenceFunctionStrategy( // otherwise forward declaration of IntegratorMCMiser doesn't work IInterferenceFunctionStrategy::~IInterferenceFunctionStrategy() {} +//! Initializes the object with form factors and interference functions void IInterferenceFunctionStrategy::init( const SafePointerVector<WeightedFormFactor>& weighted_formfactors, - const IInterferenceFunction& iff) + const IInterferenceFunction& iff, + const LayerSpecularInfo& specular_info) { + if (weighted_formfactors.size()==0) + throw Exceptions::ClassInitializationException("Bug: Decorated layer has no formfactors."); m_weighted_ffs = weighted_formfactors; mP_iff.reset(iff.clone()); + m_total_abundance = 0; for (const auto wff: m_weighted_ffs) m_total_abundance += wff->m_abundance; -} -void IInterferenceFunctionStrategy::setSpecularInfo(const LayerSpecularInfo& specular_info) -{ - if (mP_specular_info.get() != &specular_info) + if (&specular_info != mP_specular_info.get()) mP_specular_info.reset(specular_info.clone()); + + strategy_specific_post_init(); } double IInterferenceFunctionStrategy::evaluate(const SimulationElement& sim_element) const diff --git a/Core/Multilayer/IInterferenceFunctionStrategy.h b/Core/Multilayer/IInterferenceFunctionStrategy.h index ffc2e50d640..9f5cfd06496 100644 --- a/Core/Multilayer/IInterferenceFunctionStrategy.h +++ b/Core/Multilayer/IInterferenceFunctionStrategy.h @@ -31,7 +31,14 @@ class IInterferenceFunction; class LayerSpecularInfo; class SimulationElement; -//! Algorithm to apply one of interference function strategies (LMA, SCCA etc). +//! Virtual base class of the interference function strategy classes +//! DecouplingApproximationStrategy, SizeSpacingCorrelationApproximationStrategy. +//! These classes provide 'evaluate' functions that compute the scattering intensity +//! from a decorated layer, taking into account a specific inter-particle interference function. +//! +//! Child classes are instantiated in LayerStrategyBuilder::createStrategy, +//! which is called from DecoratedLayerComputation::eval. +//! //! @ingroup algorithms_internal class BA_CORE_API_ IInterferenceFunctionStrategy @@ -43,12 +50,8 @@ public: IInterferenceFunctionStrategy(const SimulationOptions& sim_params); virtual ~IInterferenceFunctionStrategy(); - //! Initializes the object with form factors and interference functions - virtual void init(const SafePointerVector<WeightedFormFactor>& weighted_formfactors, - const IInterferenceFunction& iff); - - //! Provides the R,T coefficients information - void setSpecularInfo(const LayerSpecularInfo& specular_info); + void init(const SafePointerVector<WeightedFormFactor>& weighted_formfactors, + const IInterferenceFunction& iff, const LayerSpecularInfo& specular_info); //! Calculates the intensity for scalar particles/interactions double evaluate(const SimulationElement& sim_element) const; @@ -57,6 +60,8 @@ public: double evaluatePol(const SimulationElement& sim_element) const; protected: + virtual void strategy_specific_post_init() {} + //! Evaluates the intensity for given list of evaluated form factors virtual double evaluateForList(const SimulationElement& sim_element) const = 0; diff --git a/Core/Multilayer/LayerStrategyBuilder.cpp b/Core/Multilayer/LayerStrategyBuilder.cpp index 815c4d07f47..84986c816fc 100644 --- a/Core/Multilayer/LayerStrategyBuilder.cpp +++ b/Core/Multilayer/LayerStrategyBuilder.cpp @@ -73,8 +73,7 @@ IInterferenceFunctionStrategy* LayerStrategyBuilder::createStrategy() if (!p_result) throw Exceptions::ClassInitializationException( "Could not create appropriate strategy"); - p_result->init(m_weighted_ffs, *mP_interference_function); - p_result->setSpecularInfo(*mP_specular_info); + p_result->init(m_weighted_ffs, *mP_interference_function, *mP_specular_info); return p_result; } diff --git a/Core/Multilayer/SizeSpacingCorrelationApproximationStrategy.cpp b/Core/Multilayer/SizeSpacingCorrelationApproximationStrategy.cpp index 46f3c72de6c..7cd55d1cb90 100644 --- a/Core/Multilayer/SizeSpacingCorrelationApproximationStrategy.cpp +++ b/Core/Multilayer/SizeSpacingCorrelationApproximationStrategy.cpp @@ -27,14 +27,8 @@ SizeSpacingCorrelationApproximationStrategy::SizeSpacingCorrelationApproximation { } -void SizeSpacingCorrelationApproximationStrategy::init( - const SafePointerVector<WeightedFormFactor>& weighted_formfactors, - const IInterferenceFunction &iff) +void SizeSpacingCorrelationApproximationStrategy::strategy_specific_post_init() { - IInterferenceFunctionStrategy::init(weighted_formfactors, iff); - if (m_weighted_ffs.size()==0) - throw Exceptions::ClassInitializationException( - "No formfactors for Size-Spacing Correlation Approximation."); initMeanRadius(); } diff --git a/Core/Multilayer/SizeSpacingCorrelationApproximationStrategy.h b/Core/Multilayer/SizeSpacingCorrelationApproximationStrategy.h index 62ed20c6244..44f8885d972 100644 --- a/Core/Multilayer/SizeSpacingCorrelationApproximationStrategy.h +++ b/Core/Multilayer/SizeSpacingCorrelationApproximationStrategy.h @@ -29,10 +29,8 @@ public: SizeSpacingCorrelationApproximationStrategy(SimulationOptions sim_params, double kappa); ~SizeSpacingCorrelationApproximationStrategy() final {} - void init(const SafePointerVector<WeightedFormFactor>& weighted_formfactors, - const IInterferenceFunction& iff) final; - private: + void strategy_specific_post_init() final; double evaluateForList(const SimulationElement& sim_element) const final; double evaluateForMatrixList(const SimulationElement& sim_element) const final; -- GitLab