Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
testBicrystalCorner1537.cpp
Go to the documentation of this file.
3#include <filesystem>
4#include <fstream>
5#include <iomanip>
6#include <chrono>
7#include <iostream>
8#include <vector>
9#include <iterator>
10
11void require(bool condition, const char* message)
12{
13 if(!condition)
14 {
15 throw std::runtime_error(message);
16 }
17}
18
19int main(int argc, char** argv)
20{
21 try
22 {
23 require(argc == 2, "Expected repository root");
24 const std::filesystem::path root(argv[1]);
25 const auto folder = std::filesystem::temp_directory_path() /
26 ("bicrystal-corner-1537-" + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
27 const auto input = folder / "inputFiles";
28 std::filesystem::create_directories(input);
29 std::filesystem::create_directories(folder / "F");
30 std::filesystem::copy_file(root / "Library/Materials/W.txt", input / "W.txt");
31
32 std::filesystem::copy_file(root / "Library/Meshes/bicrystal_48.msh", input / "mesh.msh");
33 std::filesystem::copy_file(root / "Library/DislocationDynamics/DD.txt", input / "DD.txt");
34 std::filesystem::create_directories(folder / "config");
35 const double length=3671.9477120460206;
36 {
37 std::ofstream f(input / "DefectiveCrystal.txt");
38 f << "physics=DislocationDynamics;\nuseFEM=0;\nNsteps=0;\nmaxResolveSteps=0;\ndtMax=1;\noutputFrequency=1;\noutputBinary=0;\nstartAtTimeStep=0;\nperiodicImageSize=0 0 0;\nEwaldLengthFactor=0;\n";
39 std::ofstream p(input / "polycrystal.txt");
40 p << std::setprecision(17) << "materialFile=W.txt;\nmeshFile=mesh.msh;\nabsoluteTemperature=300;\nC2G1=1 0 0 0 1 0 0 0 1;\n"
41 << "C2G2=0.8 0 0.6 0 1 0 -0.6 0 0.8;\nF=" << length << " 0 0 0 " << length << " 0 0 0 " << length
42 << ";\nX0=0 0 0;\nperiodicFaceIDs=-1;\n";
43 }
44 model::DefectiveCrystalBase<3> base(folder.string());
45 const auto grain=base.poly.grain(2);
46 const auto plane=base.dislocationDynamics().periodicGlidePlaneFactory.get(model::GlidePlaneKey<3>(Eigen::Vector3d(1295.5740040615206,1619.467505076901,-971.68050304614053),grain->reciprocalLatticeDirection(Eigen::Vector3d(0.56568542494923801,0.70710678118654757,-0.42426406871192851))));
47 std::vector<Eigen::Vector2d> vertices;
48 std::ifstream source(root/"tests/data/bicrystalCorner1537.txt");
49 require(bool(source),"Missing frame 1537 contour");
50 double x,y;
51 while(source>>x>>y)
52 {
53 vertices.emplace_back(x,y);
54 }
55 require(vertices.size()==108,"Incomplete frame 1537 contour");
56 double referenceArea=0;
57 for(bool reverse : {false,true})
58 {
59 std::vector<std::pair<Eigen::Vector2d,const int* const>> polygon;
60 for(size_t i=0;i<vertices.size();++i)
61 {
62 polygon.emplace_back(vertices[reverse ? vertices.size()-1-i : i],nullptr);
63 }
64 const auto result=plane->polygonPatchIntersection(polygon,false);
65 require(result.size()>=3,"Corner clipping discarded the retained area");
66 double area=0;
67 for(size_t i=0;i<result.size();++i)
68 {
69 const Eigen::Vector2d a=std::get<0>(result[i]);
70 const Eigen::Vector2d b=std::get<0>(result[(i+1)%result.size()]);
71 area+=0.5*(a.x()*b.y()-a.y()*b.x());
72 const auto patch=plane->getPatch(std::get<1>(result[i]));
73 // Every returned node must lie inside its actual convex patch,
74 // including near the oblique periodic/physical corner.
75 for(const auto& edge : patch->edges())
76 {
77 const Eigen::Vector2d d=*edge->sink-*edge->source;
78 const Eigen::Vector2d offset=a-*edge->source;
79 require((d.x()*offset.y()-d.y()*offset.x())/d.norm()>-1.e-8,
80 "Clipping retained a node outside its patch");
81 }
82 }
83 if(!reverse)
84 {
85 referenceArea=area;
86 require(std::abs(area)>1.0,"Corner clipping erased slipped area");
87 }
88 else
89 {
90 require(std::abs(area+referenceArea)<1.e-6,"Corner clipping depends on polygon orientation");
91 }
92 }
93 std::filesystem::remove_all(folder);
94 std::cout<<"PASS: frame 1537 oblique periodic/physical corner in both orientations\n";
95 return 0;
96 }
97 catch(const std::exception& error)
98 {
99 std::cerr<<error.what()<<std::endl;
100 return 1;
101 }
102}
function int_R syms a b c u real f
Definition int_R.m:4
a
Definition int_R.m:14
b
Definition int_R.m:16
x
Definition int_R.m:12
LatticePlaneKey< dim > GlidePlaneKey
void require(bool condition, const char *message)
void argv
void b int argc
vertex p[3]
int i
REAL area
result
void vertices