BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IInterferenceFunction.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/Aggregate/IInterferenceFunction.cpp
6 //! @brief Implements the interface class IInterferenceFunction.
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 
17 #include <algorithm>
18 #include <stdexcept>
19 
21  const std::vector<double>& PValues)
22  : ISample(meta, PValues)
23 {
24  registerParameter("PositionVariance", &m_position_var).setUnit("nm^2").setNonnegative();
25 }
26 
27 IInterferenceFunction::IInterferenceFunction(double position_var) : m_position_var(position_var)
28 {
29  registerParameter("PositionVariance", &m_position_var).setUnit("nm^2").setNonnegative();
30 }
31 
32 // Default implementation of evaluate assumes no inner structure
33 // It is only to be overriden in case of the presence of such inner structure. See for example
34 // InterferenceFunction2DSuperLattice for such a case.
35 double IInterferenceFunction::evaluate(const kvector_t q, double outer_iff) const
36 {
37  return iff_no_inner(q, outer_iff);
38 }
39 
41 {
42  if (var < 0.0)
43  throw std::runtime_error("IInterferenceFunction::setPositionVariance: "
44  "variance should be positive.");
45  m_position_var = var;
46 }
47 
49 {
50  // remove z component for two dimensional interference functions:
51  if (supportsMultilayer())
52  q.setZ(0.0);
53  return std::exp(-q.mag2() * m_position_var);
54 }
55 
56 double IInterferenceFunction::iff_no_inner(const kvector_t q, double outer_iff) const
57 {
58  return DWfactor(q) * (iff_without_dw(q) * outer_iff - 1.0) + 1.0;
59 }
Defines and implements the interface class IInterferenceFunction.
Defines class RealParameter.
double mag2() const
Returns magnitude squared of the vector.
void setZ(const T &a)
Sets z-component in cartesian coordinate system.
Definition: BasicVector3D.h:75
double DWfactor(kvector_t q) const
Evaluates the Debye-Waller factor for a given wavevector transfer.
virtual bool supportsMultilayer() const
Indicates if this interference function can be used with a multilayer (DWBA mode)
void setPositionVariance(double var)
Sets the variance of the position for the calculation of the DW factor It is defined as the variance ...
double iff_no_inner(const kvector_t q, double outer_iff) const
Calculates the structure factor in the absence of extra inner structure.
virtual double evaluate(const kvector_t q, double outer_iff=1.0) const
Evaluates the interference function for a given wavevector transfer.
virtual double iff_without_dw(const kvector_t q) const =0
Calculates the structure factor without Debye-Waller factor.
IInterferenceFunction(const NodeMeta &meta, const std::vector< double > &PValues)
RealParameter & registerParameter(const std::string &name, double *parpointer)
Pure virtual base class for sample components and properties related to scattering.
Definition: ISample.h:28
RealParameter & setNonnegative()
RealParameter & setUnit(const std::string &name)
Metadata of one model node.
Definition: INode.h:37