BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Lattice2D.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Lattice/Lattice2D.cpp
6 //! @brief Implements classes of Lattice2D family.
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/Math/Constants.h"
17 #include "Fit/Param/RealLimits.h"
18 #include <cmath>
19 
20 // ************************************************************************************************
21 // class Lattice2D
22 // ************************************************************************************************
23 
24 Lattice2D::Lattice2D(const std::vector<double>& PValues)
25  : INode(PValues)
26 {
27 }
28 
30  : m_xi(xi)
31 {
32 }
33 
35 {
36  const double sinalpha = std::sin(latticeAngle());
37  const double ainv = M_TWOPI / length1() / sinalpha;
38  const double binv = M_TWOPI / length2() / sinalpha;
39  const double xi = rotationAngle();
40  const double xialpha = xi + latticeAngle();
41 
42  return {+ainv * std::sin(xialpha), -ainv * std::cos(xialpha), -binv * std::sin(xi),
43  +binv * std::cos(xi)};
44 }
45 
46 void Lattice2D::setRotationEnabled(bool /*enabled*/) // TODO ASAP replace by generic mechanism
47 {
48  // #bapool enabling/disabling was done by register/unregister m_xi. Any equivalent
49  // implementation necessary?
50 }
51 
52 // ************************************************************************************************
53 // class BasicLattice2D
54 // ************************************************************************************************
55 
56 BasicLattice2D::BasicLattice2D(double length1, double length2, double angle, double xi)
57  : Lattice2D(xi)
58  , m_length1(length1)
59  , m_length2(length2)
60  , m_angle(angle)
61 {
62  if (m_length1 <= 0.0 || m_length2 <= 0.0)
63  throw std::runtime_error(
64  "BasicLattice2D::BasicLattice2D() -> Error. Lattice length can't be "
65  "negative or zero.");
66  RealLimits::positive().check("LatticeLength1", m_length1);
67  RealLimits::positive().check("LatticeLength2", m_length2);
68 }
69 
71 {
73 }
74 
76 {
77  return std::abs(m_length1 * m_length2 * std::sin(m_angle));
78 }
79 
80 // ************************************************************************************************
81 // class SquareLattice2D
82 // ************************************************************************************************
83 
84 SquareLattice2D::SquareLattice2D(double length, double xi)
85  : Lattice2D(xi)
86  , m_length(length)
87 {
88  if (m_length <= 0.0)
89  throw std::runtime_error(
90  "SquareLattice2D::SquareLattice2D() -> Error. Lattice length can't be "
91  "negative or zero.");
92  RealLimits::positive().check("LatticeLength", m_length);
93 }
94 
96 {
97  return new SquareLattice2D(m_length, m_xi);
98 }
99 
101 {
102  return M_PI / 2.0;
103 }
104 
106 {
107  return std::abs(m_length * m_length);
108 }
109 
110 // ************************************************************************************************
111 // class HexagonalLattice2D
112 // ************************************************************************************************
113 
114 HexagonalLattice2D::HexagonalLattice2D(double length, double xi)
115  : Lattice2D(xi)
116  , m_length(length)
117 {
118  if (m_length <= 0.0)
119  throw std::runtime_error("HexagonalLattice2D::HexagonalLattice2D() -> Error. "
120  "Lattice length can't be negative or zero.");
121  RealLimits::positive().check("LatticeLength", m_length);
122 }
123 
125 {
126  return new HexagonalLattice2D(m_length, m_xi);
127 }
128 
130 {
131  return M_TWOPI / 3.0;
132 }
133 
135 {
136  static const double sinval = std::sin(latticeAngle());
137  return std::abs(m_length * m_length * sinval);
138 }
Defines M_PI and some more mathematical constants.
#define M_TWOPI
Definition: Constants.h:54
#define M_PI
Definition: Constants.h:44
Defines classes of Lattice2D family.
Defines class RealLimits.
A two-dimensional Bravais lattice with no special symmetry.
Definition: Lattice2D.h:51
double m_length1
Definition: Lattice2D.h:70
double unitCellArea() const override
Definition: Lattice2D.cpp:75
double m_length2
Definition: Lattice2D.h:70
double m_angle
Definition: Lattice2D.h:71
BasicLattice2D * clone() const override
Definition: Lattice2D.cpp:70
BasicLattice2D(double length1, double length2, double angle, double xi)
Definition: Lattice2D.cpp:56
A two-dimensional Bravais lattice with hexagonal symmetry.
Definition: Lattice2D.h:98
double unitCellArea() const override
Definition: Lattice2D.cpp:134
HexagonalLattice2D * clone() const override
Definition: Lattice2D.cpp:124
double latticeAngle() const override
Definition: Lattice2D.cpp:129
HexagonalLattice2D(double length, double xi)
Definition: Lattice2D.cpp:114
Base class for tree-like structures containing parameterized objects.
Definition: INode.h:40
A two-dimensional Bravais lattice.
Definition: Lattice2D.h:23
double rotationAngle() const
Definition: Lattice2D.h:39
ReciprocalBases reciprocalBases() const
Definition: Lattice2D.cpp:34
virtual double latticeAngle() const =0
Lattice2D(const std::vector< double > &PValues)
Definition: Lattice2D.cpp:24
double m_xi
Definition: Lattice2D.h:46
virtual double length2() const =0
virtual double length1() const =0
void setRotationEnabled(bool enabled)
Definition: Lattice2D.cpp:46
static RealLimits positive()
Creates an object which can have only positive values (>0., zero is not included)
Definition: RealLimits.cpp:119
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
A two-dimensional Bravais lattice with square unit cell.
Definition: Lattice2D.h:76
double unitCellArea() const override
Definition: Lattice2D.cpp:105
SquareLattice2D * clone() const override
Definition: Lattice2D.cpp:95
double latticeAngle() const override
Definition: Lattice2D.cpp:100
SquareLattice2D(double length, double xi=0.0)
Definition: Lattice2D.cpp:84
double m_length
Definition: Lattice2D.h:93