BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
IFormFactor.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Particle/IFormFactor.cpp
6 //! @brief Implements interface class IFormFactor.
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/Py/PyFmt.h"
17 #include "Base/Util/StringUtils.h"
21 #include "Sample/Shapes/IShape3D.h"
22 #include <stdexcept>
23 
24 IFormFactor::IFormFactor() = default;
25 
26 IFormFactor::IFormFactor(const std::vector<double>& PValues)
27  : ISampleNode(PValues)
28 {
29 }
30 
31 IFormFactor::~IFormFactor() = default;
32 
33 std::string IFormFactor::shapeName() const
34 {
35  if (className().substr(0, 10) == "FormFactor")
36  return className().substr(10);
37  return className();
38 }
39 
40 complex_t IFormFactor::theFF(const WavevectorInfo& wavevectors) const
41 {
42  return formfactor_at_bottom(wavevectors.getQ());
43 }
44 
46 {
47  return formfactor_pol(wavevectors.getQ());
48 }
49 
50 double IFormFactor::bottomZ(const IRotation* rotation) const
51 {
52  if (!m_shape3D)
53  throw std::runtime_error("Bug: Form factor has no m_shape3D, cannot compute bottom z");
54  return PolyhedralUtil::BottomZ(m_shape3D->vertices(), rotation);
55 }
56 
57 double IFormFactor::topZ(const IRotation* rotation) const
58 {
59  if (!m_shape3D)
60  throw std::runtime_error("Bug: Form factor has no m_shape3D, cannot compute top z");
61  return PolyhedralUtil::TopZ(m_shape3D->vertices(), rotation);
62 }
63 
64 bool IFormFactor::canSliceAnalytically(const IRotation* rotation) const
65 {
66  return !rotation || rotation->zInvariant();
67 }
68 
69 std::string IFormFactor::pythonConstructor() const
70 {
71  std::vector<std::pair<double, std::string>> arguments;
72  for (size_t i = 0; i < parDefs().size(); i++)
73  arguments.emplace_back(m_P[i], parDefs()[i].unit);
74 
75  return Py::Fmt::printFunction(className(), arguments);
76 }
77 
79 {
81 }
82 
83 double IFormFactor::volume() const
84 {
85  return std::abs(formfactor_at_bottom(C3()));
86 }
Defines a few helper functions.
Defines interface IDecoratableBorn.
Defines interface IShape3D.
Defines interface IDecoratableBorn.
Defines namespace pyfmt.
Defines IRotation classes.
Defines WavevectorInfo.
virtual SpinMatrix thePolFF(const WavevectorInfo &wavevectors) const
Definition: IFormFactor.cpp:45
virtual std::string pythonConstructor() const
Creates the Python constructor of this class (or derived classes)
Definition: IFormFactor.cpp:69
virtual double bottomZ(const IRotation *rotation) const
Definition: IFormFactor.cpp:50
virtual complex_t formfactor_at_bottom(C3 q) const =0
virtual SpinMatrix formfactor_pol(C3 q) const
Returns scattering amplitude for complex scattering wavevector q=k_i-k_f in case of matrix interactio...
Definition: IFormFactor.cpp:78
~IFormFactor() override
virtual double topZ(const IRotation *rotation) const
Definition: IFormFactor.cpp:57
virtual bool canSliceAnalytically(const IRotation *rot) const
Default implementation only allows rotations along z-axis.
Definition: IFormFactor.cpp:64
virtual complex_t theFF(const WavevectorInfo &wavevectors) const
Definition: IFormFactor.cpp:40
std::unique_ptr< IShape3D > m_shape3D
IShape3D object, used to retrieve vertices (which may be approximate in the case of round shapes)....
Definition: IFormFactor.h:74
std::string shapeName() const
Definition: IFormFactor.cpp:33
virtual double volume() const
Definition: IFormFactor.cpp:83
virtual std::vector< ParaMeta > parDefs() const
Returns the parameter definitions, to be hard-coded in each leaf class.
Definition: INode.h:51
std::vector< double > m_P
Definition: INode.h:63
virtual std::string className() const =0
Returns the class name, to be hard-coded in each leaf class that inherits from INode.
Abstract base class for rotations.
Definition: Rotations.h:29
bool zInvariant() const
Definition: Rotations.cpp:52
Abstract base class for sample components and properties related to scattering.
Definition: ISampleNode.h:27
static SpinMatrix One()
Definition: SpinMatrix.cpp:36
Holds all wavevector information relevant for calculating form factors.
C3 getQ() const
double BottomZ(const std::vector< R3 > &vertices, const IRotation *rotation)
Calculates the z-coordinate of the lowest vertex after rotation.
double TopZ(const std::vector< R3 > &vertices, const IRotation *rotation)
Calculates the z-coordinate of the highest vertex after rotation.
std::string printFunction(const std::string &name, const std::vector< std::pair< double, std::string >> &arguments)
Print a function in the form "<name>(<arguments>)". arguments will be processed by printArguments(),...
Definition: PyFmt.cpp:168