diff --git a/Core/Computation/LayoutStrategyBuilder.cpp b/Core/Computation/LayoutStrategyBuilder.cpp deleted file mode 100644 index aed5f7f0b411ad35ae2ae4b714b554d9008b0c7c..0000000000000000000000000000000000000000 --- a/Core/Computation/LayoutStrategyBuilder.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file Core/Computation/LayoutStrategyBuilder.cpp -//! @brief Implements class LayoutStrategyBuilder. -//! -//! @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 "Core/Computation/LayoutStrategyBuilder.h" -#include "Base/Types/Exceptions.h" -#include "Core/Computation/ProcessedLayout.h" -#include "Sample/Aggregate/InterferenceFunctionRadialParaCrystal.h" -#include "Sample/Interference/DecouplingApproximationStrategy.h" -#include "Sample/Interference/SSCApproximationStrategy.h" - -LayoutStrategyBuilder::LayoutStrategyBuilder(const ProcessedLayout* p_layout, - const SimulationOptions& sim_params, bool polarized) - : m_layout(p_layout), m_sim_params(sim_params), m_polarized(polarized) -{ - createStrategy(); -} - -// needs class definitions => don't move to .h -LayoutStrategyBuilder::~LayoutStrategyBuilder() = default; - -IInterferenceFunctionStrategy* LayoutStrategyBuilder::releaseStrategy() -{ - return m_strategy.release(); -} - -//! Returns a new strategy object that is able to calculate the scattering for fixed k_f. -void LayoutStrategyBuilder::createStrategy() -{ - const IInterferenceFunction* p_iff = m_layout->interferenceFunction(); - if (p_iff && m_layout->numberOfSlices() > 1 && !p_iff->supportsMultilayer()) - throw std::runtime_error("LayoutStrategyBuilder::checkInterferenceFunction: " - "interference function does not support multiple layers"); - - auto p_radial_para = dynamic_cast<const InterferenceFunctionRadialParaCrystal*>(p_iff); - if (p_radial_para && p_radial_para->kappa() > 0.0) { - double kappa = p_radial_para->kappa(); - m_strategy = std::make_unique<SSCApproximationStrategy>(m_sim_params, kappa, m_polarized); - } else { - m_strategy = std::make_unique<DecouplingApproximationStrategy>(m_sim_params, m_polarized); - } - if (!m_strategy) - throw Exceptions::ClassInitializationException("Could not create appropriate strategy"); - m_strategy->init(m_layout->formFactorList(), p_iff); -} diff --git a/Core/Computation/LayoutStrategyBuilder.h b/Core/Computation/LayoutStrategyBuilder.h deleted file mode 100644 index d8534628886c599813d812cce68508f56e7479b5..0000000000000000000000000000000000000000 --- a/Core/Computation/LayoutStrategyBuilder.h +++ /dev/null @@ -1,47 +0,0 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file Core/Computation/LayoutStrategyBuilder.h -//! @brief Defines class LayoutStrategyBuilder. -//! -//! @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_CORE_COMPUTATION_LAYOUTSTRATEGYBUILDER_H -#define BORNAGAIN_CORE_COMPUTATION_LAYOUTSTRATEGYBUILDER_H - -#include "Sample/RT/SimulationOptions.h" -#include <memory> - -class IInterferenceFunction; -class IInterferenceFunctionStrategy; -class ProcessedLayout; - -//! Methods to generate a simulation strategy for a ParticleLayoutComputation. -//! @ingroup algorithms_internal - -class LayoutStrategyBuilder -{ -public: - LayoutStrategyBuilder(const ProcessedLayout* p_layout, const SimulationOptions& sim_params, - bool polarized); - - ~LayoutStrategyBuilder(); - - IInterferenceFunctionStrategy* releaseStrategy(); - -private: - void createStrategy(); - - const ProcessedLayout* m_layout; - SimulationOptions m_sim_params; - bool m_polarized; //!< polarized computation required? - std::unique_ptr<IInterferenceFunctionStrategy> m_strategy; -}; - -#endif // BORNAGAIN_CORE_COMPUTATION_LAYOUTSTRATEGYBUILDER_H diff --git a/Core/Computation/ParticleLayoutComputation.cpp b/Core/Computation/ParticleLayoutComputation.cpp index 0a0b7e0ee249736d89a5cf75f0eb8e707c950344..b47d612fbcb4182328e34e3f70be20edb95078e0 100644 --- a/Core/Computation/ParticleLayoutComputation.cpp +++ b/Core/Computation/ParticleLayoutComputation.cpp @@ -14,18 +14,48 @@ #include "Core/Computation/ParticleLayoutComputation.h" #include "Base/Pixel/SimulationElement.h" -#include "Core/Computation/LayoutStrategyBuilder.h" +#include "Base/Types/Exceptions.h" #include "Core/Computation/ProcessedLayout.h" +#include "Sample/Aggregate/InterferenceFunctionRadialParaCrystal.h" +#include "Sample/Interference/DecouplingApproximationStrategy.h" #include "Sample/Interference/IInterferenceFunctionStrategy.h" +#include "Sample/Interference/SSCApproximationStrategy.h" -ParticleLayoutComputation::ParticleLayoutComputation(const ProcessedLayout* p_layout, +namespace { + +std::unique_ptr<IInterferenceFunctionStrategy> processedInterferenceFunction( + const ProcessedLayout* layout, const SimulationOptions& sim_params, bool polarized) +{ + const IInterferenceFunction* p_iff = layout->interferenceFunction(); + if (p_iff && layout->numberOfSlices() > 1 && !p_iff->supportsMultilayer()) + throw std::runtime_error("LayoutStrategyBuilder::checkInterferenceFunction: " + "interference function does not support multiple layers"); + + auto p_radial_para = dynamic_cast<const InterferenceFunctionRadialParaCrystal*>(p_iff); + + std::unique_ptr<IInterferenceFunctionStrategy> result; + + if (p_radial_para && p_radial_para->kappa() > 0.0) { + double kappa = p_radial_para->kappa(); + result = std::make_unique<SSCApproximationStrategy>(sim_params, kappa, polarized); + } else { + result = std::make_unique<DecouplingApproximationStrategy>(sim_params, polarized); + } + if (!result) + throw Exceptions::ClassInitializationException("Could not create appropriate result"); + result->init(layout->formFactorList(), p_iff); + return result; +} + +} // namespace + +ParticleLayoutComputation::ParticleLayoutComputation(const ProcessedLayout* layout, const SimulationOptions& options, bool polarized) - : m_layout(p_layout) - , m_region_map(p_layout->regionMap()) + : m_layout(layout) + , m_region_map(layout->regionMap()) + , m_interference_function_strategy(processedInterferenceFunction(layout, options, polarized)) { - LayoutStrategyBuilder builder(p_layout, options, polarized); - m_strategy.reset(builder.releaseStrategy()); } ParticleLayoutComputation::~ParticleLayoutComputation() = default; @@ -36,7 +66,9 @@ void ParticleLayoutComputation::compute(SimulationElement& elem) const const size_t n_layers = m_layout->numberOfSlices(); if (n_layers > 1 && alpha_f < 0) return; // zero for transmission with multilayers (n>1) # TODO: support transmission GISAS - elem.addIntensity(m_strategy->evaluate(elem) * m_layout->surfaceDensity()); + + elem.addIntensity(m_interference_function_strategy->evaluate(elem) * + m_layout->surfaceDensity()); } void ParticleLayoutComputation::mergeRegionMap( diff --git a/Core/Computation/ParticleLayoutComputation.h b/Core/Computation/ParticleLayoutComputation.h index bd25b1f59d18621c4b5e4d55e2a45bfbd482d6e6..c7114bde059dbf61ad5fe035b7874cf7eec496f7 100644 --- a/Core/Computation/ParticleLayoutComputation.h +++ b/Core/Computation/ParticleLayoutComputation.h @@ -43,8 +43,8 @@ public: private: const ProcessedLayout* m_layout; - std::unique_ptr<const IInterferenceFunctionStrategy> m_strategy; const std::map<size_t, std::vector<HomogeneousRegion>> m_region_map; + std::unique_ptr<const IInterferenceFunctionStrategy> m_interference_function_strategy; }; #endif // BORNAGAIN_CORE_COMPUTATION_PARTICLELAYOUTCOMPUTATION_H diff --git a/auto/Wrap/doxygenCore.i b/auto/Wrap/doxygenCore.i index 6e68eefc69257276295e76db271f1c977866fd80..a4115d39bc1ac587a61c88b1c3f9357ac110cbfa 100644 --- a/auto/Wrap/doxygenCore.i +++ b/auto/Wrap/doxygenCore.i @@ -983,24 +983,6 @@ Returns map of fit parameter names and its current values. %feature("docstring") LabelMap ""; -// File: classLayoutStrategyBuilder.xml -%feature("docstring") LayoutStrategyBuilder " - -Methods to generate a simulation strategy for a ParticleLayoutComputation. - -C++ includes: LayoutStrategyBuilder.h -"; - -%feature("docstring") LayoutStrategyBuilder::LayoutStrategyBuilder "LayoutStrategyBuilder::LayoutStrategyBuilder(const ProcessedLayout *p_layout, const SimulationOptions &sim_params, bool polarized) -"; - -%feature("docstring") LayoutStrategyBuilder::~LayoutStrategyBuilder "LayoutStrategyBuilder::~LayoutStrategyBuilder() -"; - -%feature("docstring") LayoutStrategyBuilder::releaseStrategy "IInterferenceFunctionStrategy * LayoutStrategyBuilder::releaseStrategy() -"; - - // File: classLogMetric.xml %feature("docstring") LogMetric " @@ -2886,9 +2868,15 @@ Helper factory function to use in GISASSimulation. Depending on the type of det // File: LayoutStrategyBuilder_8cpp.xml +%feature("docstring") processedIInterferenceFunctionStrategy "IInterferenceFunctionStrategy* processedIInterferenceFunctionStrategy(const ProcessedLayout *layout, const SimulationOptions &sim_params, bool polarized) +"; // File: LayoutStrategyBuilder_8h.xml +%feature("docstring") processedInterferenceFunction "IInterferenceFunctionStrategy* processedInterferenceFunction(const ProcessedLayout *layout, const SimulationOptions &sim_params, bool polarized) + +Provides a IInterferenceFunctionStrategy for a ParticleLayoutComputation. +"; // File: MultiLayerFuncs_8cpp.xml