oILAB
Loading...
Searching...
No Matches
GbShifts.cpp
Go to the documentation of this file.
1//
2// Created by Nikhil Chandra Admal on 2/4/24.
3//
4#include "../../include/Lattices/GbShifts.h"
5#include "../../include/Utilities/randomInteger.h"
6
7namespace oILAB {
8template <int dim>
11 const std::vector<LatticeVector<dim>> &gbCslVectors,
12 const double &bhalfMax)
13 : gb(gb), axis(axis), gbCslVectors(gbCslVectors),
14 bShiftPairs(getbShiftPairs(gb, gbCslVectors, bhalfMax)) {
15 std::cout << "--------------------GBShifts class construction "
16 "---------------------------"
17 << std::endl;
18 std::cout << "GB CSL vectors = " << std::endl;
19 for (const auto &elem : gbCslVectors)
20 std::cout << elem.cartesian().transpose() << std::endl;
21 std::cout << std::endl;
22
23 std::cout << "GB reciprocal CSL vectors = " << std::endl;
24 Eigen::Matrix<double, dim, dim - 1> gbCslBasis;
25 for (int i = 0; i < dim - 1; ++i)
26 gbCslBasis.col(i) = gbCslVectors[i].cartesian();
27 Eigen::Matrix<double, dim, dim - 1> gbCslReciprocalBasis =
28 gbCslBasis.completeOrthogonalDecomposition().pseudoInverse().transpose();
29 std::cout << gbCslReciprocalBasis.transpose() << std::endl;
30 std::cout << std::endl;
31
32 std::cout << "Maximum b < "
33 << 2 * bhalfMax * gb.bc.A.latticeBasis.col(0).norm() << std::endl;
34 std::cout << std::endl;
35
36 VectorDimD normal;
37 if (dim == 3)
38 normal = gbCslVectors[0].cross(gbCslVectors[1]).cartesian().normalized();
39 else
40 normal = gbCslVectors[0].cross().cartesian().normalized();
41
42 std::cout << "Exploring the following translation-shift pairs:" << std::endl;
43 for (const auto &[b, s] : bShiftPairs) {
44 std::cout << "b = " << b.cartesian().transpose();
45 std::cout << "; s = " << s.transpose() << std::endl;
46 // if (abs(s.dot(normal)) > FLT_EPSILON)
47 if (abs(s.dot(normal)) > 1e-6)
48 throw std::runtime_error(
49 "GBShifts construction failed - shifts are not parallel to the GB.");
50
51 Eigen::MatrixXd shiftCoordinates = gbCslReciprocalBasis.transpose() * s;
52 if ((shiftCoordinates.array() < -FLT_EPSILON).any() ||
53 (shiftCoordinates.array() > 1 + FLT_EPSILON).any()) {
54 std::cout << "Shift coordinates = " << shiftCoordinates.transpose()
55 << std::endl;
56 throw std::runtime_error(
57 "GB shifts are not in the area spanned by the GB CSL vectors.");
58 }
59 }
60 std::cout << "----------------------------" << std::endl;
61 std::cout << std::endl;
62
63 }
64
65 template<int dim>
66 std::vector<std::pair<LatticeVector<dim>, typename GbShifts<dim>::VectorDimD>> GbShifts<dim>::getbShiftPairs(const Gb<dim>& gb,
67 const std::vector<LatticeVector<dim>>& gbCslVectors,
68 const double& bhalfMax)
69 {
70 std::vector<std::pair<LatticeVector<dim>, VectorDimD>> output;
71
72 assert(gbCslVectors.size()==dim-1);
73 auto nC= gb.bc.getReciprocalLatticeDirectionInC(gb.nB.reciprocalLatticeVector());
74
75 // form a CSL cell for modulo operations
76 auto gbPlaneParallelCslBasis= gb.bc.csl.planeParallelLatticeBasis(nC,true);
77 std::vector<LatticeVector<dim>> cslSubLatticeVectors;
78 cslSubLatticeVectors.push_back(gbPlaneParallelCslBasis[0].latticeVector());
79 cslSubLatticeVectors.push_back(gbCslVectors[0]);
80 cslSubLatticeVectors.push_back(gbCslVectors[1]);
81 auto cslPoints= gb.bc.csl.box(cslSubLatticeVectors);
82
83 // form a T lattice cell for exploring translations
84 auto nT= gb.getReciprocalLatticeDirectionInT(gb.bc.getReciprocalLatticeDirectionInD(gb.nA.reciprocalLatticeVector()).reciprocalLatticeVector());
85 auto planeParallelBasisT= gb.T.planeParallelLatticeBasis(nT,true);
86 std::vector<LatticeVector<dim>> latticeVectorsT;
87
88 double latticeConstant= gb.bc.A.latticeBasis.col(0).norm();
89 for(int i=0; i<dim; ++i)
90 {
91 // scale the lattice vectors of T based on the bhalfMax parameter
92 //int factor= floor(bhalfMax*latticeConstant/planeParallelBasisT[i].latticeVector().cartesian().norm()+FLT_EPSILON);
93 int factor= floor(35*bhalfMax*latticeConstant/planeParallelBasisT[i].latticeVector().cartesian().norm()+FLT_EPSILON);
94 factor= (factor>0 ? factor : 1);
95 latticeVectorsT.push_back(factor * planeParallelBasisT[i].latticeVector());
96 }
97 auto points= gb.T.box(latticeVectorsT,"T.txt");
98
99
100 VectorDimD shiftT, shiftC;
101 shiftT << -0.5, -0.5, -0.5;
102 shiftC << -0.5, -FLT_EPSILON, -FLT_EPSILON;
103 for(auto& point : points) {
104 //if (point.cartesian().norm() > bhalfMax*gb.bc.A.latticeBasis.col(0).norm())
105 // continue;
106 LatticeVector<dim>::modulo(point, latticeVectorsT, shiftT);
107 if (point.cartesian().norm() > bhalfMax*gb.bc.A.latticeBasis.col(0).norm())
108 continue;
109 auto cslShift = LatticeVector<dim>((gb.bc.LambdaA * gb.basisT * point).eval(), gb.bc.dscl);
110 for(const auto& cslPoint : cslPoints) {
111 // only for those CSL points on the boundary
112 if (gb.bc.getLatticeVectorInA(cslPoint).dot(gb.nA)!=0) continue;
113 VectorDimD cslShiftCentered = cslShift.cartesian() + cslPoint.cartesian() - point.cartesian() / 2;
114 LatticeVector<dim>::modulo(cslShiftCentered, cslSubLatticeVectors, shiftC);
115 output.push_back(std::make_pair(point, cslShiftCentered));
116 }
117 }
118 return output;
119 }
120 /*
121 template<int dim>
122 std::vector<LatticeVector<dim>> GbShifts<dim>::getGbCslVectors(const Gb<dim>& gb, const ReciprocalLatticeVector<dim>& axis)
123 {
124 std::vector<LatticeVector<dim>> output;
125 LatticeVector<dim> axisA(gb.bc.A.latticeDirection(axis.cartesian()).latticeVector());
126 LatticeVector<dim> axisC(gb.bc.getLatticeDirectionInC(axisA).latticeVector());
127 for(int i=0; i<dim-1; ++i) {
128 if (i==0) output.push_back(gb.getPeriodVector(axis));
129 if (i==1) output.push_back(axisC);
130 }
131 return output;
132 }
133 */
134
135 //template class GbShifts<2>;
136 template class GbShifts<3>;
137
138 } // namespace oILAB
Definition Gb.h:13
ReciprocalLatticeDirection< dim > getReciprocalLatticeDirectionInT(const ReciprocalLatticeVector< dim > &v) const
Definition Gb.cpp:240
const ReciprocalLatticeDirection< dim > nB
Definition Gb.h:36
const ReciprocalLatticeDirection< dim > nA
Definition Gb.h:32
const MatrixDimI basisT
Definition Gb.h:40
const BiCrystal< dim > & bc
Definition Gb.h:28
const Lattice< dim > T
Definition Gb.h:38
std::vector< std::pair< LatticeVector< dim >, VectorDimD > > bShiftPairs
Definition GbShifts.h:28
GbShifts(const Gb< dim > &gb, const ReciprocalLatticeVector< dim > &axis, const std::vector< LatticeVector< dim > > &gbCslVectors, const double &bhalfMax=1)
Definition GbShifts.cpp:9
typename LatticeCore< dim >::VectorDimD VectorDimD
Definition GbShifts.h:13
const std::vector< LatticeVector< dim > > gbCslVectors
Definition GbShifts.h:27
const Gb< dim > & gb
Definition GbShifts.h:25
static std::vector< std::pair< LatticeVector< dim >, VectorDimD > > getbShiftPairs(const Gb< dim > &gb, const std::vector< LatticeVector< dim > > &gbCslVectors, const double &bhalfMax)
Definition GbShifts.cpp:66
LatticeVector class.
static std::enable_if< dm==2, void >::type modulo(LatticeVector< dim > &input, const std::vector< LatticeVector< dim > > &basis, const VectorDimD &shift=VectorDimD::Zero())