13void require(
bool condition,
const char* message)
17 throw std::runtime_error(message);
23 const bool enforceRemeshLength=
true)
30 && (!enforceRemeshLength || link.
chordLength()>2.0*link.
network().networkRemesher.Lmin)
34 if((*link.
loopLinks().begin())->loop->slipSystem())
36 const auto& grain(**link.
grains().begin());
37 return std::make_pair(
true,grain.grainID);
40 return std::make_pair(
false,-1);
48 if(isBaseCSLink.first)
51 const auto loop((*link.
loopLinks().begin())->loop);
52 const auto slipSystem(loop->slipSystem());
55 const auto& grain(**link.
grains().begin());
57 const double pkGlide=std::fabs((pki-pki.dot(slipSystem->unitNormal)*slipSystem->unitNormal).norm());
59 std::map<double,int> ssMap;
60 for(
size_t s=0;s<grain.slipSystems().size();++s)
62 const auto& crossSlipSystem(grain.slipSystems().at(s));
63 if((loop->flow()-crossSlipSystem->s).squaredNorm()==0)
65 const double pkCross=std::fabs((pki-pki.dot(crossSlipSystem->unitNormal)*crossSlipSystem->unitNormal).norm());
66 ssMap.emplace(pkCross,s);
72 const auto& crossSlipSystem(grain.slipSystems().at(ssMap.rbegin()->second));
73 if(slipSystem->unitNormal.cross(crossSlipSystem->unitNormal).squaredNorm()>FLT_EPSILON
74 && ssMap.rbegin()->first>1.1*pkGlide)
76 return std::make_pair(
true,std::make_pair(grain.grainID,ssMap.rbegin()->second));
81 return std::make_pair(
false,std::make_pair(-1,-1));
87 for(
const auto& entry : network.
loops())
89 const auto loop=entry.second.lock();
90 std::map<size_t,const Network::LoopLinkType*> ordered;
91 for(
const auto* link : loop->loopLinks())
93 ordered.emplace(link->source->sID,link);
95 const auto sequence=loop->linkSequence();
96 require(sequence.size()==loop->loopLinks().size(),
"Loop traversal count changed");
99 const auto*
current=ordered.begin()->second;
100 for(
const auto* link : sequence)
107 size_t eligible=0,selected=0;
110 const auto link=entry.second.lock();
111 link->createQuadraturePoints(
false);
112 link->updateQuadraturePoints(
false);
113 for(
bool enforceLength : {
false,
true})
116 "Cross-slip eligibility changed");
119 require(
model.isCrossSlipLink(*link)==legacy,
"Cross-slip target or tie-breaking changed");
121 selected+=legacy.first;
123 std::vector<Eigen::Vector3d> forces;
124 for(
auto& point : link->quadraturePoints())
126 forces.push_back(point.pkForce);
127 point.pkForce.setZero();
131 for(
auto& point : link->quadraturePoints())
133 point.pkForce=forces[
k++];
136 std::cout<<
"Cross-slip reference: "<<eligible<<
" eligible, "<<selected<<
" selected links; exact agreement\n";
143 const std::filesystem::path root(
argv[1]);
144 if(
argc==3 && std::filesystem::is_directory(
argv[2]))
147 omp_set_num_threads(12);
151 saved.
read(base.simulationParameters.runID);
155 require(
bool(network) && !network->computeDDinteractions,
"Benchmark requires DD with interactions disabled");
159 const auto folder = std::filesystem::temp_directory_path() /
160 (
"cross-slip-optimization-" + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
161 const auto input = folder /
"inputFiles";
162 std::filesystem::create_directories(input);
163 std::filesystem::create_directories(folder /
"F");
164 std::filesystem::copy_file(root /
"Library/Materials/W.txt", input /
"W.txt");
166 std::filesystem::copy_file(root /
"Library/Meshes/bicrystal_48.msh", input /
"mesh.msh");
167 std::filesystem::copy_file(root /
"Library/DislocationDynamics/DD.txt", input /
"DD.txt");
168 std::filesystem::create_directories(folder /
"config");
169 const double length=3671.9477120460206;
171 std::ofstream
f(input /
"DefectiveCrystal.txt");
172 f <<
"physics=DislocationDynamics;\nuseFEM=0;\nNsteps=0;\nmaxResolveSteps=0;\ndtMax=1;\noutputFrequency=1;\noutputBinary=0;\nstartAtTimeStep=0;\nperiodicImageSize=0 0 0;\nEwaldLengthFactor=0;\n";
173 std::ofstream
p(input /
"polycrystal.txt");
174 p << std::setprecision(17) <<
"materialFile=W.txt;\nmeshFile=mesh.msh;\nabsoluteTemperature=300;\nC2G1=1 0 0 0 1 0 0 0 1;\n"
175 <<
"C2G2=0.8 0 0.6 0 1 0 -0.6 0 0.8;\nF=" << length <<
" 0 0 0 " << length <<
" 0 0 0 " << length
176 <<
";\nX0=0 0 0;\nperiodicFaceIDs=-1;\n";
182 std::ifstream stream(
argc==3 ? std::filesystem::path(
argv[2]) : root/
"tests/data/bicrystalSharedConstraints1915.txt");
183 require(
bool(stream),
"Missing bicrystal junction regression fixture");
188 omp_set_num_threads(
argc==3 ? 12 : 2);
193 std::shared_ptr<Network::NetworkLinkType> shared;
196 const auto link=entry.second.lock();
197 if(link->loopLinks().size()>1 && link->chordLength()>1 && !link->isBoundarySegment())
203 require(
bool(shared),
"Missing shared junction for topology-change test");
204 const auto memberships=shared->loopLinks().size();
208 require(inserted->loopNodes().size()==memberships,
"Expansion lost junction sharing");
214 std::filesystem::remove_all(folder);
215 std::cout<<
"PASS: exact cross-slip traversal and selection equivalence before and after shared junction topology changes\n";
218 catch(
const std::exception& error)
220 std::cerr<<error.what()<<
'\n';
void read(const size_t &runID)
void readTxtStream(std::istream &infile)
void initializeConfiguration(const DefectiveCrystalConfigIO< dim > &configIO)
bool computeDDinteractions
DefectiveCrystalBase< dim > & ddBase
TraitsType::NetworkLinkType NetworkLinkType
void initializeConfiguration(const DefectiveCrystalConfigIO< dim > &configIO, const std::ofstream &f_file, const std::ofstream &F_labels) override
VectorDim pkIntegral() const
bool isGrainBoundarySegment() const
bool isBoundarySegment() const
const VectorDim & burgers() const
GrainContainerType grains() const
const LoopContainerType & loops() const
const NetworkNodeContainerType & networkNodes() const
NetworkLinkContainerType & networkLinks()
SharedNetworkNodePtrType expandNetworkLink(const std::shared_ptr< NetworkLinkType > &Lij, const SharedNetworkNodePtrType &networkNode)
void removeNetworkNode(const size_t &nodeID)
const LoopNetworkType & network() const
LoopLinkContainerType & loopLinks()
const VectorDim & unitDirection() const
const double & chordLength() const
function int_R syms a b c u real f
DefectiveCrystalParameters simulationParameters
const DefectiveCrystalTraitsIO traitsIO
std::shared_ptr< MicrostructureType > getUniqueTypedMicrostructure() const
SharedPtrType create(const Args &...args)
void verify(Network &network)
std::pair< bool, std::pair< int, int > > legacySelection(const Network::NetworkLinkType &link, const model::AthermalCrossSlipModel< model::TypeTraits< Network >::dim > &model)
std::pair< bool, int > legacyBase(const Network::NetworkLinkType &link, const model::AthermalCrossSlipModel< model::TypeTraits< Network >::dim > &model, const bool enforceRemeshLength=true)
model::DislocationNetwork< 3 > Network
void require(bool condition, const char *message)