Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
Lattices_NEW/LatticePlane.cpp
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MODEL is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_LatticePlane_cpp_
9#define model_LatticePlane_cpp_
10
11#include <LatticeModule.h>
12namespace model
13{
14
15
16 /**************************************************************************/
17 template <int dim>
18 typename LatticePlaneKey<dim>::ArrayType LatticePlaneKey<dim>::hr2array(const VectorDimI &r, const LongIntType &h, const LongIntType &latticeID)
19 {
20 ArrayType temp;
21 for (int k = 0; k < dim; ++k)
22 {
23 temp[k] = r(k);
24 }
25 temp[dim] = h;
26 temp[dim + 1] = latticeID;
27 return temp;
28 }
29
30 /**************************************************************************/
31 template <int dim>
32 int LatticePlaneKey<dim>::sgn(const LongIntType &val)
33 {
34 return (LongIntType(0) < val) - (val < LongIntType(0));
35 }
36
37 /**************************************************************************/
38 template <int dim>
39 typename LatticePlaneKey<dim>::ArrayType LatticePlaneKey<dim>::correct_h_sign(VectorDimI r, LongIntType h, const LongIntType &latticeID)
40 {
41 assert(r.squaredNorm() > 0 && "zero direction cannot be used as LatticePlaneKey");
42 for (int d = 0; d < dim; ++d)
43 {
44 const int sgnrd(sgn(r(d)));
45 if (sgnrd != 0)
46 {
47 r *= sgnrd;
48 h *= sgnrd;
49 break;
50 }
51 }
52 return hr2array(r, h, latticeID);
53 }
54
55
56 /**********************************************************************/
57 template <int dim>
59 const LongIntType& h,
60 const LongIntType& latticeID) :
61 /* init */ array(correct_h_sign(r,h,latticeID))
62 {
63 }
64
65 /**********************************************************************/
66 template <int dim>
67 LatticePlaneKey<dim>::LatticePlaneKey(const VectorDimD& P,
68 const ReciprocalLatticeDirection<dim>& r) :
69 /* delegate */ LatticePlaneKey(r,r.planeIndexOfPoint(P),r.lattice.sID)
70 {
71
72 }
73
74 /**********************************************************************/
75 template <int dim>
76 LatticePlaneKey<dim>::LatticePlaneKey(const LatticeVector<dim>& L,
77 const ReciprocalLatticeDirection<dim>& r) :
78 /* delegate */ LatticePlaneKey(r,r.planeIndexOfPoint(L),r.lattice.sID)
79 {
80
81 }
82
83 /**********************************************************************/
84 template <int dim>
85 LatticePlaneKey<dim>::LatticePlaneKey(const long int& hin,
86 const ReciprocalLatticeDirection<dim>& r) :
87 /* init */ LatticePlaneKey(r,hin,r.lattice.sID)
88 {
89
90 }
91
92 template <int dim>
93 Eigen::Map<const typename LatticePlaneKey<dim>::VectorDimI> LatticePlaneKey<dim>::reciprocalDirectionComponents() const
94 {
95 return Eigen::Map<const VectorDimI>(&array.data()[0]);
96 }
97
98 template <int dim>
99 const typename LatticePlaneKey<dim>::LongIntType& LatticePlaneKey<dim>::planeIndex() const
100 {
101 return array[dim];
102 }
103
104 template <int dim>
105 const typename LatticePlaneKey<dim>::LongIntType& LatticePlaneKey<dim>::latticeID() const
106 {
107 return array[dim + 1];
108 }
109
110 template <int dim>
111 bool LatticePlaneKey<dim>::operator<(const LatticePlaneKey<dim> &other) const
112 { // allow use in sorted STL containers
113 return array < other.array;
114 }
115
116 template struct LatticePlaneKey<3>;
117
118//for the lattice plane class.
119 /**********************************************************************/
120 std::pair<bool, long int> LatticePlane::computeHeight(const ReciprocalLatticeDirection<dim> &r,
121 const VectorDimD &P)
122 {
124 assert(r.squaredNorm() > 0 && "A zero normal cannot be used as valid GlidePlane normal");
125 const double hd(P.dot(r.cartesian()));
126 const long int h(std::lround(hd));
127 return std::make_pair(fabs(hd - h) < FLT_EPSILON, h);
128 }
129
130 /**********************************************************************/
131 std::pair<bool, long int> LatticePlane::computeHeight(const ReciprocalLatticeDirection<dim> &r,
132 const LatticeVector<dim> &L)
133 {
135 assert(r.squaredNorm() > 0 && "A zero normal cannot be used as valid GlidePlane normal");
136 return std::make_pair(true, L.dot(r));
137 }
138
139 /**********************************************************************/
140 LatticePlane::LatticePlane(const VectorDimD& P,
141 const ReciprocalLatticeDirection<dim>& r) :
142 /* init */ key(P,r)
143 /* init */,n(ReciprocalLatticeVector<dim>(key.reciprocalDirectionComponents(),r.lattice))
144 /* init */,planeIndex(key.planeIndex())
145 {
146}
147
148 /**********************************************************************/
149 LatticePlane::LatticePlane(const LatticeVector<dim>& L,
150 const ReciprocalLatticeDirection<dim>& r) :
151 /* init */ key(L,r)
152 /* init */,n(ReciprocalLatticeVector<dim>(key.reciprocalDirectionComponents(),r.lattice))
153 /* init */,planeIndex(key.planeIndex())
154 {
155
156 }
157
158 /**********************************************************************/
159 LatticePlane::LatticePlane(const long int& hin,
160 const ReciprocalLatticeDirection<dim>& r) :
161 /* init */ key(hin,r)
162 /* init */,n(ReciprocalLatticeVector<dim>(key.reciprocalDirectionComponents(),r.lattice))
163 /* init */,planeIndex(key.planeIndex())
164 {
165
166 }
167 /**********************************************************************/
168 typename LatticePlane::VectorDimD LatticePlane::planeOrigin() const
169 {
170 return planeIndex * n.planeSpacing() * n.cartesian().normalized();
171 }
172}
173#endif
174
float r
Definition plotLoops.py:41
static int sgn(const LongIntType &val)
static ArrayType hr2array(const VectorDimI &r, const LongIntType &h, const LongIntType &latticeID)
LatticePlaneKey(const VectorDimI &r, const LongIntType &h, const LongIntType &latticeID)
std::array< LongIntType, dim+2 > ArrayType
static ArrayType correct_h_sign(VectorDimI r, LongIntType h, const LongIntType &latticeID)
int k
REAL * h
newbad key
vertex temp