Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
GlidePlaneNoise.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_GlidePlaneNoise_cpp
9#define model_GlidePlaneNoise_cpp
10
11#include <algorithm>
12#include <filesystem>
13#include <GlidePlaneNoise.h>
14#include <StrUtilities.h>
15
16namespace model
17{
18
20 {
21 const auto noiseFiles(TextFileParser(mat.materialFile).readStringVector("glidePlaneNoise"));
22 for(const auto& pair : noiseFiles)
23 {
24 const auto noiseFileString(StrUtilities::removeSpaces(pair.first));
25 if(noiseFileString!="none" && noiseFileString!="None")
26 {
27 const std::string noiseFileName(std::filesystem::path(mat.materialFile).parent_path().string()+"/"+noiseFileString);
28 TextFileParser parser(noiseFileName);
29 const std::string type(StrUtilities::removeSpaces(parser.readString("type",true)));
30 const std::string tag(StrUtilities::removeSpaces(parser.readString("tag",true)));
31 const int seed(parser.readScalar<int>("seed",true));
32 const Eigen::Matrix<int,1,3> gridSize(parser.readMatrix<int,1,3>("gridSize",true));
33 const Eigen::Matrix<double,1,3> gridSpacing(parser.readMatrix<double,1,3>("gridSpacing_SI",true)/mat.b_SI);
34
35 if(type=="AnalyticalSolidSolutionNoise")
36 {
37 const double a(parser.readScalar<double>("spreadLstress_SI",true)/mat.b_SI); // spreading length for stresses [AA]
38 const double a_Cai(parser.readScalar<double>("a_cai_SI",true)/mat.b_SI);
39 const double MSSS(parser.readScalar<double>("MSSS_SI",true)/std::pow(mat.mu_SI,2));
40 const auto success(solidSolutionNoise().emplace(tag,new AnalyticalSolidSolutionNoise(tag,seed,gridSize,gridSpacing,Eigen::Matrix<double,2,2>::Identity(),a,a_Cai,MSSS)));
41
42 if(!success.second)
43 {
44 throw std::runtime_error("Could not insert noise "+tag);
45 }
46 }
47 if(type=="MDSolidSolutionNoise")
48 {
49 const double a_Cai(parser.readScalar<double>("a_cai_SI",true)/mat.b_SI);
50
51 // relative paths for correlation vtk files (easier to make everything self contained)
52 const std::string correlationFile_xz(std::filesystem::path(mat.materialFile).parent_path().string()+"/"+StrUtilities::removeSpaces(parser.readString("correlationFile_xz",true)));
53 const std::string correlationFile_yz(std::filesystem::path(mat.materialFile).parent_path().string()+"/"+StrUtilities::removeSpaces(parser.readString("correlationFile_yz",true)));
54
55 const auto success(solidSolutionNoise().emplace(tag,new MDSolidSolutionNoise(mat,tag,correlationFile_xz,correlationFile_yz,seed,gridSize,gridSpacing,Eigen::Matrix<double,2,2>::Identity(),a_Cai)));
56 if(!success.second)
57 {
58 throw std::runtime_error("Could not insert noise "+tag);
59 }
60 }
61 if(type=="MDStackingFaultNoise")
62 {
63 // relative paths for correlation vtk files (easier to make everything self contained)
64 const std::string correlationFile_stackingFault(std::filesystem::path(mat.materialFile).parent_path().string()+"/"+StrUtilities::removeSpaces(parser.readString("correlationFile",true)));
65
66 const auto success(stackingFaultNoise().emplace(tag,new MDStackingFaultNoise(mat,tag,correlationFile_stackingFault,seed,gridSize,gridSpacing,Eigen::Matrix<double,2,2>::Identity())));
67
68 if(!success.second)
69 {
70 throw std::runtime_error("Could not insert noise "+tag);
71 }
72 }
73 if(type=="MDShortRangeOrderNoise")
74 {
75
76 }
77 }
78
79
80 }
81 for(auto& pair : solidSolutionNoise())
82 {
83 pair.second->computeRealNoise();
84 pair.second->computeRealNoiseStatistics(mat);
85 }
86
87 for(auto& pair : stackingFaultNoise())
88 {
89 pair.second->computeRealNoise();
90 pair.second->computeRealNoiseStatistics(mat);
91 }
92
93 }
94
95 std::tuple<double,double,double> GlidePlaneNoise::gridInterp(const Eigen::Matrix<double,2,1>& localPos) const
96 { // Added by Hyunsoo (hyunsol@g.clemson.edu)
97 double effsolNoiseXZ(0.0);
98 double effsolNoiseYZ(0.0);
99 for(const auto& noise : solidSolutionNoise())
100 {
101 const auto idxAndWeights(noise.second->posToPeriodicCornerIdxAndWeights(localPos));
102 for(size_t p=0;p<idxAndWeights.first.size();++p)
103 {
104 const int storageID(noise.second->storageIndex(idxAndWeights.first[p](0),idxAndWeights.first[p](1)));
105 effsolNoiseXZ+=noise.second->operator[](storageID)(0)*idxAndWeights.second[p];
106 effsolNoiseYZ+=noise.second->operator[](storageID)(1)*idxAndWeights.second[p];
107 }
108 }
109
110 double effsfNoise(0.0);
111 for(const auto& noise : stackingFaultNoise())
112 {
113 // transform the basis if it is non-orthogonal
114 //const auto idxAndWeights(noise.second->posToPeriodicCornerIdxAndWeights(localPos));
115 const auto idxAndWeights(noise.second->posToPeriodicCornerIdxAndWeights(noise.second->invTransposeLatticeBasis*localPos));
116
117 for(size_t p=0;p<idxAndWeights.first.size();++p)
118 {
119 const int storageID(noise.second->storageIndex(idxAndWeights.first[p](0),idxAndWeights.first[p](1)));
120 effsfNoise+=noise.second->operator[](storageID)*idxAndWeights.second[p];
121 }
122 }
123 return std::make_tuple(effsolNoiseXZ,effsolNoiseYZ,effsfNoise);
124 }
125
126 std::tuple<double,double,double> GlidePlaneNoise::gridVal(const Eigen::Array<int,2,1>& idx) const
127 { // Added by Hyunsoo (hyunsol@g.clemson.edu)
128
129 double effsolNoiseXZ(0.0);
130 double effsolNoiseYZ(0.0);
131 for(const auto& noise : solidSolutionNoise())
132 {
133 const Eigen::Array<int,2,1> pidx(noise.second->idxToPeriodicIdx(idx));
134 const int storageID(noise.second->storageIndex(pidx(0),pidx(1)));
135 effsolNoiseXZ+=noise.second->operator[](storageID)(0);
136 effsolNoiseYZ+=noise.second->operator[](storageID)(1);
137 }
138
139 double effsfNoise(0.0);
140 for(const auto& noise : stackingFaultNoise())
141 {
142 const Eigen::Array<int,2,1> pidx(noise.second->idxToPeriodicIdx(idx));
143 const int storageID(noise.second->storageIndex(pidx(0),pidx(1)));
144 effsfNoise+=noise.second->operator[](storageID);
145 }
146
147 return std::make_tuple(effsolNoiseXZ,effsolNoiseYZ,effsfNoise);
148 }
149
151 {
152 return *this;
153 }
154
159
161 {
162 return *this;
163 }
164
169
170// typename GlidePlaneNoise::GridSizeType GlidePlaneNoise::rowAndColIndices(const int& storageIdx) const
171// {
172// return GridSizeType(storageIdx/this->gridSize(1), storageIdx%this->gridSize(1));
173// }
174
175// int GlidePlaneNoise::storageIndex(const int& i,const int& j) const
176// {/*!\param[in] localPos the position vector on the grid
177// * \returns The grid index periodically wrapped within the gridSize bounds
178// */
179// return gridSize(1)*i+j;
180// }
181
182}
183#endif
184
std::vector< std::pair< std::string, std::string > > readStringVector(const std::string &key)
a
Definition int_R.m:14
const StackingFaultNoiseContainer & stackingFaultNoise() const
GlidePlaneNoise(const PolycrystallineMaterialBase &mat)
std::tuple< double, double, double > gridInterp(const Eigen::Matrix< double, 2, 1 > &localPos) const
const SolidSolutionNoiseContainer & solidSolutionNoise() const
std::map< std::string, std::shared_ptr< GlidePlaneNoiseBase< 1 > > > StackingFaultNoiseContainer
std::map< std::string, std::shared_ptr< GlidePlaneNoiseBase< 2 > > > SolidSolutionNoiseContainer
std::tuple< double, double, double > gridVal(const Eigen::Array< int, 2, 1 > &idx) const
static std::string removeSpaces(std::string key)
vertex p[3]
enum insertvertexresult success