8#ifndef model_ShearLoopGenerator_cpp_
9#define model_ShearLoopGenerator_cpp_
29 std::cout<<
"shear loop density="<<density<<std::endl;
30 if(spec.targetDensity_SI>0.0)
35 std::normal_distribution<double> radiusDistribution(spec.radiusDistributionMean_SI/mg.
ddBase.
poly.b_SI,spec.radiusDistributionStd_SI/mg.
ddBase.
poly.b_SI);
36 std::mt19937 generator;
38 std::uniform_int_distribution<> allowedSlipSystemDist(0,spec.allowedSlipSystemIDs.size()-1);
40 std::set<int> allowedGrainIDsSet;
41 for(
const auto& gID : spec.allowedGrainIDs)
43 allowedGrainIDsSet.insert(gID);
45 const double allowAllGrains(allowedGrainIDsSet.size() ? (*allowedGrainIDsSet.begin())<0 :
true);
48 while(density<spec.targetDensity_SI)
50 const std::pair<LatticeVector<3>,
int> rp(mg.
ddBase.
poly.randomLatticePointInMesh());
52 const size_t grainID=rp.second;
54 if(allowAllGrains || allowedGrainIDsSet.find(grainID)!=allowedGrainIDsSet.end())
56 std::uniform_int_distribution<> ssDist(0,mg.
ddBase.
poly.grain(grainID)->slipSystems().size()-1);
57 const int allowedIndex(allowedSlipSystemDist(generator));
58 const int allowedSlipID(spec.allowedSlipSystemIDs[allowedIndex]);
59 const int rSS(allowedSlipID<0 ? ssDist(generator) : allowedSlipID);
61 const double radius(radiusDistribution(generator));
64 const bool success=generateSingle(mg,rSS,L0.
cartesian(),radius,spec.numberOfSides);
68 std::cout<<
"shear loop density="<<density<<std::endl;
71 catch(
const std::exception&
e)
84 if(spec.slipSystemIDs.size()!=spec.loopRadii.size())
86 throw std::runtime_error(
"loopSlipSystemIDs.size()="+std::to_string(spec.slipSystemIDs.size())+
" NOT EQUAL TO loopRadii.size()="+std::to_string(spec.loopRadii.size()));
88 if(
int(spec.slipSystemIDs.size())!=spec.loopCenters.rows())
90 throw std::runtime_error(
"slipSystemIDs.size()="+std::to_string(spec.slipSystemIDs.size())+
" NOT EQUAL TO loopCenters.rows()="+std::to_string(spec.loopCenters.rows()));
92 if(spec.slipSystemIDs.size()!=spec.loopSides.size())
94 throw std::runtime_error(
"slipSystemIDs.size()="+std::to_string(spec.slipSystemIDs.size())+
" NOT EQUAL TO loopSides.size()="+std::to_string(spec.loopSides.size()));
98 for(
size_t k=0;
k<spec.slipSystemIDs.size();++
k)
102 const bool success=generateSingle(mg,spec.slipSystemIDs[
k],spec.loopCenters.row(
k),spec.loopRadii[
k]/mg.
ddBase.
poly.b_SI,spec.loopSides[
k]);
106 std::cout<<
"shear loop density="<<density<<std::endl;
109 catch(
const std::exception&
e)
122 throw std::runtime_error(
"ShearLoopGenerator::generateSingle:: point is outside mesh.");
125 const int grainID(found.second->region->regionID);
127 assert(mg.
ddBase.
poly.grains.size()==1 &&
"Periodic dislocations only supported for single crystals");
128 const auto& grain(mg.
ddBase.
poly.grain(grainID));
130 if(rSS>=0 && rSS<
int(grain->slipSystems().size()))
132 const auto& slipSystem(*grain->slipSystems().at(rSS));
135 const long int planeIndex(slipSystem.n.closestPlaneIndexOfPoint(center));
137 std::shared_ptr<PeriodicGlidePlane<3>> glidePlane(mg.
ddBase.
dislocationDynamics().periodicGlidePlaneFactory.get(glidePlaneKey));
138 const VectorDimD P0(glidePlane->referencePlane->snapToPlane(center));
141 std::vector<VectorDimD> loopNodePos;
144 loopNodePos.push_back(P0+Eigen::AngleAxisd(
k*2.0*std::numbers::pi/
sides,slipSystem.unitNormal)*slipSystem.s.cartesian().normalized()*radius);
157 slipSystem.s.cartesian(),glidePlane->referencePlane->unitNormal,
164 std::cout<<
"Skipping slip system "<<rSS<<std::endl;
168 throw std::runtime_error(
"slipSystem "+std::to_string(rSS)+
" not found, skipping.");
VectorDimD cartesian() const
bool insertJunctionLoop(const std::vector< VectorDimD > &loopNodePos, const std::shared_ptr< PeriodicGlidePlane< 3 > > &periodicPlane, const VectorDimD &b, const VectorDimD &unitNormal, const VectorDimD &P0, const size_t &grainID, const DislocationLoopIO< dim >::DislocationLoopType &loopType)
DefectiveCrystalBase< 3 > & ddBase
ShearLoopGenerator(const ShearLoopDensitySpecification &, MicrostructureGenerator &mg)
std::pair< bool, const Simplex< _dim, _dim > * > search(const Eigen::Matrix< double, dim, 1 > &P) const
const double & volume() const
static std::string defaultColor
static std::string magentaBoldColor
LatticePlaneKey< dim > GlidePlaneKey
const Polycrystal< dim > & poly
const SimplicialMesh< dim > & mesh
DislocationDynamicsBase< dim > & dislocationDynamics() const
enum insertvertexresult success