BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
DWBAComputation.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sim/Computation/DWBAComputation.cpp
6 //! @brief Implements class DWBAComputation.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
19 #include "Resample/Flux/IFlux.h"
26 
27 namespace {
28 
29 std::vector<std::unique_ptr<const ParticleLayoutContribution>>
30 makeLayoutComputation(const std::vector<reLayout>& layouts, const SimulationOptions& options,
31  bool polarized)
32 {
33  std::vector<std::unique_ptr<const ParticleLayoutContribution>> result;
34 
35  for (const reLayout& layout : layouts)
36  result.emplace_back(new ParticleLayoutContribution(layout, options, polarized));
37 
38  return result;
39 }
40 
41 } // namespace
42 
43 
45  ProgressHandler& progress,
46  std::vector<std::unique_ptr<DiffuseElement>>::iterator begin_it,
47  std::vector<std::unique_ptr<DiffuseElement>>::iterator end_it)
48  : IComputation(re_sample, options, progress)
49  , m_begin_it(begin_it)
50  , m_end_it(end_it)
51  , m_specular_contrib(options.includeSpecular() ? new GISASSpecularContribution() : nullptr)
52  , m_roughness_contrib(m_re_sample.hasRoughness() ? new RoughMultiLayerContribution(m_re_sample)
53  : nullptr)
54  , m_layout_contribs(makeLayoutComputation(m_re_sample.layouts(), options,
55  m_re_sample.containsMagneticMaterial()))
56 {
57 }
58 
60 
61 // The normalization of the calculated scattering intensities is:
62 // For nanoparticles: rho * (scattering cross-section/scattering particle)
63 // For roughness: (scattering cross-section of area S)/S
64 // For specular peak: |R|^2 * sin(alpha_i) / solid_angle
65 // This allows them to be added and normalized together to the beam afterwards
67 {
68  for (auto it = m_begin_it; it != m_end_it; ++it) {
69  if (!m_progress->alive())
70  break;
71  std::unique_ptr<DiffuseElement>& ele = *it;
72 
73  const Fluxes fluxes_in = m_re_sample.fluxesIn(ele->getKi());
74  const Fluxes fluxes_out = m_re_sample.fluxesOut(ele->meanKf());
75  ele->setFluxes(&fluxes_in, &fluxes_out);
76 
77  for (const auto& contrib : m_layout_contribs)
78  contrib->compute(*ele);
79 
81  m_roughness_contrib->compute(*ele);
82 
84  m_specular_contrib->compute(*ele);
85 
86  stepProgress();
87  }
88 }
Defines class DWBAComputation.
Defines class DelayedProgressCounter.
Defines class DiffuseElement.
std::vector< std::unique_ptr< const IFlux > > Fluxes
Defines class GISASSpecularContribution.
Defines and implements class IFlux.
Defines class ParticleLayoutContribution.
Defines class ProgressHandler.
Defines class reLayout.
Defines class reSample.
Defines class RoughMultiLayerContribution.
Defines class SimulationOptions.
void runProtected() override
Performs a single-threaded DWBA computation for a DiffuseElements in range m_begin_it ....
const std::unique_ptr< const RoughMultiLayerContribution > m_roughness_contrib
const std::vector< std::unique_ptr< const ParticleLayoutContribution > > m_layout_contribs
const std::unique_ptr< const GISASSpecularContribution > m_specular_contrib
~DWBAComputation() override
std::vector< std::unique_ptr< DiffuseElement > >::iterator m_end_it
std::vector< std::unique_ptr< DiffuseElement > >::iterator m_begin_it
DWBAComputation(const reSample &re_sample, const SimulationOptions &options, ProgressHandler &progress, std::vector< std::unique_ptr< DiffuseElement >>::iterator begin_it, std::vector< std::unique_ptr< DiffuseElement >>::iterator end_it)
Computes the specular signal in the bin where q_parallel = 0. Used by DWBAComputation.
Interface for a single-threaded computation with given range of DiffuseElements and ProgressHandler.
Definition: IComputation.h:37
ProgressHandler * m_progress
Definition: IComputation.h:55
const reSample & m_re_sample
Definition: IComputation.h:53
void stepProgress() const
Computes the scattering contribution from one particle layout. Instances are created and used by DWBA...
Maintains information about progress of a computation.
Computes the diffuse reflection from the rough interfaces of a sample. Used by DWBAComputation.
Collect the different options for simulation.SimulationOptions.
Data structure that contains preprocessed data for a single layout.
Definition: ReLayout.h:36
Data structure that contains all the necessary data for scattering calculations.
Definition: ReSample.h:41
Fluxes fluxesIn(const R3 &k) const
Definition: ReSample.cpp:384
Fluxes fluxesOut(const R3 &k) const
Definition: ReSample.cpp:391
bool hasRoughness(const MultiLayer &sample)