BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
FormFactorWeighted.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Particle/FormFactorWeighted.cpp
6 //! @brief Implements class FormFactorWeighted.
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 
16 #include "Base/Utils/Algorithms.h"
17 
19 {
20  setName("FormFactorWeighted");
21 }
22 
24 {
25  for (size_t index = 0; index < m_form_factors.size(); ++index)
26  delete m_form_factors[index];
27 }
28 
30 {
31  FormFactorWeighted* result = new FormFactorWeighted();
32  for (size_t index = 0; index < m_form_factors.size(); ++index)
33  result->addFormFactor(*m_form_factors[index], m_weights[index]);
34  return result;
35 }
36 
38 {
39  double result{0.0};
40  for (size_t index = 0; index < m_form_factors.size(); ++index)
41  result += m_weights[index] * m_form_factors[index]->radialExtension();
42  return result;
43 }
44 
45 double FormFactorWeighted::bottomZ(const IRotation& rotation) const
46 {
47  if (m_form_factors.empty())
48  throw std::runtime_error("FormFactorWeighted::bottomZ() -> Error: "
49  "'this' contains no form factors.");
50  return algo::min_value(m_form_factors.begin(), m_form_factors.end(),
51  [&rotation](IFormFactor* ff) { return ff->bottomZ(rotation); });
52 }
53 
54 double FormFactorWeighted::topZ(const IRotation& rotation) const
55 {
56  if (m_form_factors.empty())
57  throw std::runtime_error("FormFactorWeighted::topZ() -> Error: "
58  "'this' contains no form factors.");
59  return algo::max_value(m_form_factors.begin(), m_form_factors.end(),
60  [&rotation](IFormFactor* ff) { return ff->topZ(rotation); });
61 }
62 
63 void FormFactorWeighted::addFormFactor(const IFormFactor& form_factor, double weight)
64 {
65  m_form_factors.push_back(form_factor.clone());
66  m_weights.push_back(weight);
67 }
68 
70 {
71  for (size_t index = 0; index < m_form_factors.size(); ++index)
73 }
74 
76 {
77  complex_t result(0.0, 0.0);
78  for (size_t index = 0; index < m_form_factors.size(); ++index)
79  result += m_weights[index] * m_form_factors[index]->evaluate(wavevectors);
80  return result;
81 }
82 
83 Eigen::Matrix2cd FormFactorWeighted::evaluatePol(const WavevectorInfo& wavevectors) const
84 {
85  Eigen::Matrix2cd result = Eigen::Matrix2cd::Zero();
86  for (size_t index = 0; index < m_form_factors.size(); ++index)
87  result += m_weights[index] * m_form_factors[index]->evaluatePol(wavevectors);
88  return result;
89 }
Defines and implements namespace algo with some algorithms.
std::complex< double > complex_t
Definition: Complex.h:20
Defines class FormFactorWeighted.
Coherent sum of different scalar IFormFactors with different weights.
void setAmbientMaterial(const Material &material) override
Passes the material in which this particle is embedded.
double radialExtension() const override
Returns the (approximate in some cases) radial size of the particle of this form factor's shape.
complex_t evaluate(const WavevectorInfo &wavevectors) const override
Returns scattering amplitude for complex wavevectors ki, kf.
FormFactorWeighted * clone() const override
Returns a clone of this ISampleNode object.
Eigen::Matrix2cd evaluatePol(const WavevectorInfo &wavevectors) const override
Calculates and returns a polarized form factor calculation in DWBA.
void addFormFactor(const IFormFactor &form_factor, double weight=1.0)
std::vector< IFormFactor * > m_form_factors
double topZ(const IRotation &rotation) const override
Returns the z-coordinate of the lowest point in this shape after a given rotation.
std::vector< double > m_weights
double bottomZ(const IRotation &rotation) const override
Returns the z-coordinate of the lowest point in this shape after a given rotation.
Abstract base class for all form factors.
Definition: IFormFactor.h:36
IFormFactor * clone() const override=0
Returns a clone of this ISampleNode object.
void setName(const std::string &name)
Abstract base class for rotations.
Definition: Rotations.h:28
virtual const Material * material() const
Returns nullptr, unless overwritten to return a specific material.
Definition: ISampleNode.h:37
A wrapper for underlying material implementation.
Definition: Material.h:29
Holds all wavevector information relevant for calculating form factors.
double max_value(const Iterator &begin, const Iterator &end, const Evaluator &evaluate)
Returns the maximum value of function evaluate as applied to the elements of an iterator range.
Definition: Algorithms.h:69
double min_value(const Iterator &begin, const Iterator &end, const Evaluator &evaluate)
Returns the minimum value of function evaluate as applied to the elements of an iterator range.
Definition: Algorithms.h:58