oILAB
Loading...
Searching...
No Matches
ReciprocalLatticeVector.cpp
Go to the documentation of this file.
1/* This file is part of gbLAB.
2 *
3 * gbLAB is distributed without any warranty under the MIT License.
4 */
5
6
7#ifndef gbLAB_ReciprocalLatticeVector_cpp_
8#define gbLAB_ReciprocalLatticeVector_cpp_
9
10#include <iostream>
11#include <LatticeModule.h>
12
13namespace gbLAB
14{
15
16 template <int dim>
21
22 template <int dim>
24 {
25 return *this;
26 }
27
28 template <int dim>
30 /* init */ BaseType(VectorDimI::Zero()),
31 /* init */ lattice(lat)
32 { }
33
34 template <int dim>
36 /* init */ BaseType(LatticeCore<dim>::integerCoordinates(d, lat.latticeBasis.transpose())),
37 /* init */ lattice(lat)
38 { }
39
40 template <int dim>
42 /* init base */ BaseType(other),
43 /* init base */ lattice(lat)
44 {}
45
46 template <int dim>
48 {
49 assert(&lattice == &other.lattice && "ReciprocalLatticeVector<dim> belong to different Lattices.");
50 base() = other.base();
51 return *this;
52 }
53
54 template <int dim>
56 {
57 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
58 base() = other.base();
59 return *this;
60 }
61
62 template <int dim>
64 {
65 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
66 VectorDimI temp= static_cast<VectorDimI>(*this) + static_cast<VectorDimI>(other);
67 return ReciprocalLatticeVector<dim>(temp, lattice);
68 }
69
70 template <int dim>
72 {
73 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
74 base() += other.base();
75 return *this;
76 }
77
78 template <int dim>
80 {
81 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
82 VectorDimI temp= static_cast<VectorDimI>(*this) - static_cast<VectorDimI>(other);
83 return ReciprocalLatticeVector<dim>(temp, lattice);
84 }
85
86 template <int dim>
88 {
89 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
90 base() -= other.base();
91 return *this;
92 }
93
94 template <int dim>
96 {
97 VectorDimI temp= static_cast<VectorDimI>(*this) * scalar;
98 return ReciprocalLatticeVector<dim>(temp, lattice);
99 }
100
101 template <int dim>
103 {
104 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
105 return static_cast<VectorDimI>(*this).dot(static_cast<VectorDimI>(other));
106 }
107
108 template <int dim>
110 {
111 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
112 return dot(other.latticeVector());
113 }
114
115
116
117 template <int dim>
119 {
120 return lattice.reciprocalBasis * this->template cast<double>();
121 }
122
123
124 template <int dim>
126 {
127 assert(this->squaredNorm() > 0 && "A null ReciprocalLatticeVector cannot be used to compute planeIndexOfPoint");
128 const double hd(cartesian().dot(P));
129 return std::lround(hd);
130 }
131
132 template <int dim>
134 {
135 assert(this->squaredNorm() > 0 && "A null ReciprocalLatticeVector cannot be used to compute planeIndexOfPoint");
136 const double hd(cartesian().dot(P));
137 const IntScalarType h(std::lround(hd));
138 if (fabs(hd - h) > FLT_EPSILON)
139 {
140 std::cout << "P=" << P.transpose() << std::endl;
141 std::cout << "r=" << this->cartesian().transpose() << std::endl;
142 std::cout << "hd=" << std::setprecision(15) << std::scientific << hd << std::endl;
143 std::cout << "h=" << h << std::endl;
144 assert(0 && "P in not on a lattice plane.");
145 }
146 return h;
147 }
148
149 template <int dim>
151 {
152 assert(this->squaredNorm() > 0 && "A null ReciprocalLatticeVector cannot be used to compute planeIndexOfPoint");
153 return dot(P);
154 }
155
156
157 //Operator starts here
158 template <int dim>
163 template <int dim>
165 {
166 return L * scalar;
167 }
168
169 template<int dim> template<int dm>
170 typename std::enable_if<dm==2,LatticeDirection<dim>>::type
172 {
173 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
175 LatticeVector<dm>((VectorDimI() << 0,0).finished(), lattice));
176 }
177
178 template<int dim> template<int dm>
179 typename std::enable_if<dm==2,LatticeDirection<dim>>::type
182 LatticeVector<dm>((VectorDimI() << -(*this)(1), (*this)(0)).finished(), lattice));
183 }
184
185 template<int dim> template<int dm>
186 typename std::enable_if<dm==3,LatticeDirection<dim>>::type
188 {
189 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
190 return LatticeDirection<dim>(LatticeVector<dim>(static_cast<VectorDimI>(*this).cross(static_cast<VectorDimI>(other)), lattice));
191 }
192 template<int dim> template<int dm>
193 typename std::enable_if<dm==3,LatticeDirection<dim>>::type
195 return LatticeDirection<dm>(
196 LatticeVector<dm>((VectorDimI() << -(*this)(1), (*this)(0), 0).finished(), lattice));
197 }
198
199template class ReciprocalLatticeVector<1>;
202template class ReciprocalLatticeVector<2>;
205
206template class ReciprocalLatticeVector<3>;
213
214template class ReciprocalLatticeVector<4>;
217template class ReciprocalLatticeVector<5>;
220} // end namespace
221#endif
Lattice class.
Definition Lattice.h:34
LatticeVector class.
const Lattice< dim > & lattice
LatticeCore< dim >::VectorDimD VectorDimD
LatticeCore< dim >::VectorDimI VectorDimI
IntScalarType dot(const LatticeVector< dim > &other) const
IntScalarType closestPlaneIndexOfPoint(const VectorDimD &P) const
ReciprocalLatticeVector< dim > & operator=(const ReciprocalLatticeVector< dim > &other)
std::enable_if< dm==2, LatticeDirection< dim > >::type cross() const
IntScalarType planeIndexOfPoint(const VectorDimD &P) const
ReciprocalLatticeVector< dim > & operator+=(const ReciprocalLatticeVector< dim > &other)
ReciprocalLatticeVector(const Lattice< dim > &lat)
LatticeCore< dim >::IntScalarType IntScalarType
Eigen::Matrix< typename LatticeCore< dim >::IntScalarType, dim, 1 > BaseType
ReciprocalLatticeVector< dim > operator-(const ReciprocalLatticeVector< dim > &other) const
ReciprocalLatticeVector< dim > & operator-=(const ReciprocalLatticeVector< dim > &other)
ReciprocalLatticeVector< dim > operator+(const ReciprocalLatticeVector< dim > &other) const
ReciprocalLatticeVector< dim > operator*(const IntScalarType &scalar) const
LatticeVector< dim > operator*(const typename LatticeVector< dim >::IntScalarType &scalar, const LatticeVector< dim > &L)
LatticeDirection class.
const LatticeVector< dim > & latticeVector() const