26 const std::filesystem::path root(
argv[1]);
27 const bool frame283=
argc==3 && std::string(
argv[2])==
"283";
28 const auto folder = std::filesystem::temp_directory_path() /
29 (
"bicrystal-junction-collapse-" + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
30 const auto input = folder /
"inputFiles";
31 std::filesystem::create_directories(input);
32 std::filesystem::create_directories(folder /
"F");
33 std::filesystem::copy_file(root /
"Library/Materials/W.txt", input /
"W.txt");
35 std::filesystem::copy_file(root /
"Library/Meshes/bicrystal_48.msh", input /
"mesh.msh");
36 std::filesystem::copy_file(root /
"Library/DislocationDynamics/DD.txt", input /
"DD.txt");
37 std::filesystem::create_directories(folder /
"config");
38 const double length=3671.9477120460206;
40 std::ofstream
f(input /
"DefectiveCrystal.txt");
41 f <<
"physics=DislocationDynamics;\nuseFEM=0;\nNsteps=0;\nmaxResolveSteps=0;\ndtMax=1;\noutputFrequency=1;\noutputBinary=0;\nstartAtTimeStep=0;\nperiodicImageSize=0 0 0;\nEwaldLengthFactor=0;\n";
42 std::ofstream
p(input /
"polycrystal.txt");
43 p << std::setprecision(17) <<
"materialFile=W.txt;\nmeshFile=mesh.msh;\nabsoluteTemperature=300;\nC2G1=1 0 0 0 1 0 0 0 1;\n"
44 <<
"C2G2=0.8 0 0.6 0 1 0 -0.6 0 0.8;\nF=" << length <<
" 0 0 0 " << length <<
" 0 0 0 " << length
45 <<
";\nX0=0 0 0;\nperiodicFaceIDs=-1;\n";
49 const auto dd=input/
"DD.txt";
50 std::ifstream source(dd);
51 std::string contents((std::istreambuf_iterator<char>(source)),std::istreambuf_iterator<char>());
52 const auto location=contents.find(
"Lmax=100;");
53 require(location!=std::string::npos,
"Expected library remeshing default");
54 contents.replace(location,std::string(
"Lmax=100;").size(),
"Lmax=150;");
55 std::ofstream output(dd);
63 std::ifstream stream(root/(frame283 ?
"tests/data/bicrystalJunction283.txt" :
"tests/data/bicrystalJunction596.txt"));
64 require(
bool(stream),
"Missing bicrystal junction regression fixture");
69 network.
moveNodes(frame283 ? 272.4170214605611 : 236.5277449432792);
72 for(
const auto& entry : network.
loops())
74 const auto loop=entry.second.lock();
75 const auto links=loop->linkSequence();
77 for(
const auto* link : links)
79 if(!link->source->isPeriodicSubdivision())
84 require(anchors>=3,
"Collapsed periodic contour survived junction reconciliation");
85 require(links.size()>=3,
"Collapsed loop survived junction reconciliation");
86 for(
const auto* link : links)
88 require(link->sink->next.second->source==link->sink,
"Loop connectivity is broken");
91 for(
const auto& entry : network.
loopNodes())
93 const auto node=entry.second.lock();
94 require((node->get_P()+node->periodicPlanePatch()->shift-node->networkNode->get_P()).norm()<1.e-7,
95 "Junction reconciliation broke the loop/network mapping");
99 std::map<std::pair<size_t,size_t>,Eigen::Vector3d> burgers;
102 burgers.emplace(entry.first,entry.second.lock()->burgers());
104 const auto loopCount=network.
loops().size();
106 require(network.
loops().size()==loopCount,
"Repeated update changed surviving loops");
107 require(network.
networkLinks().size()==burgers.size(),
"Repeated update changed junction links");
110 require((entry.second.lock()->burgers()-burgers.at(entry.first)).norm()<1.e-12,
111 "Repeated update changed a shared Burgers contribution");
115 const auto grain=base.poly.grain(1);
116 const auto plane=base.dislocationDynamics().periodicGlidePlaneFactory.get(
model::GlidePlaneKey<3>(Eigen::Vector3d::Zero(),grain->reciprocalLatticeDirection(Eigen::Vector3d::UnitZ())));
117 for(
double separation : {1.e-12,1.e-5})
119 std::vector<std::pair<Eigen::Vector2d,const int* const>> polygon;
120 const Eigen::Vector2d center=plane->referencePlane->localPosition(Eigen::Vector3d(-0.5*length,0,0));
121 polygon.emplace_back(center,
nullptr);
122 polygon.emplace_back(center+Eigen::Vector2d(separation,0),
nullptr);
123 polygon.emplace_back(center+Eigen::Vector2d(0,10),
nullptr);
126 require(plane->polygonPatchIntersection(polygon,
false).empty(),
127 "Near-coincident triangle returned a two-point contour");
131 require(plane->polygonPatchIntersection(polygon,
false).size()==3,
132 "Resolvable thin triangle was discarded");
135 std::filesystem::remove_all(folder);
136 std::cout<<
"PASS: junction collapse, shared Burgers contributions and periodic mapping\n";
139 catch(
const std::exception& error)
141 std::cerr<<error.what()<<
'\n';