Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
Lattices/ReciprocalLatticeVector.cpp
Go to the documentation of this file.
1/* This file is part of PIL, the Particle Interaction Library.
2 *
3 *
4 * MODEL is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_ReciprocalLatticeVector_cpp_
9#define model_ReciprocalLatticeVector_cpp_
10
11#include <iostream>
12#include <LatticeModule.h>
13
14namespace model
15{
16
17 template <int dim>
22
23 template <int dim>
25 {
26 return _base;
27 }
28
29 template <int dim>
31/* init */ _base(VectorDimI::Zero())
32 /* init */,lattice(lat)
33 {
36 }
37
38 template <int dim>
40 /* */ const LatticeType&lat) :
41/* init base */ _base(d2cov(d, lat))
42/* init base */,lattice(lat)
43 {
46 }
47
48template <int dim>
50 /* */ const LatticeType&lat) :
51/* init base */ _base(d)
52/* init base */,lattice(lat)
53{
55 */
58 template <int dim>
60 {
61 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
62 return ReciprocalLatticeVectorType((base() + other.base()).eval(), lattice);
63 }
64
65 template <int dim>
67 {
68 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
69 base() += other.base();
70 return *this;
71 }
72
73 template <int dim>
75 {
76 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
77 return ReciprocalLatticeVectorType((base() - other.base()).eval(), lattice);
78 }
79
80 template <int dim>
82 {
83 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
84 base() -= other.base();
85 return *this;
86 }
87
88 template <int dim>
93
94 template <int dim>
96 {
97 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
98 return base().dot(other.base());
99 }
100
101 template <int dim>
103 {
104 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
106 }
107
108 template <int dim>
110 {
111 return lattice.reciprocalBasis * base().template cast<double>();
112 }
113
114 template <int dim>
116 {
117 return 1.0 / cartesian().norm();
118 }
119
120 template <int dim>
122 {
123 const VectorDimD c(cartesian());
124 return c / c.squaredNorm();
125 }
126
127 template <int dim>
129 {
130 assert(base().squaredNorm() > 0 && "A null ReciprocalLatticeVector cannot be used to compute planeIndexOfPoint");
131 const double hd(cartesian().dot(P));
132 return std::lround(hd);
133 }
134
135 template <int dim>
137 {
138 assert(base().squaredNorm() > 0 && "A null ReciprocalLatticeVector cannot be used to compute planeIndexOfPoint");
139 const double hd(cartesian().dot(P));
140 const long int h(std::lround(hd));
141 if (fabs(hd - h) > FLT_EPSILON)
142 {
143 std::cout << "P=" << P.transpose() << std::endl;
144 std::cout << "r=" << this->cartesian().transpose() << std::endl;
145 std::cout << "hd=" << std::setprecision(15) << std::scientific << hd << std::endl;
146 std::cout << "h=" << h << std::endl;
147 throw std::runtime_error("P in not on a lattice plane.");
148 }
149 return h;
150 }
151
152 template <int dim>
154 {
155 assert(base().squaredNorm() > 0 && "A null ReciprocalLatticeVector cannot be used to compute planeIndexOfPoint");
156 return dot(P);
157 }
158
159 template <int dim>
161 const LatticeType &lat)
162 {
163 const VectorDimD nd(lat.latticeBasis.transpose() * d);
164 const VectorDimD rd(nd.array().round());
165 if ((nd - rd).norm() > roundTol)
166 {
167 std::cout << "d2cov, nd=" << nd.transpose() << std::endl;
168 std::cout << "d2cov, rd=" << rd.transpose() << std::endl;
169 throw std::runtime_error("Input vector is not a reciprocal lattice vector");
170 }
171 return rd.template cast<long int>();
172 }
173
174 template <int dim>
176 {
177 return L * scalar;
178 }
179
180 template class ReciprocalLatticeVector<3>;
181 template ReciprocalLatticeVector<3> operator*(const long int &scalar, const ReciprocalLatticeVector<3> &L);
182} // end namespace
183#endif
const MatrixDimD latticeBasis
const LatticeType & lattice
static VectorDimI d2cov(const VectorDimD &d, const LatticeType &lat)
ReciprocalLatticeVector< dim > ReciprocalLatticeVectorType
ReciprocalLatticeVectorType operator-(const ReciprocalLatticeVectorType &other) const
ReciprocalLatticeVectorType operator*(const long int &scalar) const
Eigen::Matrix< long int, dim, 1 > VectorDimI
LatticeDirectionType cross(const ReciprocalLatticeVectorType &other) const
ReciprocalLatticeVectorType & operator+=(const ReciprocalLatticeVectorType &other)
long int planeIndexOfPoint(const VectorDimD &P) const
Eigen::Matrix< double, dim, 1 > VectorDimD
Eigen::Matrix< long int, dim, 1 > BaseType
long int closestPlaneIndexOfPoint(const VectorDimD &P) const
ReciprocalLatticeVectorType operator+(const ReciprocalLatticeVectorType &other) const
ReciprocalLatticeVectorType & operator-=(const ReciprocalLatticeVectorType &other)
long int dot(const LatticeVectorType &other) const
c
Definition int_R.m:15
auto operator*(const std::shared_ptr< BilinearForm< T1, T2 > > &f, const IntegrationDomain< FE, D, Q, Rule > &dom)
auto eval(const std::shared_ptr< T > &t)
REAL * h