diff --git a/Core/Algorithms/inc/LayerStrategyBuilder.h b/Core/Algorithms/inc/LayerStrategyBuilder.h index 0cefcbb7323681a06a9b17c190f6c6cf14f47578..717abd05ff54c2979004737d2e254a265587cdf1 100644 --- a/Core/Algorithms/inc/LayerStrategyBuilder.h +++ b/Core/Algorithms/inc/LayerStrategyBuilder.h @@ -70,12 +70,6 @@ private: const ParticleInfo *p_particle_info, const IMaterial *p_ambient_material, complex_t factor) const; - //! Decorates the given formfactor with a scalar dwba formfactor - IFormFactor *createDWBAScalarFormFactor(IFormFactor *p_form_factor, - double depth) const; - //! Decorates the given formfactor with a matrix dwba formfactor - IFormFactor *createDWBAMatrixFormFactor(IFormFactor *p_form_factor, - double depth) const; SafePointerVector<FormFactorInfo> m_ff_infos; SafePointerVector<IInterferenceFunction> m_ifs; diff --git a/Core/Algorithms/src/DiffuseDWBASimulation.cpp b/Core/Algorithms/src/DiffuseDWBASimulation.cpp index 76c3b17696bbc2bdeaed63d70a5be6818497d605..8268520812f6746fa9b47931ded271c2437e7816 100644 --- a/Core/Algorithms/src/DiffuseDWBASimulation.cpp +++ b/Core/Algorithms/src/DiffuseDWBASimulation.cpp @@ -90,18 +90,24 @@ void DiffuseDWBASimulation::initDiffuseFormFactorTerms( double depth = p_diff_info->getDepth() - j*p_diff_info->getHeightRange()/(nbr_heights-1.0); std::vector<IFormFactor*> form_factors; - p_diff_info->getParticle()->getSimpleFormFactor()->createDistributedFormFactors( - form_factors, p_diffuse_term->m_probabilities, - samples_per_particle); + p_diff_info->getParticle()->getSimpleFormFactor() + ->createDistributedFormFactors( + form_factors, p_diffuse_term->m_probabilities, + samples_per_particle); for (size_t ff_index=0; ff_index<form_factors.size(); ++ff_index) { p_particle->setSimpleFormFactor(form_factors[ff_index]); - IFormFactor *ff_particle = p_particle->createFormFactor( + IFormFactor *p_ff_particle = p_particle->createFormFactor( wavevector_scattering_factor); - FormFactorDWBAConstZ *p_dwba_z = - new FormFactorDWBAConstZ(ff_particle, depth); - p_dwba_z->setSpecularInfo(*mp_specular_info); - - p_diffuse_term->m_form_factors.push_back(p_dwba_z); + IFormFactor *p_dwba_ff(p_ff_particle); + if (checkPolarizationPresent()) { + p_dwba_ff = FormFactorTools::createDWBAMatrixFormFactor( + p_ff_particle, *mp_specular_info, depth); + } + else { + p_dwba_ff = FormFactorTools::createDWBAScalarFormFactor( + p_ff_particle, *mp_specular_info, depth); + } + p_diffuse_term->m_form_factors.push_back(p_dwba_ff); } terms.push_back(p_diffuse_term); } diff --git a/Core/Algorithms/src/LayerStrategyBuilder.cpp b/Core/Algorithms/src/LayerStrategyBuilder.cpp index f25af31d227ac853e6a6cbcf8dc3b6c78c2d636e..a63d238a590dca80ea99962a1fa3b4b1bfe60ecc 100644 --- a/Core/Algorithms/src/LayerStrategyBuilder.cpp +++ b/Core/Algorithms/src/LayerStrategyBuilder.cpp @@ -20,6 +20,7 @@ #include "InterferenceFunctions.h" #include "InterferenceFunctionStrategies.h" #include "FormFactors.h" +#include "FormFactorTools.h" #include "PositionParticleInfo.h" #include <cmath> @@ -163,10 +164,12 @@ FormFactorInfo *LayerStrategyBuilder::createFormFactorInfo( assert(mp_specular_info); double depth = p_particle_info->getDepth(); if (requiresMatrixFFs()) { - p_ff_framework = createDWBAMatrixFormFactor(p_ff_particle, depth); + p_ff_framework = FormFactorTools::createDWBAMatrixFormFactor( + p_ff_particle, *mp_specular_info, depth); } else { - p_ff_framework = createDWBAScalarFormFactor(p_ff_particle, depth); + p_ff_framework = FormFactorTools::createDWBAScalarFormFactor( + p_ff_particle, *mp_specular_info, depth); } break; } @@ -186,29 +189,6 @@ FormFactorInfo *LayerStrategyBuilder::createFormFactorInfo( return p_result; } -IFormFactor* LayerStrategyBuilder::createDWBAScalarFormFactor( - IFormFactor* p_form_factor, double depth) const -{ - FormFactorDWBAConstZ *p_result = - new FormFactorDWBAConstZ(p_form_factor, depth); - p_result->setSpecularInfo(*mp_specular_info); - return p_result; -} - -IFormFactor* LayerStrategyBuilder::createDWBAMatrixFormFactor( - IFormFactor* p_form_factor, double depth) const -{ - FormFactorDWBAPol *p_result(0); - if (depth) { - p_result = new FormFactorDWBAPolConstZ(p_form_factor, depth); - } - else { - p_result = new FormFactorDWBAPol(p_form_factor); - } - p_result->setSpecularInfo(*mp_specular_info); - return p_result; -} - // ============================================================================= // Implementation of FormFactorInfo // ============================================================================= diff --git a/Core/FormFactors/inc/FormFactorTools.h b/Core/FormFactors/inc/FormFactorTools.h new file mode 100644 index 0000000000000000000000000000000000000000..4445d1a10d695d780cdd84677344a12b863484be --- /dev/null +++ b/Core/FormFactors/inc/FormFactorTools.h @@ -0,0 +1,37 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file FormFactorTools.h +//! @brief Defines global functions that facilitate IFormFactor handling. +//! +//! @homepage http://apps.jcns.fz-juelich.de/BornAgain +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2013 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#ifndef FORMFACTORTOOLS_H_ +#define FORMFACTORTOOLS_H_ + +#include "IFormFactor.h" + +class LayerSpecularInfo; + +namespace FormFactorTools { + +//! Decorates the given formfactor with a scalar dwba formfactor and returns +//! this form factor +IFormFactor* createDWBAScalarFormFactor(IFormFactor* p_form_factor, + const LayerSpecularInfo &specular_info, double depth) const + +//! Decorates the given formfactor with a matrix dwba formfactor and returns +//! this form factor +IFormFactor* createDWBAMatrixFormFactor(IFormFactor* p_form_factor, + const LayerSpecularInfo &specular_info, double depth) const +} + + +#endif /* FORMFACTORTOOLS_H_ */ diff --git a/Core/FormFactors/src/FormFactorTools.cpp b/Core/FormFactors/src/FormFactorTools.cpp new file mode 100644 index 0000000000000000000000000000000000000000..aaa94d99f5814e4586c73cf7f8a42c00fb195cb3 --- /dev/null +++ b/Core/FormFactors/src/FormFactorTools.cpp @@ -0,0 +1,41 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file FormFactorTools.cpp +//! @brief Defines class . +//! +//! @homepage http://apps.jcns.fz-juelich.de/BornAgain +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2013 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#include "FormFactorTools.h" + +IFormFactor* FormFactorTools::createDWBAScalarFormFactor( + IFormFactor* p_form_factor, const LayerSpecularInfo& specular_info, + double depth) const +{ + FormFactorDWBAConstZ *p_result = + new FormFactorDWBAConstZ(p_form_factor, depth); + p_result->setSpecularInfo(specular_info); + return p_result; +} + +IFormFactor* FormFactorTools::createDWBAMatrixFormFactor( + IFormFactor* p_form_factor, const LayerSpecularInfo& specular_info, + double depth) const +{ + FormFactorDWBAPol *p_result(0); + if (depth) { + p_result = new FormFactorDWBAPolConstZ(p_form_factor, depth); + } + else { + p_result = new FormFactorDWBAPol(p_form_factor); + } + p_result->setSpecularInfo(specular_info); + return p_result; +}