Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
LatticeCore.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_LatticeCore_cpp_
8#define model_LatticeCore_cpp_
9
10#include <LatticeCore.h>
12#include <Eigen/Dense>
13
14namespace model
15{
16
17
18
19template <int dim>
21{
22 Eigen::Array<IntScalarType, dim, 1> nums = VectorDimI::Zero();
23
24 if (nd.squaredNorm() > 0.0)
25 {
26 const Eigen::Array<double, dim, 1> nda(nd.array().abs()); // vector of close-to-integer numbers corresponding to lattice coordinates
27 size_t maxID = 0;
28 const double maxVal(nda.maxCoeff(&maxID));
29 nd /= maxVal; // make each value of nd in [-1:1]
30
31 nums = VectorDimI::Ones();
32 Eigen::Array<IntScalarType, dim, 1> dens = VectorDimI::Ones();
33 IntScalarType denProd = 1;
34
35 for (int k = 0; k < dim; ++k)
36 {
37 BestRationalApproximation bra(nd(k), 10000);
38
39 nums(k) = bra.num;
40 dens(k) = bra.den;
41 denProd *= bra.den;
42 }
43
44 for (int k = 0; k < dim; ++k)
45 {
46 nums(k) *= (denProd / dens(k));
47 }
48 }
49
50 return nums.matrix();
51}
52
53template <int dim>
55{
56 const VectorDimD nd(invA*d);
57 const VectorDimD rd(nd.array().round());
58 if ((nd - rd).norm() > roundTol)
59 {
60 std::cout << "nd=" << nd.transpose() << std::endl;
61 std::cout << "rd=" << rd.transpose() << std::endl;
62 assert(0 && "Input vector is not a lattice vector");
63 }
64 return rd.template cast<IntScalarType>();
65}
66
67
68
69 template struct LatticeCore<1>;
70 template struct LatticeCore<2>;
71 template struct LatticeCore<3>;
72} // end namespace
73#endif
static VectorDimI integerCoordinates(const VectorDimD &d, const MatrixDimD &invA)
static constexpr double roundTol
Definition LatticeCore.h:22
long long int IntScalarType
Definition LatticeCore.h:26
static VectorDimI rationalApproximation(VectorDimD v)
Eigen::Matrix< double, dim, 1 > VectorDimD
Definition LatticeCore.h:24
Eigen::Matrix< double, dim, dim > MatrixDimD
Definition LatticeCore.h:25
Eigen::Matrix< IntScalarType, dim, 1 > VectorDimI
Definition LatticeCore.h:27
int k