Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
DislocationMobilityPy.cpp
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 * Written in 2024 by Matthew Maron <mlm335@miami.edu>
3 *
4 *
5 * MoDELib is distributed without any warranty under the
6 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
7 */
8
9#ifndef _model_DislocationMobilityPy_cpp_
10#define _model_DislocationMobilityPy_cpp_
11
13#include <filesystem>
14
15namespace model
16{
17#ifdef _MODEL_PYBIND11_ // COMPILED WITH PYBIND11
18 DislocationMobilityPy::DislocationMobilityPy(const PolycrystallineMaterialBase& material,const std::string& pyModuleName_in) :
19 /* init */ DislocationMobility("DislocationMobilityPy for "+material.materialName)
20 /* init */,kB(kB_SI/material.mu_SI/std::pow(material.b_SI,3))
21 /* init */,mu_SI(material.mu_SI)
22 /* init */,Tm(material.Tm)
23 /* init */,cs(material.cs_SI)
24 /* init */,pyModuleName(pyModuleName_in)
25 {// Set up pyModule
26 std::filesystem::path modulePath(pyModuleName);
27 const std::string moduleStem(modulePath.stem().string());
28 const std::string moduleDir(modulePath.parent_path().string());
29 std::cout<<"moduleStem="<<moduleStem<<std::endl;
30 std::cout<<"moduleDir="<<moduleDir<<std::endl;
31 pybind11::module sys = pybind11::module::import("sys");
32 pybind11::list path = sys.attr("path");
33 path.append(moduleDir);
34 pyModule = pybind11::module::import(moduleStem.c_str());
35 }
36
38 const VectorDim& b,
39 const VectorDim& xi,
40 const VectorDim& n,
41 const double& T,
42 const double& dL,
43 const double& dt,
44 const std::shared_ptr<StochasticForceGenerator>& ) const
45 {
46 Eigen::MatrixXd stress(S*mu_SI*1e-9); // GPa
47 Eigen::VectorXd burgers(b); // Vector Direction
48 Eigen::VectorXd tangent(xi); // Vector Direction
49 Eigen::VectorXd normal(n); // Vector Direction
50 const double temp(T); // K
51
52 try
53 {
54 pybind11::object mobilitySolver = pyModule.attr("MobilitySolver")();
55 double qpPythonVelocity = mobilitySolver.attr("velocityPy")(stress, burgers, tangent, normal, temp, dL, dt).cast<double>();
56 return qpPythonVelocity*100/cs; //Convert from A/ps to code units
57 }
58 catch (const pybind11::error_already_set& e)
59 {
60 std::cerr << "Python error: " << e.what() << std::endl;
61 std::terminate();
62 }
63
64
65 }
66
67#else // COMPILED WITHOUT PYBIND11
68 DislocationMobilityPy::DislocationMobilityPy(const PolycrystallineMaterialBase& material,const std::string& pyModuleName_in) :
69 /* init */ DislocationMobility("DislocationMobilityPy for "+material.materialName)
70 /* init */,kB(kB_SI/material.mu_SI/std::pow(material.b_SI,3))
71 /* init */,mu_SI(material.mu_SI)
72 /* init */,Tm(material.Tm)
73 /* init */,cs(material.cs_SI)
74 /* init */,pyModuleName(pyModuleName_in)
75 {
76 }
77
79 const VectorDim& ,
80 const VectorDim& ,
81 const VectorDim& ,
82 const double& ,
83 const double& ,
84 const double& ,
85 const std::shared_ptr<StochasticForceGenerator>& ) const
86 {
87 throw std::runtime_error("DislocationMobilityPy used without pybind11");
88 return 0.0;
89 }
90#endif
91
92}
93#endif
the tangent vector S
b
Definition int_R.m:16
Eigen::Matrix< double, 3, 1 > VectorDim
Definition pyMoDELib.cxx:66
Eigen::Matrix< double, 3, 3 > MatrixDim
Definition pyMoDELib.cxx:67
DislocationMobility(const std::string &name_in)
Eigen::Matrix< double, 3, 3 > MatrixDim
double velocity(const MatrixDim &S, const VectorDim &b, const VectorDim &xi, const VectorDim &n, const double &T, const double &dL, const double &dt, const std::shared_ptr< StochasticForceGenerator > &sfg) const override
DislocationMobilityPy(const PolycrystallineMaterialBase &material, const std::string &pyModuleName_in)
Eigen::Matrix< double, 3, 1 > VectorDim
REAL * xi
int e
vertex temp