Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
PolyhedronInclusionsGenerator.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_InclusionsGenerator_cpp_
9#define model_InclusionsGenerator_cpp_
10
11
12#include <chrono>
13#include <random>
14#include <cmath>
15#include <list>
16#include <assert.h>
17#include <Eigen/LU>
18#include <Eigen/Cholesky>
19#include <limits>
20
21//#include <Simplex.h>
22#include <SimplicialMesh.h>
23#include <Polycrystal.h>
25#include <LatticeModule.h>
26//#include <PlaneMeshIntersection.h>
33
35#include <TextFileParser.h>
37#include <MeshBoundarySegment.h>
38//#include <ConfinedDislocationObject.h>
39#include <GlidePlaneModule.h>
40#include <MeshModule.h>
41#include <Plane.h>
45#include <GmshReader.h>
46#include <set>
47
48namespace model
49{
50
51 bool PolyhedronInclusionsGenerator::generateSingle(MicrostructureGenerator& mg,const std::map<size_t,Eigen::Vector3d>& polyNodes,const std::map<size_t,std::vector<size_t>>& faceMap, const Eigen::Matrix<double,1,dim*dim>& eTrow, const double& vrc,const int&type)
52 {
53 // Match the simulation loader: all boundary vertices must belong to one grain.
54 std::set<size_t> grainIDs;
55 for(const auto &face : faceMap)
56 {
57 for(const auto nodeID : face.second)
58 {
59 const auto searchPair = mg.ddBase.mesh.search(polyNodes.at(nodeID));
60 if(!searchPair.first)
61 {
62 throw std::runtime_error("Polyhedral inclusion node outside mesh; cannot determine crystal frame");
63 }
64 grainIDs.insert(searchPair.second->region->regionID);
65 }
66 }
67 if(grainIDs.size() != 1)
68 {
69 throw std::runtime_error("Polyhedral inclusion must belong to a single grain");
70 }
71 const auto &C2G = mg.ddBase.poly.grain(*grainIDs.begin())->C2G;
72 const Eigen::Matrix<double,dim,dim> crystalET(
73 Eigen::Map<const Eigen::Matrix<double,dim,dim>>(eTrow.data()).transpose());
74 const Eigen::Matrix<double,dim,dim> eT = C2G * crystalET * C2G.transpose();
75 mg.insertInclusion(polyNodes,faceMap, eT, vrc,type);
76 return true;
77 }
78
80 /* init */ allowOverlap(false)
81 {
82 GmshReader mshReader(spec.mshFile);
83
84// std::cout<<spec.X0<<std::endl;
85// std::cout<<spec.F<<std::endl;
86// std::cout<<spec.crystalEigenDistortion<<std::endl;
87
88 Eigen::Vector3d nodeBary(Eigen::Vector3d::Zero());
89 for(const auto& node : mshReader.nodes())
90 {
91 nodeBary+=node.second;
92 }
93 nodeBary/=mshReader.nodes().size();
94
95 for(int j=0;j<spec.X0.rows();++j)
96 {
97 std::map<size_t,Eigen::Vector3d> scaledNodes;
98 const Eigen::Vector3d x0(spec.X0.row(j));
99 for(const auto& node : mshReader.nodes())
100 {
101 scaledNodes.emplace(node.first,spec.F*(node.second-nodeBary)+x0);
102 }
103
104 std::map<size_t,std::vector<size_t>> faces;
105 size_t eleCounter(0);
106 for(const auto& ele : mshReader.elements())
107 {
108 if(ele.second.type==2)
109 {// 3-nodes triangle
110 faces.emplace(eleCounter,ele.second.nodeIDs);
111 eleCounter++;
112 }
113
114 }
115
116 generateSingle(mg,scaledNodes,faces, spec.crystalEigenDistortion, spec.velocityReductionFactor,spec.phaseID);
117 }
118 }
119}
120#endif
const std::map< size_t, Eigen::Vector3d > & nodes() const
const std::map< size_t, GmshElement > & elements() const
PolyhedronInclusionsGenerator(const PolyhedronInclusionIndividualSpecification &spec, MicrostructureGenerator &mg)
int j