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 "../../include/Lattices/LatticeModule.h"
11#include <iostream>
12
13namespace oILAB {
14
15template <int dim>
18 return *this;
19 }
20
21 template <int dim>
23 {
24 return *this;
25 }
26
27 template <int dim>
29 /* init */ BaseType(VectorDimI::Zero()),
30 /* init */ lattice(lat)
31 { }
32
33 template <int dim>
35 /* init */ BaseType(LatticeCore<dim>::integerCoordinates(d, lat.latticeBasis.transpose())),
36 /* init */ lattice(lat)
37 { }
38
39 template <int dim>
41 /* init base */ BaseType(other),
42 /* init base */ lattice(lat)
43 {}
44
45 template <int dim>
47 {
48 assert(&lattice == &other.lattice && "ReciprocalLatticeVector<dim> belong to different Lattices.");
49 base() = other.base();
50 return *this;
51 }
52
53 template <int dim>
55 {
56 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
57 base() = other.base();
58 return *this;
59 }
60
61 template <int dim>
63 {
64 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
65 VectorDimI temp= static_cast<VectorDimI>(*this) + static_cast<VectorDimI>(other);
66 return ReciprocalLatticeVector<dim>(temp, lattice);
67 }
68
69 template <int dim>
71 {
72 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
73 base() += other.base();
74 return *this;
75 }
76
77 template <int dim>
79 {
80 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
81 VectorDimI temp= static_cast<VectorDimI>(*this) - static_cast<VectorDimI>(other);
82 return ReciprocalLatticeVector<dim>(temp, lattice);
83 }
84
85 template <int dim>
87 {
88 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
89 base() -= other.base();
90 return *this;
91 }
92
93 template <int dim>
95 {
96 VectorDimI temp= static_cast<VectorDimI>(*this) * scalar;
97 return ReciprocalLatticeVector<dim>(temp, lattice);
98 }
99
100 template <int dim>
102 {
103 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
104 return static_cast<VectorDimI>(*this).dot(static_cast<VectorDimI>(other));
105 }
106
107 template <int dim>
109 {
110 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
111 return dot(other.latticeVector());
112 }
113
114
115
116 template <int dim>
118 {
119 return lattice.reciprocalBasis * this->template cast<double>();
120 }
121
122
123 template <int dim>
125 {
126 assert(this->squaredNorm() > 0 && "A null ReciprocalLatticeVector cannot be used to compute planeIndexOfPoint");
127 const double hd(cartesian().dot(P));
128 return std::lround(hd);
129 }
130
131 template <int dim>
133 {
134 assert(this->squaredNorm() > 0 && "A null ReciprocalLatticeVector cannot be used to compute planeIndexOfPoint");
135 const double hd(cartesian().dot(P));
136 const IntScalarType h(std::lround(hd));
137 if (fabs(hd - h) > FLT_EPSILON)
138 {
139 std::cout << "P=" << P.transpose() << std::endl;
140 std::cout << "r=" << this->cartesian().transpose() << std::endl;
141 std::cout << "hd=" << std::setprecision(15) << std::scientific << hd << std::endl;
142 std::cout << "h=" << h << std::endl;
143 assert(0 && "P in not on a lattice plane.");
144 }
145 return h;
146 }
147
148 template <int dim>
150 {
151 assert(this->squaredNorm() > 0 && "A null ReciprocalLatticeVector cannot be used to compute planeIndexOfPoint");
152 return dot(P);
153 }
154
155
156 //Operator starts here
157 template <int dim>
162 template <int dim>
164 {
165 return L * scalar;
166 }
167
168 template<int dim> template<int dm>
169 typename std::enable_if<dm==2,LatticeDirection<dim>>::type
171 {
172 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
174 LatticeVector<dm>((VectorDimI() << 0,0).finished(), lattice));
175 }
176
177 template<int dim> template<int dm>
178 typename std::enable_if<dm==2,LatticeDirection<dim>>::type
181 LatticeVector<dm>((VectorDimI() << -(*this)(1), (*this)(0)).finished(), lattice));
182 }
183
184 template<int dim> template<int dm>
185 typename std::enable_if<dm==3,LatticeDirection<dim>>::type
187 {
188 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
189 return LatticeDirection<dim>(LatticeVector<dim>(static_cast<VectorDimI>(*this).cross(static_cast<VectorDimI>(other)), lattice));
190 }
191 template<int dim> template<int dm>
192 typename std::enable_if<dm==3,LatticeDirection<dim>>::type
194 return LatticeDirection<dm>(
195 LatticeVector<dm>((VectorDimI() << -(*this)(1), (*this)(0), 0).finished(), lattice));
196 }
197
198template class ReciprocalLatticeVector<1>;
201template class ReciprocalLatticeVector<2>;
204
205template class ReciprocalLatticeVector<3>;
212
213template class ReciprocalLatticeVector<4>;
216template class ReciprocalLatticeVector<5>;
219} // namespace oILAB
220#endif
Lattice class.
Definition Lattice.h:31
LatticeVector class.
const Lattice< dim > & lattice
LatticeCore< dim >::VectorDimI VectorDimI
IntScalarType closestPlaneIndexOfPoint(const VectorDimD &P) const
LatticeCore< dim >::VectorDimD VectorDimD
ReciprocalLatticeVector< dim > & operator+=(const ReciprocalLatticeVector< dim > &other)
ReciprocalLatticeVector< dim > operator*(const IntScalarType &scalar) const
ReciprocalLatticeVector< dim > operator-(const ReciprocalLatticeVector< dim > &other) const
ReciprocalLatticeVector< dim > operator+(const ReciprocalLatticeVector< dim > &other) const
std::enable_if< dm==2, LatticeDirection< dim > >::type cross() const
IntScalarType dot(const LatticeVector< dim > &other) const
ReciprocalLatticeVector< dim > & operator-=(const ReciprocalLatticeVector< dim > &other)
IntScalarType planeIndexOfPoint(const VectorDimD &P) const
ReciprocalLatticeVector< dim > & operator=(const ReciprocalLatticeVector< dim > &other)
Eigen::Matrix< typename LatticeCore< dim >::IntScalarType, dim, 1 > BaseType
ReciprocalLatticeVector(const Lattice< dim > &lat)
LatticeCore< dim >::IntScalarType IntScalarType
LatticeVector< dim > operator*(const typename LatticeVector< dim >::IntScalarType &scalar, const LatticeVector< dim > &L)
LatticeDirection class.
const LatticeVector< dim > & latticeVector() const