From 81ed04f81e39fe8ad7f37db1d7627073b909dd08 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de> Date: Mon, 16 Nov 2020 19:41:48 +0100 Subject: [PATCH] merge SSCAHelper into SSCA..Strategy --- .../Computation/ParticleLayoutComputation.cpp | 4 +- Sample/Interference/SSCAHelper.cpp | 54 -------------- Sample/Interference/SSCAHelper.h | 46 ------------ .../Interference/SSCApproximationStrategy.cpp | 49 ++++++++++-- .../Interference/SSCApproximationStrategy.h | 15 +++- auto/Wrap/doxygenSample.i | 74 ++++++------------- 6 files changed, 78 insertions(+), 164 deletions(-) delete mode 100644 Sample/Interference/SSCAHelper.cpp delete mode 100644 Sample/Interference/SSCAHelper.h diff --git a/Core/Computation/ParticleLayoutComputation.cpp b/Core/Computation/ParticleLayoutComputation.cpp index b6d1e2dd917..e28e00f885f 100644 --- a/Core/Computation/ParticleLayoutComputation.cpp +++ b/Core/Computation/ParticleLayoutComputation.cpp @@ -43,8 +43,8 @@ processedInterferenceFunction(const ProcessedLayout& layout, const SimulationOpt return std::make_unique<SSCApproximationStrategy>(weighted_formfactors, iff, sim_params, polarized, kappa); } - return std::make_unique<DecouplingApproximationStrategy>(weighted_formfactors, iff, - sim_params, polarized); + return std::make_unique<DecouplingApproximationStrategy>(weighted_formfactors, iff, sim_params, + polarized); } } // namespace diff --git a/Sample/Interference/SSCAHelper.cpp b/Sample/Interference/SSCAHelper.cpp deleted file mode 100644 index 38c772bdf3c..00000000000 --- a/Sample/Interference/SSCAHelper.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file Sample/Interference/SSCAHelper.cpp -//! @brief Implements class SSCAHelper. -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************** // - -#include "Sample/Interference/SSCAHelper.h" -#include "Base/Types/Exceptions.h" -#include "Sample/Aggregate/InterferenceFunctionRadialParaCrystal.h" -#include "Sample/Fresnel/FormFactorCoherentSum.h" - -SSCAHelper::SSCAHelper(double kappa) : m_kappa(kappa), m_mean_radius{} {} - -void SSCAHelper::init(const std::vector<FormFactorCoherentSum>& ff_wrappers) -{ - m_mean_radius = 0.0; - for (auto& ffw : ff_wrappers) - m_mean_radius += ffw.relativeAbundance() * ffw.radialExtension(); -} - -complex_t SSCAHelper::getCharacteristicSizeCoupling( - double qp, const std::vector<FormFactorCoherentSum>& ff_wrappers) const -{ - complex_t result{}; - for (auto& ffw : ff_wrappers) { - double radial_extension = ffw.radialExtension(); - result += - ffw.relativeAbundance() * calculatePositionOffsetPhase(2.0 * qp, radial_extension); - } - return result; -} - -complex_t SSCAHelper::getCharacteristicDistribution(double qp, - const IInterferenceFunction* p_iff) const -{ - const InterferenceFunctionRadialParaCrystal* p_iff_radial = - dynamic_cast<const InterferenceFunctionRadialParaCrystal*>(p_iff); - if (!p_iff_radial) - throw Exceptions::ClassInitializationException("Wrong interference function for SSCA"); - return p_iff_radial->FTPDF(qp); -} - -complex_t SSCAHelper::calculatePositionOffsetPhase(double qp, double radial_extension) const -{ - return exp_I(m_kappa * qp * (radial_extension - m_mean_radius)); -} diff --git a/Sample/Interference/SSCAHelper.h b/Sample/Interference/SSCAHelper.h deleted file mode 100644 index 13ea4268361..00000000000 --- a/Sample/Interference/SSCAHelper.h +++ /dev/null @@ -1,46 +0,0 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file Sample/Interference/SSCAHelper.h -//! @brief Defines class SSCAHelper. -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************** // - -#ifndef BORNAGAIN_SAMPLE_INTERFERENCE_SSCAHELPER_H -#define BORNAGAIN_SAMPLE_INTERFERENCE_SSCAHELPER_H - -#include "Sample/Interference/IInterferenceFunctionStrategy.h" -#include <Eigen/StdVector> - -class FormFactorCoherentSum; -class IInterferenceFunction; - -//! Helper class for SSCApproximationStrategy, offering some methods, shared between -//! the scalar and polarized scattering calculations -//! @ingroup algorithms_internal - -class SSCAHelper -{ -public: - SSCAHelper(double kappa); - - void init(const std::vector<FormFactorCoherentSum>& ff_wrappers); - - complex_t - getCharacteristicSizeCoupling(double qp, - const std::vector<FormFactorCoherentSum>& ff_wrappers) const; - complex_t getCharacteristicDistribution(double qp, const IInterferenceFunction* p_iff) const; - complex_t calculatePositionOffsetPhase(double qp, double radial_extension) const; - -private: - double m_kappa; - double m_mean_radius; -}; - -#endif // BORNAGAIN_SAMPLE_INTERFERENCE_SSCAHELPER_H diff --git a/Sample/Interference/SSCApproximationStrategy.cpp b/Sample/Interference/SSCApproximationStrategy.cpp index f569c165074..5afef486a52 100644 --- a/Sample/Interference/SSCApproximationStrategy.cpp +++ b/Sample/Interference/SSCApproximationStrategy.cpp @@ -14,16 +14,49 @@ #include "Sample/Interference/SSCApproximationStrategy.h" #include "Base/Pixel/SimulationElement.h" +#include "Base/Types/Exceptions.h" #include "Sample/Aggregate/IInterferenceFunction.h" +#include "Sample/Aggregate/InterferenceFunctionRadialParaCrystal.h" #include "Sample/Fresnel/FormFactorCoherentSum.h" +complex_t SSCApproximationStrategy::getCharacteristicSizeCoupling( + double qp, const std::vector<FormFactorCoherentSum>& ff_wrappers) const +{ + complex_t result{}; + for (auto& ffw : ff_wrappers) { + double radial_extension = ffw.radialExtension(); + result += + ffw.relativeAbundance() * calculatePositionOffsetPhase(2.0 * qp, radial_extension); + } + return result; +} + +complex_t +SSCApproximationStrategy::getCharacteristicDistribution(double qp, + const IInterferenceFunction* p_iff) const +{ + const InterferenceFunctionRadialParaCrystal* p_iff_radial = + dynamic_cast<const InterferenceFunctionRadialParaCrystal*>(p_iff); + if (!p_iff_radial) + throw Exceptions::ClassInitializationException("Wrong interference function for SSCA"); + return p_iff_radial->FTPDF(qp); +} + +complex_t SSCApproximationStrategy::calculatePositionOffsetPhase(double qp, + double radial_extension) const +{ + return exp_I(m_kappa * qp * (radial_extension - m_mean_radius)); +} + SSCApproximationStrategy::SSCApproximationStrategy( const std::vector<FormFactorCoherentSum>& weighted_formfactors, const IInterferenceFunction* p_iff, SimulationOptions sim_params, bool polarized, double kappa) : IInterferenceFunctionStrategy(weighted_formfactors, p_iff, sim_params, polarized) - , m_helper(kappa) + , m_kappa(kappa) { - m_helper.init(m_formfactor_wrappers); + m_mean_radius = 0.0; + for (auto& ffw : m_formfactor_wrappers) + m_mean_radius += ffw.relativeAbundance() * ffw.radialExtension(); } //! Returns the total scattering intensity for given kf and @@ -40,13 +73,13 @@ double SSCApproximationStrategy::scalarCalculation(const SimulationElement& sim_ diffuse_intensity += fraction * std::norm(ff); double radial_extension = ffw.radialExtension(); complex_t prefac = - ffw.relativeAbundance() * m_helper.calculatePositionOffsetPhase(qp, radial_extension); + ffw.relativeAbundance() * calculatePositionOffsetPhase(qp, radial_extension); ff_orig += prefac * ff; ff_conj += prefac * std::conj(ff); } complex_t mean_ff_norm = ff_orig * ff_conj; - complex_t p2kappa = m_helper.getCharacteristicSizeCoupling(qp, m_formfactor_wrappers); - complex_t omega = m_helper.getCharacteristicDistribution(qp, m_iff.get()); + complex_t p2kappa = getCharacteristicSizeCoupling(qp, m_formfactor_wrappers); + complex_t omega = getCharacteristicDistribution(qp, m_iff.get()); double iff = 2.0 * (mean_ff_norm * omega / (1.0 - p2kappa * omega)).real(); double dw_factor = m_iff->DWfactor(sim_element.getMeanQ()); return diffuse_intensity + dw_factor * iff; @@ -66,12 +99,12 @@ double SSCApproximationStrategy::polarizedCalculation(const SimulationElement& s diffuse_matrix += fraction * (ff * polarization_handler.getPolarization() * ff.adjoint()); double radial_extension = ffw.radialExtension(); complex_t prefac = - ffw.relativeAbundance() * m_helper.calculatePositionOffsetPhase(qp, radial_extension); + ffw.relativeAbundance() * calculatePositionOffsetPhase(qp, radial_extension); ff_orig += prefac * ff; ff_conj += prefac * ff.adjoint(); } - complex_t p2kappa = m_helper.getCharacteristicSizeCoupling(qp, m_formfactor_wrappers); - complex_t omega = m_helper.getCharacteristicDistribution(qp, m_iff.get()); + complex_t p2kappa = getCharacteristicSizeCoupling(qp, m_formfactor_wrappers); + complex_t omega = getCharacteristicDistribution(qp, m_iff.get()); Eigen::Matrix2cd interference_matrix = (2.0 * omega / (1.0 - p2kappa * omega)) * polarization_handler.getAnalyzerOperator() * ff_orig * polarization_handler.getPolarization() * ff_conj; diff --git a/Sample/Interference/SSCApproximationStrategy.h b/Sample/Interference/SSCApproximationStrategy.h index 073a478ab49..0a0f02e85fb 100644 --- a/Sample/Interference/SSCApproximationStrategy.h +++ b/Sample/Interference/SSCApproximationStrategy.h @@ -15,7 +15,8 @@ #ifndef BORNAGAIN_SAMPLE_INTERFERENCE_SSCAPPROXIMATIONSTRATEGY_H #define BORNAGAIN_SAMPLE_INTERFERENCE_SSCAPPROXIMATIONSTRATEGY_H -#include "Sample/Interference/SSCAHelper.h" +#include "Sample/Interference/IInterferenceFunctionStrategy.h" +#include <Eigen/StdVector> class SimulationElement; @@ -33,7 +34,17 @@ public: private: double scalarCalculation(const SimulationElement& sim_element) const override; double polarizedCalculation(const SimulationElement& sim_element) const override; - SSCAHelper m_helper; + + void init(const std::vector<FormFactorCoherentSum>& ff_wrappers); + + complex_t + getCharacteristicSizeCoupling(double qp, + const std::vector<FormFactorCoherentSum>& ff_wrappers) const; + complex_t getCharacteristicDistribution(double qp, const IInterferenceFunction* p_iff) const; + complex_t calculatePositionOffsetPhase(double qp, double radial_extension) const; + + double m_kappa; + double m_mean_radius; }; #endif // BORNAGAIN_SAMPLE_INTERFERENCE_SSCAPPROXIMATIONSTRATEGY_H diff --git a/auto/Wrap/doxygenSample.i b/auto/Wrap/doxygenSample.i index 2569a92ae4b..f8efb90997f 100644 --- a/auto/Wrap/doxygenSample.i +++ b/auto/Wrap/doxygenSample.i @@ -7320,30 +7320,6 @@ C++ includes: TwoDimLatticeBuilder.h "; -// File: classSSCAHelper.xml -%feature("docstring") SSCAHelper " - -Helper class for SSCApproximationStrategy, offering some methods, shared between the scalar and polarized scattering calculations - -C++ includes: SSCAHelper.h -"; - -%feature("docstring") SSCAHelper::SSCAHelper "SSCAHelper::SSCAHelper(double kappa) -"; - -%feature("docstring") SSCAHelper::init "void SSCAHelper::init(const std::vector< FormFactorCoherentSum > &ff_wrappers) -"; - -%feature("docstring") SSCAHelper::getCharacteristicSizeCoupling "complex_t SSCAHelper::getCharacteristicSizeCoupling(double qp, const std::vector< FormFactorCoherentSum > &ff_wrappers) const -"; - -%feature("docstring") SSCAHelper::getCharacteristicDistribution "complex_t SSCAHelper::getCharacteristicDistribution(double qp, const IInterferenceFunction *p_iff) const -"; - -%feature("docstring") SSCAHelper::calculatePositionOffsetPhase "complex_t SSCAHelper::calculatePositionOffsetPhase(double qp, double radial_extension) const -"; - - // File: classSSCApproximationStrategy.xml %feature("docstring") SSCApproximationStrategy " @@ -7544,13 +7520,16 @@ C++ includes: ZLimits.h // File: namespace_0d115.xml -// File: namespace_0d141.xml +// File: namespace_0d139.xml + +// File: namespace_0d143.xml -// File: namespace_0d145.xml +// File: namespace_0d147.xml -// File: namespace_0d149.xml + +// File: namespace_0d157.xml // File: namespace_0d159.xml @@ -7562,40 +7541,40 @@ C++ includes: ZLimits.h // File: namespace_0d161.xml -// File: namespace_0d163.xml +// File: namespace_0d171.xml -// File: namespace_0d173.xml +// File: namespace_0d192.xml // File: namespace_0d194.xml -// File: namespace_0d196.xml +// File: namespace_0d2.xml -// File: namespace_0d2.xml +// File: namespace_0d204.xml -// File: namespace_0d206.xml +// File: namespace_0d220.xml // File: namespace_0d222.xml -// File: namespace_0d224.xml +// File: namespace_0d229.xml -// File: namespace_0d231.xml +// File: namespace_0d247.xml -// File: namespace_0d249.xml +// File: namespace_0d25.xml -// File: namespace_0d25.xml +// File: namespace_0d255.xml -// File: namespace_0d257.xml +// File: namespace_0d265.xml // File: namespace_0d267.xml @@ -7610,7 +7589,7 @@ C++ includes: ZLimits.h // File: namespace_0d273.xml -// File: namespace_0d275.xml +// File: namespace_0d277.xml // File: namespace_0d279.xml @@ -7619,25 +7598,22 @@ C++ includes: ZLimits.h // File: namespace_0d281.xml -// File: namespace_0d283.xml +// File: namespace_0d293.xml -// File: namespace_0d295.xml +// File: namespace_0d299.xml -// File: namespace_0d301.xml - - -// File: namespace_0d305.xml +// File: namespace_0d303.xml // File: namespace_0d31.xml -// File: namespace_0d323.xml +// File: namespace_0d321.xml -// File: namespace_0d342.xml +// File: namespace_0d340.xml // File: namespace_0d37.xml @@ -8212,12 +8188,6 @@ Used by the hard sphere and by several soft sphere classes. // File: IInterferenceFunctionStrategy_8h.xml -// File: SSCAHelper_8cpp.xml - - -// File: SSCAHelper_8h.xml - - // File: SSCApproximationStrategy_8cpp.xml -- GitLab