Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
BiCrystal.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_BiCrystal_cpp_
8#define model_BiCrystal_cpp_
9
10#include <LatticeModule.h>
11
12namespace model
13{
14
15 template <int dim>
16 typename BiCrystal<dim>::MatrixDimI BiCrystal<dim>::getM(const RationalMatrix<dim>& rm,
18 {
19 typename BiCrystal<dim>::MatrixDimI M=BiCrystal<dim>::MatrixDimI::Identity();
20 for(int i=0;i<dim;++i)
21 {
22 const auto& dii(sd.matrixD()(i,i));
23 M(i,i)=dii/IntegerMath<IntScalarType>::gcd(rm.mu,dii);
24 }
25 return M;
26 }
27
28 template <int dim>
29 typename BiCrystal<dim>::MatrixDimI BiCrystal<dim>::getN(const RationalMatrix<dim>& rm,
31 {
32 typename BiCrystal<dim>::MatrixDimI N=BiCrystal<dim>::MatrixDimI::Identity();
33 for(int i=0;i<dim;++i)
34 {
35 const auto& dii=sd.matrixD()(i,i);
36 N(i,i)=rm.mu/IntegerMath<IntScalarType>::gcd(rm.mu,dii);
37 }
38 return N;
39 }
40
41 template <int dim>
42 typename BiCrystal<dim>::MatrixDimD BiCrystal<dim>::getCSLBasis(const Lattice<dim>& A,
43 const Lattice<dim>& B,
45 const typename BiCrystal<dim>::MatrixDimI& M,
46 const typename BiCrystal<dim>::MatrixDimI& N,
47 const bool& useRLLL)
48 {
49 // The transition matrix is T=P/sigma, where P=rm.integerMatrix is
50 // an integer matrix and sigma=rm.sigma is an integer
51 // The integer matrix P can be decomposed as P=X*D*Y using the Smith decomposition.
52 // X and Y are unimodular, and D is diagonal with D(k,k) dividing D(k+1,k+1)
53 // The decomposition also computes the matices U and V such that D=U*P*V
54 // From T=inv(A)*B=P/sigma=X*D*Y/sigma=X*D*inv(V)/sigma, we have
55 // B1*(sigma*I)=A1*D
56 // where
57 // B1=B*V
58 // A1=A*X
59 // Since V and X are unimodular matrices, B1 and A1 are new bases
60 // of the lattices B and A, respectively. Moreover, since
61 // (sigma*I) and D are diagonal, the columns of B1 and A1 are
62 // proportional, with rational proportionality factors different for each column.
63 // For example, columns "i" read
64 // b1_i*sigma=a1_i*D(i,i)
65 // Therefore, the i-th primitive vectors of the CSL is
66 // c_i=b1_i*sigma/gcd(sigma,D(i,i))=a1_i*D(i,i)/gcd(sigma,D(i,i))
67 // or, in matrix form
68 // C=B1*N=A1*M, that is
69 // C=B*V*N=A*X*M
70 // where M=diag(D(i,i)/gcd(sigma,D(i,i))) and
71 // N=diag(sigma/gcd(sigma,D(i,i))) and
72
73 const auto C1(A.latticeBasis*(sd.matrixX()*M).template cast<double>());
74 const auto C2(B.latticeBasis*(sd.matrixV()*N).template cast<double>());
75 if ((C1-C2).norm()>FLT_EPSILON)
76 {
77 throw std::runtime_error("CSL calculation failed.\n");
78 }
79
80 if(useRLLL)
81 {
82 return RLLL(0.5*(C1+C2),0.75).reducedBasis();
83 }
84 else
85 {
86 return 0.5*(C1+C2);
87 }
88 }
89
90 template <int dim>
91 typename BiCrystal<dim>::MatrixDimD BiCrystal<dim>::getDSCLBasis(const Lattice<dim>& A,
92 const Lattice<dim>& B,
94 const typename BiCrystal<dim>::MatrixDimI& M,
95 const typename BiCrystal<dim>::MatrixDimI& N,
96 const bool& useRLLL)
97 {
98
99 const auto D1(A.latticeBasis*sd.matrixX().template cast<double>()*N.template cast<double>().inverse());
100 const auto D2(B.latticeBasis*sd.matrixV().template cast<double>()*M.template cast<double>().inverse());
101 if ((D1-D2).norm()>FLT_EPSILON)
102 {
103 throw std::runtime_error("DSCL calculation failed.\n");
104 }
105 if(useRLLL)
106 {
107 return RLLL(0.5*(D1+D2),0.75).reducedBasis();
108 }
109 else
110 {
111 return 0.5*(D1+D2);
112 }
113 }
114
115
116 template <int dim>
118 const Lattice<dim>& B_in,
119 const bool& useRLLL) :
120 /* init */ RationalMatrix<dim>(A_in.reciprocalBasis.transpose()*B_in.latticeBasis)
121 /* init */,SmithDecomposition<dim>(this->integerMatrix)
122 /* init */,A(A_in)
123 /* init */,B(B_in)
124 /* init */,M(getM(*this,*this))
125 /* init */,N(getN(*this,*this))
126 /* init */,sigmaA(M.determinant())
127 /* init */,sigmaB(N.determinant())
128 /* init */,sigma(std::abs(sigmaA)==std::abs(sigmaB)? std::abs(sigmaA) : 0)
129 /* init */, csl(getCSLBasis (A,B,*this,M,N,useRLLL),MatrixDimD::Identity())
130 /* init */,dscl(getDSCLBasis(A,B,*this,M,N,useRLLL),MatrixDimD::Identity())
131 /* init */,Ap(A.latticeBasis*this->matrixX().template cast<double>())
132 /* init */,Bp(B.latticeBasis*this->matrixV().template cast<double>())
133 {
134
135 if(true)
136 {//verify that CSL can be obtained as multiple of A and B
137
138 const MatrixDimD tempA(A.reciprocalBasis.transpose()*csl.latticeBasis);
139 if ((tempA-tempA.array().round().matrix()).norm()>FLT_EPSILON)
140 {
141 throw std::runtime_error("CSL is not a multiple of lattice A\n");
142 }
143
144 const MatrixDimD tempB(B.reciprocalBasis.transpose()*csl.latticeBasis);
145 if ((tempB-tempB.array().round().matrix()).norm()>FLT_EPSILON)
146 {
147 throw std::runtime_error("CSL is not a multiple of lattice B\n");
148 }
149 }
150
151 if(true)
152 {//verify that A and B are multiples of DSCL
153
154 const MatrixDimD tempA(dscl.reciprocalBasis.transpose()*A.latticeBasis);
155 if ((tempA-tempA.array().round().matrix()).norm()>FLT_EPSILON)
156 {
157 throw std::runtime_error("Lattice A is not a multiple of the DSCL\n");
158 }
159
160 const MatrixDimD tempB(dscl.reciprocalBasis.transpose()*B.latticeBasis);
161 if ((tempB-tempB.array().round().matrix()).norm()>FLT_EPSILON)
162 {
163 throw std::runtime_error("Lattice B is not a multiple of the DSCL\n");
164 }
165 }
166
167 // update(useRLLL);
168 }
169
170// template<int dim>
171// LatticeDirection<dim> BiCrystal<dim>::AtoCSLvector(const LatticeVector<dim>& n) const
172// {
173// return csl.latticeDirection(M.adjoint()*this->matrixU()*n); // NOOO, adjoint in Eigen means conjugate transpose
174// }
175
176
177// template class BiCrystal<1>;
178 template class BiCrystal<2>;
179 template class BiCrystal<3>;
180
181} // end namespace
182#endif
183
Eigen::Matrix3d M
const int sigmaA
Definition BiCrystal.h:56
const int sigmaB
Definition BiCrystal.h:57
const Lattice< dim > Ap
Definition BiCrystal.h:61
const int sigma
Definition BiCrystal.h:58
const Lattice< dim > Bp
Definition BiCrystal.h:62
const Lattice< dim > & A
Definition BiCrystal.h:52
const Lattice< dim > dscl
Definition BiCrystal.h:60
const Lattice< dim > csl
Definition BiCrystal.h:59
BiCrystal(const Lattice< dim > &A, const Lattice< dim > &B, const bool &useRLLL=true)
const MatrixDimI N
Definition BiCrystal.h:55
const Lattice< dim > & B
Definition BiCrystal.h:53
const MatrixDimI M
Definition BiCrystal.h:54
const MatrixType & reducedBasis() const
RationalMatrix(const MatrixDimD &R)
initial point of the source segment B
function infiniteDisplacement syms Ax Ay Az Bx By Bz qx qy qz u L x y z real A
static IntScalarType gcd(const IntScalarType &a, const IntScalarType &b)
Definition IntegerMath.h:22
REAL C2[12]
REAL C1[8]
int i