Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
DislocationLoopPatches.cpp
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MoDELib is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_DislocationLoopPatches_cpp_
9#define model_DislocationLoopPatches_cpp_
10
11
13#include <Polygon2D.h>
14
15namespace model
16{
17
18 template <int dim>
19 DislocationLoopPatches<dim>::DislocationLoopPatches(const std::shared_ptr<PeriodicGlidePlaneType>& periodicGlidePlane_in) :
20 /* */ periodicGlidePlane(periodicGlidePlane_in)
21 {
22
23 }
24
25 template <int dim>
26 void DislocationLoopPatches<dim>::update(const std::vector<VectorDim>& linkShifts, const std::vector<Eigen::Matrix<double,dim,1>>& nodePos)
27 {
29 {
30 localPatches().clear();
31 globalPatches().clear();
32 std::vector<Eigen::Matrix<double,dim-1,1>> localNodePos;
33 for(const auto& globalPos : nodePos)
34 {
35 localNodePos.push_back(periodicGlidePlane->referencePlane->localPosition(globalPos));
36 }
37
38 const auto loopPatches(periodicGlidePlane->filledPatches(linkShifts));
39 for(const auto& patch : loopPatches)
40 {
41 // Collect local patch nodes pos
42 std::vector<Eigen::Matrix<double,dim-1,1>> localPatchPos;
43 for(const auto& edge : patch->edges())
44 {
45 localPatchPos.push_back(*edge->source);
46 }
47
48 const auto localLoopPosOnPeriodicPlane(SutherlandHodgman::clip(localNodePos,localPatchPos));
50 if(!localLoopPosOnPeriodicPlane.empty())
51 {
52 std::vector<Eigen::Matrix<double,dim,1>> globalLoopPos;
53 std::vector<Eigen::Matrix<double,dim-1,1>> localLoopPos;
55 for(const auto& localPos : localLoopPosOnPeriodicPlane)
56 {
57 globalLoopPos.push_back(periodicGlidePlane->referencePlane->globalPosition(localPos)+patch->shift);
58 localLoopPos.push_back(patch->glidePlane->localPosition(globalLoopPos.back()));
59 }
60 globalPatches().emplace(patch,globalLoopPos);
61 localPatches().emplace(patch,localLoopPos);
62
63 }
64 }
65 }
66 }
67
68 template <int dim>
73
74 template <int dim>
79
80 template <int dim>
85
86 template <int dim>
91
92 template <int dim>
94 {
95 VectorDim nA(VectorDim::Zero());
96 for(const auto& patch : globalPatches())
97 {
98
99 const VectorDim& Ps(patch.second[0]);
100 for(size_t k0=0;k0<patch.second.size();++k0)
101 {
102 const size_t k1(k0+1<patch.second.size()? k0+1 : 0);
103 const VectorDim& P0(patch.second[k0]);
104 const VectorDim& P1(patch.second[k1]);
105 nA+= 0.5*(P0-Ps).cross(P1-P0);
106 }
107 }
108
109 return nA;
110 }
111
112 template <int dim>
114 {
115 const double a2(1.0e-2);
116 const double oneA2=sqrt(1.0+a2);
117 double temp(0.0);
118 const VectorDim rhA(orientedArea());
119 const double rhAnorm(rhA.norm());
120 if(rhAnorm>FLT_EPSILON)
121 {
122 const VectorDim rhN(rhA/rhAnorm);
123 for(const auto& patch : globalPatches())
124 {
125 if(patch.second.size())
126 {
127 const VectorDim& planePoint(patch.second[0]);
128 const double posNorm((x-planePoint).norm());
129 const double dotProd((x-planePoint).dot(rhN));
130 if(std::fabs(dotProd)>FLT_EPSILON*posNorm)
131 {// x is outside the plane of the loop
132 const VectorDim s(sgn(dotProd)*rhN); // s points along +n for points above, and along -n for points below
133 for(size_t k=0;k<patch.second.size();++k)
134 {
135 const size_t k1(k<patch.second.size()-1? k+1 : 0);
136
137 VectorDim e1(patch.second[k]-x);
138 const double e1Norm(e1.norm());
139 if(e1Norm>FLT_EPSILON)
140 {
141 e1/=e1Norm;
142 VectorDim Y1(patch.second[k1]-x);
143 const double Y1norm(Y1.norm());
144 if(Y1norm>FLT_EPSILON)
145 {
146 Y1/=Y1norm;
147 VectorDim e3(e1.cross(Y1));
148 const double e3Norm(e3.norm());
149 if(e3Norm>FLT_EPSILON)
150 {// e1 and Y1 are not align. If they are the projection on the unit sphere is a point and therefore there is no contribution to solid angle
151 e3/=e3Norm; // normalize e3
152 const VectorDim e2(e3.cross(e1));
153 const double ydy(e1.dot(Y1));
154 const double w=sqrt((1.0-ydy)/(1.0+ydy));
155 const double s3(s.dot(e3));
156 const double s3A2=sqrt(std::pow(s3,2)+a2);
157 temp+=2.0*s3/oneA2/s3A2*atan(s3A2*w/(oneA2-s.dot(e1)-s.dot(e2)*w));
158 }
159 }
160 }
161 }
162 }
163 }
164 }
165 }
166 return temp;
167 }
168
169 template <int dim>
171 {
174 int wn(0);
175 for(const auto& pair : localPatches())
176 {
177 if(pair.first->glidePlane)
178 {
179 if(pair.first->glidePlane->contains(pt))
180 {
181 const auto localPt(pair.first->glidePlane->localPosition(pt));
182 wn+=Polygon2D::windingNumber(localPt,pair.second);
183 }
184 }
185 }
186 return wn;
187 }
188
189 template <int dim>
190 int DislocationLoopPatches<dim>::windingNumber(const Eigen::Matrix<double,dim-1,1>& localPt,const std::shared_ptr<GlidePlane<dim>>& ptPlane) const
191 {
194 int wn(0);
195 for(const auto& pair : localPatches())
196 {
197 if(pair.first->glidePlane)
198 {
199 if(pair.first->glidePlane==ptPlane)
200 {
201 wn+=Polygon2D::windingNumber(localPt,pair.second);
202 }
203 }
204 }
205 return wn;
206 }
207
208 template <int dim>
209 template <typename T>
211 {
212 return (val > T(0)) - (val < T(0));
213 }
214
215 template struct DislocationLoopPatches<3>;
216
217}
218#endif
219
static constexpr std::vector< PointType > clip(const std::vector< PointType > &subject, const std::vector< PointType > &boundary)
x
Definition int_R.m:12
void update(const std::vector< VectorDim > &linkShifts, const std::vector< VectorDim > &nodePos)
std::map< std::shared_ptr< PeriodicPlanePatch< dim > >, std::vector< VectorDim > > GlobalPatchPositionType
const GlobalPatchPositionType & globalPatches() const
Eigen::Matrix< double, dim, 1 > VectorDim
const LocalPatchPositionType & localPatches() const
double solidAngle(const VectorDim &x) const
std::map< std::shared_ptr< PeriodicPlanePatch< dim > >, std::vector< VectorLowerDim > > LocalPatchPositionType
DislocationLoopPatches(const std::shared_ptr< PeriodicGlidePlaneType > &periodicGlidePlane_in)
const std::shared_ptr< PeriodicGlidePlaneType > periodicGlidePlane
int windingNumber(const VectorDim &pt) const
static int windingNumber(const PointType &P, const std::vector< PointType > &V)
Definition Polygon2D.h:56
REAL w[16]
int k
vertex temp