BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
IInterference.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Aggregate/IInterference.cpp
6 //! @brief Implements the interface class IInterference.
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 "Fit/Param/RealLimits.h"
17 #include <algorithm>
18 #include <stdexcept>
19 
20 IInterference::IInterference(const std::vector<double>& PValues)
21  : INode(PValues)
22 {
23  RealLimits::nonnegative().check("PositionVariance", m_position_var);
24 }
25 
26 IInterference::IInterference(double position_var)
27  : m_position_var(position_var)
28 {
29  RealLimits::nonnegative().check("PositionVariance", m_position_var);
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 // Interference2DSuperLattice for such a case.
35 double IInterference::structureFactor(const R3 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("IInterference::setPositionVariance: "
44  "variance should be positive.");
45  m_position_var = var;
46 }
47 
48 double IInterference::DWfactor(R3 q) const
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 IInterference::iff_no_inner(const R3 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 IInterference.
Defines class RealLimits.
double DWfactor(R3 q) const
structureFactors the Debye-Waller factor for a given wavevector transfer
virtual bool supportsMultilayer() const
Indicates if this interference function can be used with a sample (DWBA mode)
Definition: IInterference.h:47
double m_position_var
Definition: IInterference.h:53
virtual double structureFactor(R3 q, double outer_iff=1.0) const
The interference function for a given wavevector transfer.
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(R3 q, double outer_iff) const
Calculates the structure factor in the absence of extra inner structure.
virtual double iff_without_dw(R3 q) const =0
Calculates the structure factor without Debye-Waller factor.
IInterference(const std::vector< double > &PValues)
Base class for tree-like structures containing parameterized objects.
Definition: INode.h:40
void check(const std::string &name, double value) const
Throws if value is outside limits. Parameter 'name' is for exception message.
Definition: RealLimits.cpp:170
static RealLimits nonnegative()
Creates an object which can have only positive values with 0. included.
Definition: RealLimits.cpp:124