Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
DislocationInjector.h
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_DislocationInjector_H_
9#define model_DislocationInjector_H_
10
11
12
13
14namespace model
15{
16 template <int dim>
18 {
19 // constexpr static int dim=DislocationNetworkType::dim;
20 typedef Eigen::Matrix<double,dim,1> VectorDim;
21 // DislocationNetworkType& DN;
22
23 public:
24
25
26 /**********************************************************************/
27 static std::vector<VectorDim> straightLineBoundaryClosure(const VectorDim& P0,
28 const VectorDim& d,
29 const VectorDim& n,
30 const int& grainID,
32 {
33
34 return straightLineBoundaryClosure(P0,d,MeshPlane<dim>(mesh,grainID,P0,n),mesh);
35 }
36
37 /**********************************************************************/
38 static std::vector<VectorDim> straightLineBoundaryClosure(const VectorDim& P0,
39 const VectorDim& d,
40 const MeshPlane<dim>& plane,
42 {
43
44 assert(std::fabs(plane.unitNormal.dot(d))<FLT_EPSILON);
45 assert(plane.contains(P0));
46
47 const double maxSize=std::max(mesh.xMax(0)-mesh.xMin(0),std::max(mesh.xMax(1)-mesh.xMin(1),mesh.xMax(2)-mesh.xMin(2)));
48
49
50 // Define line AB containing dislocaiton and piercing the mesh
51 const VectorDim A(P0+3.0*maxSize*d);
52 const VectorDim B(P0-3.0*maxSize*d);
53
54// MeshPlane<dim> plane(mesh,grainID,P0,n);
55 // const auto& segDeq(plane.meshIntersections);
56
57 std::vector<VectorDim> nodePos;
58 int nIntersections=0;
59 for(const auto& pair : plane.meshIntersections)
60 {
61
62 SegmentSegmentDistance<dim> ssi(A,B,pair->P0,pair->P1);
63
64 if(nIntersections==0)
65 {
66 if(ssi.dMin>FLT_EPSILON) // no intersection
67 {
68
69 }
70 else //if(ssi.size==1)
71 {
72 nIntersections++;
73 nodePos.push_back((ssi.x0+ssi.x1)*0.5);
74 }
75 }
76 else if(nIntersections==1)
77 {
78 if(ssi.dMin>FLT_EPSILON)
79 {// no intersection
80 if((pair->P0-nodePos.back()).norm()>FLT_EPSILON)
81 {
82 nodePos.push_back(pair->P0);
83 }
84 }
85 else
86 {// intersection
87 const VectorDim X((ssi.x0+ssi.x1)*0.5);
88 if((X-nodePos.back()).norm()>FLT_EPSILON)
89 {
90 nIntersections++;
91 nodePos.push_back(pair->P0);
92 if((X-pair->P0).norm()>FLT_EPSILON)
93 {
94 nodePos.push_back(X);
95 }
96 }
97 }
98 }
99 else
100 {
101
102 }
103 }
104
105 if(nodePos.size()<3)
106 {
107 std::cout<<"nodePos.size="<<nodePos.size()<<std::endl;
108 std::cout<<"plane.meshIntersections are:"<<std::endl;
109 std::cout<<std::setprecision(15)<<std::scientific<<plane.meshIntersections<<std::endl;
110 std::cout<<"P0="<<std::setprecision(15)<<std::scientific<<P0.transpose()<<std::endl;
111 std::cout<<"d="<<std::setprecision(15)<<std::scientific<<d.transpose()<<std::endl;
112 assert(false && "LOOP DOES NOT HAVE ENOUGH POINTS");
113 }
114
115 return nodePos;
116 }
117
118
119 /**********************************************************************/
120 template <typename DislocationNetworkType>
122 {
123 typedef typename DislocationNetworkType::NodeType NodeType;
124 const std::pair<LatticeVector<dim>,int> rp=DN.poly.randomLatticePointInMesh();
125 const int& grainID=rp.second; // random grain ID
126 const LatticeVector<dim>& L0=rp.first; // random lattice position in the grain
127 const VectorDim P0(L0.cartesian()); // cartesian position of L0
128 std::mt19937 generator(std::chrono::system_clock::now().time_since_epoch().count());
129 std::uniform_int_distribution<> distribution(0,DN.poly.grain(grainID).slipSystems().size()-1);
130 const int rSS=distribution(generator); // a random SlipSystem ID
131 const SlipSystem& slipSystem=DN.poly.grain(grainID).slipSystems()[rSS];
132 const VectorDim b=slipSystem.s.cartesian(); // Burgers vector
133 const VectorDim n=slipSystem.n.cartesian().normalized(); // slip plane normal
134
135 std::uniform_real_distribution<> dis(0.0, 2.0*std::numbers::pi);
136 const double theta=dis(generator); // random angle of the dislocation line in the plane from screw orientation.
137 const VectorDim d=Eigen::AngleAxisd(theta,n)*b.normalized(); // a random direction in the glide plane
138
139 std::vector<VectorDim> nodePos(straightLineBoundaryClosure(P0,d,n,grainID,DN.mesh));
140 std::vector<std::shared_ptr<NodeType>> loopNodes;
141 for (const auto& pos : nodePos)
142 {
143 loopNodes.emplace_back(new NodeType(&DN,pos,VectorDim::Zero(),1.0));
144 }
145 DN.insertLoop(loopNodes,b,n,P0,grainID);
146// DN.clearDanglingNodes();
147 }
148
149 };
150
151}
152#endif
static std::vector< VectorDim > straightLineBoundaryClosure(const VectorDim &P0, const VectorDim &d, const MeshPlane< dim > &plane, const SimplicialMesh< dim > &mesh)
static std::vector< VectorDim > straightLineBoundaryClosure(const VectorDim &P0, const VectorDim &d, const VectorDim &n, const int &grainID, const SimplicialMesh< dim > &mesh)
void insertRandomStraightDislocation(DislocationNetworkType &DN)
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
b
Definition int_R.m:16
size_t InstanceCount< Derived >::count
DislocationNetwork< 3 > DislocationNetworkType
Definition pyMoDELib.cxx:69
const RationalLatticeDirection< 3 > s
Definition SlipSystem.h:29
const GlidePlaneBase & n
Definition SlipSystem.h:28