File: Lattice2D.cpp

package info (click to toggle)
bornagain 23.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,936 kB
  • sloc: cpp: 423,131; python: 40,997; javascript: 11,167; awk: 630; sh: 318; ruby: 173; xml: 130; makefile: 51; ansic: 24
file content (158 lines) | stat: -rw-r--r-- 4,453 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Sample/Lattice/Lattice2D.cpp
//! @brief     Implements classes of Lattice2D family.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#include "Sample/Lattice/Lattice2D.h"
#include <cmath>
#include <numbers>

using std::numbers::pi;

//  ************************************************************************************************
//  class Lattice2D
//  ************************************************************************************************

Lattice2D::Lattice2D(const std::vector<double>& PValues)
    : INode(PValues)
{
}

Lattice2D::Lattice2D(double xi)
    : m_xi(xi)
{
}

ReciprocalBases Lattice2D::reciprocalBases() const
{
    const double sinalpha = std::sin(latticeAngle());
    const double ainv = (2 * pi) / length1() / sinalpha;
    const double binv = (2 * pi) / length2() / sinalpha;
    const double xi = rotationAngle();
    const double xialpha = xi + latticeAngle();

    return {+ainv * std::sin(xialpha), -ainv * std::cos(xialpha), -binv * std::sin(xi),
            +binv * std::cos(xi)};
}

void Lattice2D::setRotationEnabled(bool /*enabled*/) // TODO ASAP replace by generic mechanism
{
    // #bapool enabling/disabling was done by register/unregister m_xi. Any equivalent
    // implementation necessary?
}

//  ************************************************************************************************
//  class BasicLattice2D
//  ************************************************************************************************

BasicLattice2D::BasicLattice2D(double length1, double length2, double angle, double xi)
    : Lattice2D(xi)
    , m_length1(length1)
    , m_length2(length2)
    , m_angle(angle)
{
    validateOrThrow();
}

BasicLattice2D* BasicLattice2D::clone() const
{
    return new BasicLattice2D(m_length1, m_length2, m_angle, m_xi);
}

double BasicLattice2D::unitCellArea() const
{
    return std::abs(m_length1 * m_length2 * std::sin(m_angle));
}

std::string BasicLattice2D::validate() const
{
    std::vector<std::string> errs;
    requestGt0(errs, m_length1, "length1");
    requestGt0(errs, m_length2, "length2");
    if (!errs.empty())
        return jointError(errs);
    m_validated = true;
    return "";
}

//  ************************************************************************************************
//  class SquareLattice2D
//  ************************************************************************************************

SquareLattice2D::SquareLattice2D(double length, double xi)
    : Lattice2D(xi)
    , m_length(length)
{
    validateOrThrow();
}

SquareLattice2D* SquareLattice2D::clone() const
{
    return new SquareLattice2D(m_length, m_xi);
}

double SquareLattice2D::latticeAngle() const
{
    return pi / 2.0;
}

double SquareLattice2D::unitCellArea() const
{
    return std::abs(m_length * m_length);
}

std::string SquareLattice2D::validate() const
{
    std::vector<std::string> errs;
    requestGt0(errs, m_length, "length");
    if (!errs.empty())
        return jointError(errs);
    m_validated = true;
    return "";
}

//  ************************************************************************************************
//  class HexagonalLattice2D
//  ************************************************************************************************

HexagonalLattice2D::HexagonalLattice2D(double length, double xi)
    : Lattice2D(xi)
    , m_length(length)
{
    validateOrThrow();
}

HexagonalLattice2D* HexagonalLattice2D::clone() const
{
    return new HexagonalLattice2D(m_length, m_xi);
}

double HexagonalLattice2D::latticeAngle() const
{
    return (2 * pi) / 3.0;
}

double HexagonalLattice2D::unitCellArea() const
{
    static const double sinval = std::sin(latticeAngle());
    return std::abs(m_length * m_length * sinval);
}

std::string HexagonalLattice2D::validate() const
{
    std::vector<std::string> errs;
    requestGt0(errs, m_length, "length");
    if (!errs.empty())
        return jointError(errs);
    m_validated = true;
    return "";
}