Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
DislocationMobilitySelector.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_DislocationMobilitySelector_cpp_
9#define _model_DislocationMobilitySelector_cpp_
10
11#include <numbers>
12#include <string> // std::string
19#include <StrUtilities.h>
20#include <TextFileParser.h>
21#include <LinearInterpolant.h>
22#include <LagrangeInterpolant.h>
23
24namespace model
25{
26
27 std::shared_ptr<DislocationMobility> DislocationMobilitySelector::getMobility(const PolycrystallineMaterialBase& material,
28 const std::string& tag) const
29 {
30 std::cout<<"tag="<<tag<<std::endl;
31 std::stringstream sstream(tag);
32 std::string mobilityType;
33 sstream >> mobilityType;
34 std::cout<<"mobilityType="<<mobilityType<<std::endl;
35
36 if(StrUtilities::lowercase(StrUtilities::removeSpaces((mobilityType)))=="none")
37 {
38 return nullptr;
39 }
40 else if(StrUtilities::lowercase(StrUtilities::removeSpaces((mobilityType)))=="edgescrew")
41 {
42 TextFileParser parser(material.materialFile);
43 std::string edgeSuffix;
44 sstream >> edgeSuffix;
45 std::string screwSuffix;
46 sstream >> screwSuffix;
47 const auto edgeMobility(getMobilityBase(material,parser.readString("mobility_"+ edgeSuffix)));
48 const auto screwMobility(getMobilityBase(material,parser.readString("mobility_"+screwSuffix)));
49 return std::shared_ptr<DislocationMobilityEdgeScrew>(new DislocationMobilityEdgeScrew(material,edgeMobility,screwMobility));
50 }
51 else if(StrUtilities::lowercase(StrUtilities::removeSpaces((mobilityType)))=="python")
52 {
53 std::string pyPath;
54 sstream >> pyPath;
55 return std::shared_ptr<DislocationMobilityPy>(new DislocationMobilityPy(material,pyPath));
56 }
57 else if(StrUtilities::lowercase(StrUtilities::removeSpaces((mobilityType)))=="interpolated")
58 {
59 TextFileParser parser(material.materialFile);
60
61 std::string interpolationType;
62 sstream >> interpolationType;
63 ; // periodic extrapolation of period 2pi
65 std::map<double,std::shared_ptr<DislocationMobilityBase>> mobilityMap;
66 std::string angleDeg;
67 while (sstream >> angleDeg)
68 {
69 size_t foundUnderscore(angleDeg.find_last_of('_'));
70 if(foundUnderscore != std::string::npos)
71 {
72 const double angleRad(std::stod(angleDeg.substr(foundUnderscore+1))*std::numbers::pi/180.0);
73 vMap[angleRad]=0.0;
74 mobilityMap[angleRad]=getMobilityBase(material,parser.readString("mobility_"+ angleDeg));
75 }
76 else
77 {
78 throw std::runtime_error(angleDeg+" NOT in the format label_angleDeg");
79 }
80
81 }
82
83
84 if(StrUtilities::lowercase(StrUtilities::removeSpaces((interpolationType)))=="linear")
85 {
86 std::shared_ptr<LinearInterpolant> interpolant(new LinearInterpolant(vMap,ExtrapolationMethod(2,std::numbers::pi)));
87 return std::shared_ptr<DislocationMobilityInterpolated>(new DislocationMobilityInterpolated(material,interpolant,mobilityMap,false));
88 }
89 else if(StrUtilities::lowercase(StrUtilities::removeSpaces((interpolationType)))=="logarithmic")
90 {
91 std::shared_ptr<LinearInterpolant> interpolant(new LinearInterpolant(vMap,ExtrapolationMethod(2,std::numbers::pi)));
92 return std::shared_ptr<DislocationMobilityInterpolated>(new DislocationMobilityInterpolated(material,interpolant,mobilityMap,true));
93 }
94 else if(StrUtilities::lowercase(StrUtilities::removeSpaces((interpolationType)))=="lagrange")
95 {
96 std::shared_ptr<LagrangeInterpolant> interpolant(new LagrangeInterpolant(vMap,ExtrapolationMethod(2,std::numbers::pi)));
97 return std::shared_ptr<DislocationMobilityInterpolated>(new DislocationMobilityInterpolated(material,interpolant,mobilityMap));
98 }
99 else
100 {
101 throw std::runtime_error("unknown interpolationType of type "+interpolationType);
102 return nullptr;
103 }
104 }
105 else
106 {
107 throw std::runtime_error("unknown DislocationMobility of type "+mobilityType);
108 return nullptr;
109 }
110 }
111
112 std::shared_ptr<DislocationMobilityBase> DislocationMobilitySelector::getMobilityBase(const PolycrystallineMaterialBase& material,
113 const std::string& tag) const
114 {
115 std::stringstream sstream(tag);
116 std::string mobilityType;
117 sstream >> mobilityType;
118 if(StrUtilities::lowercase(StrUtilities::removeSpaces((mobilityType)))=="viscousdrag")
119 {
120 std::string B0_SI;
121 sstream >> B0_SI;
122 std::string B1_SI;
123 sstream >> B1_SI;
124 return std::shared_ptr<DislocationMobilityViscousDrag>(new DislocationMobilityViscousDrag(material,
125 std::stod(B0_SI),
126 std::stod(B1_SI)));
127 }
128 else if(StrUtilities::lowercase(StrUtilities::removeSpaces((mobilityType)))=="kinkpair")
129 {
130 std::string h;
131 sstream >> h;
132 std::string w;
133 sstream >> w;
134 std::string B0_SI;
135 sstream >> B0_SI;
136 std::string B1_SI;
137 sstream >> B1_SI;
138 std::string Bk_SI;
139 sstream >> Bk_SI;
140 std::string dH0_eV;
141 sstream >> dH0_eV;
142 std::string p_in;
143 sstream >> p_in;
144 std::string q_in;
145 sstream >> q_in;
146 std::string T0_hom;
147 sstream >> T0_hom;
148 std::string tauC_SI;
149 sstream >> tauC_SI;
150 std::string a0_in;
151 sstream >> a0_in;
152 std::string a1_in;
153 sstream >> a1_in;
154 std::string a2_in;
155 sstream >> a2_in;
156 std::string a3_in;
157 sstream >> a3_in;
158 std::string conjugateAngle_deg;
159 sstream >> conjugateAngle_deg;
160
161 return std::shared_ptr<DislocationMobilityKinkPair>(new DislocationMobilityKinkPair(material,
162 std::stod(h),
163 std::stod(w),
164 std::stod(B0_SI),
165 std::stod(B1_SI),
166 std::stod(Bk_SI),
167 std::stod(dH0_eV),
168 std::stod(p_in),
169 std::stod(q_in),
170 std::stod(T0_hom),
171 std::stod(tauC_SI),
172 std::stod(a0_in),
173 std::stod(a1_in),
174 std::stod(a2_in),
175 std::stod(a3_in),
176 std::stod(conjugateAngle_deg)));
177 }
178 else
179 {
180 throw std::runtime_error("unknown DislocationMobilityBase of type "+mobilityType);
181 return nullptr;
182 }
183 }
184
185}
186#endif
std::map< double, double > MapType
std::shared_ptr< DislocationMobilityBase > getMobilityBase(const PolycrystallineMaterialBase &material, const std::string &tag) const
std::shared_ptr< DislocationMobility > getMobility(const PolycrystallineMaterialBase &material, const std::string &tag) const
static std::string lowercase(std::string text)
static std::string removeSpaces(std::string key)
REAL w[16]
REAL * h