diff --git a/Core/Multilayer/DecouplingApproximationStrategy.cpp b/Core/Multilayer/DecouplingApproximationStrategy.cpp index 68ad745bd2cd3cbc7809b105c2b42adc229440ca..dbe3f5cc36e2b257571d7fc5b18220f4a5199f5f 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 7efebdcb11899e6589645d3817481e3639c1b4ff..5643946f8a4d8c628195f371b0f4cb455213a0e1 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 39db0850d12f7eacfaea76d233f2ec4d9709269a..0a3beabb3280785d4d02d0b0d3f78b25db790b25 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 ffc2e50d64094be1cb4aae757402e325e3d386e6..9f5cfd064963109654e378678613883a3932b968 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 815c4d07f471bc225abc608e76acb6ee29e1fb08..84986c816fc02ee8df9babc720660f59e9779c9c 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 46f3c72de6c95e04940fa4d01c960b049d5bb3d4..7cd55d1cb9075adb1e4fc9c59d6cc576fa696ce8 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 62ed20c6244e7348b39f37ebda2358b35f408ea7..44f8885d972fb8cee877aacc6a4e61aa4abdaac8 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;