Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
Lattices_NEW/ReciprocalLatticeVector.cpp
Go to the documentation of this file.
1/* This file is part of model.
2 *
3 * MoDELib is distributed without any warranty under the MIT License.
4 */
5
6
7#ifndef model_ReciprocalLatticeVector_cpp_
8#define model_ReciprocalLatticeVector_cpp_
9
10#include <iostream>
11#include <LatticeModule.h>
12
13namespace model
14{
15
16 template <int dim>
17 typename ReciprocalLatticeVectorBase<dim>::BaseType& ReciprocalLatticeVectorBase<dim>::base()
18 {
19 return *this;
20 }
21
22 template <int dim>
23 const typename ReciprocalLatticeVectorBase<dim>::BaseType& ReciprocalLatticeVectorBase<dim>::base() const
24 {
25 return *this;
26 }
27
28 template <int dim>
30 /* init */ BaseType(VectorDimI::Zero()),
31 /* init */ lattice(lat)
33 {
36 }
37
38 template <int dim>
40 /* */ const Lattice<dim> &lat) :
41 /* init */ BaseType(LatticeCore<dim>::integerCoordinates(d, lat.latticeBasis.transpose())),
42 /* init */ lattice(lat)
43 {
45 */
46 }
48 template <int dim>
50 {
51 assert(&lattice == &other.lattice && "ReciprocalLatticeVectorBase<dim> belong to different Lattices.");
52 base() = other.base();
53 return *this;
54 }
56 template <int dim>
58 {
59 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
60 base() = other.base();
61 return *this;
62 }
63
64 template <int dim>
66 {
67 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
68 return ReciprocalLatticeVectorBase<dim>(static_cast<VectorDimI>(*this) + static_cast<VectorDimI>(other), lattice);
69 }
70
71 template <int dim>
73 {
74 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
75 base() += other.base();
76 return *this;
77 }
78
79 template <int dim>
81 {
82 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
83 return ReciprocalLatticeVectorBase<dim>(static_cast<VectorDimI>(*this) - static_cast<VectorDimI>(other), 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>
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
108
109 template <int dim>
111 {
112 return lattice.reciprocalBasis * this->template cast<double>();
113 }
114
115 template <int dim>
117 {
118 return 1.0 / cartesian().norm();
119 }
120
121 template <int dim>
127
128 template <int dim>
130 {
131 assert(this->squaredNorm() > 0 && "A null ReciprocalLatticeVector cannot be used to compute planeIndexOfPoint");
132 const double hd(cartesian().dot(P));
133 return std::lround(hd);
134 }
135
136 template <int dim>
138 {
139 assert(this->squaredNorm() > 0 && "A null ReciprocalLatticeVector cannot be used to compute planeIndexOfPoint");
140 const double hd(cartesian().dot(P));
141 const IntScalarType h(std::lround(hd));
142 if (fabs(hd - h) > FLT_EPSILON)
143 {
144 std::cout << "P=" << P.transpose() << std::endl;
145 std::cout << "r=" << this->cartesian().transpose() << std::endl;
146 std::cout << "hd=" << std::setprecision(15) << std::scientific << hd << std::endl;
147 std::cout << "h=" << h << std::endl;
148 assert(0 && "P in not on a lattice plane.");
149 }
150 return h;
151 }
152
153 template <int dim>
155 {
156 assert(this->squaredNorm() > 0 && "A null ReciprocalLatticeVector cannot be used to compute planeIndexOfPoint");
157 return dot(P);
158 }
159
160// template <int dim>
161// typename ReciprocalLatticeVectorBase<dim>::VectorDimI ReciprocalLatticeVectorBase<dim>::d2cov(const VectorDimD &d,
162// const Lattice<dim> &lat)
163// {
164// const VectorDimD nd(lat.latticeBasis.transpose() * d);
165// // const VectorDimD rd(RoundEigen<double,dim>::round(nd));
166// const VectorDimD rd(nd.array().round());
167// if ((nd - rd).norm() > roundTol)
168// {
169// std::cout << "d2cov, nd=" << nd.transpose() << std::endl;
170// std::cout << "d2cov, rd=" << rd.transpose() << std::endl;
171// assert(0 && "Input vector is not a reciprocal lattice vector");
172// }
173// // assert((nd-rd).norm()<roundTol && "Input vector is not a lattice vector");
174// return rd.template cast<IntScalarType>();
175// }
176
177 //Operator starts here
178 template <int dim>
183
184
185template <int dim>
187/* init base */ ReciprocalLatticeVectorBase<dim>(lat)
188{
191}
192
193template <int dim>
194ReciprocalLatticeVector<dim>::ReciprocalLatticeVector(const VectorDimD &d,
195 /* */ const Lattice<dim> &lat) :
196/* init base */ ReciprocalLatticeVectorBase<dim>(d,lat)
197{
200}
201
208
210 /* */ const Lattice<3> &lat) :
211/* init base */ ReciprocalLatticeVectorBase<3>(d,lat)
212{
215}
216
218{
219 assert(&lattice == &other.lattice && "LatticeVectors belong to different Lattices.");
220 return LatticeDirection<3>(LatticeVector<3>(static_cast<VectorDimI>(*this).cross(static_cast<VectorDimI>(other)), lattice));
221}
222
223template class ReciprocalLatticeVectorBase<1>;
225template class ReciprocalLatticeVectorBase<2>;
227 template class ReciprocalLatticeVectorBase<3>;
229
230template class ReciprocalLatticeVector<1>;
231template class ReciprocalLatticeVector<2>;
232
233} // end namespace
234#endif
const LatticeType & lattice
IntScalarType dot(const LatticeVector< dim > &other) const
IntScalarType planeIndexOfPoint(const VectorDimD &P) const
IntScalarType closestPlaneIndexOfPoint(const VectorDimD &P) const
ReciprocalLatticeVectorBase< dim > operator+(const ReciprocalLatticeVectorBase< dim > &other) const
ReciprocalLatticeVectorBase< dim > & operator-=(const ReciprocalLatticeVectorBase< dim > &other)
ReciprocalLatticeVectorBase< dim > & operator+=(const ReciprocalLatticeVectorBase< dim > &other)
ReciprocalLatticeVectorBase< dim > & operator=(const ReciprocalLatticeVectorBase< dim > &other)
ReciprocalLatticeVectorBase< dim > operator*(const IntScalarType &scalar) const
ReciprocalLatticeVectorBase< dim > operator-(const ReciprocalLatticeVectorBase< dim > &other) const
LatticeDirectionType cross(const ReciprocalLatticeVectorType &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)
REAL * h