Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
ImmobileSinkRate.h
Go to the documentation of this file.
1
2#ifndef model_ImmobileSinkRate_H_
3#define model_ImmobileSinkRate_H_
4
5#include <Eigen/Dense>
6#include <EvalFunction.h>
9
10namespace model
11{
12
13template <typename MobileTrialFunctionType, typename ImmobileTrialFunctionType>
14struct ImmobileSinkRate : public EvalFunction<ImmobileSinkRate<MobileTrialFunctionType,ImmobileTrialFunctionType>>
15{
16
17 constexpr static int rows=ImmobileTrialFunctionType::rows;
18 constexpr static int cols=1;
19 constexpr static int mSize=MobileTrialFunctionType::rows;
20 constexpr static int iSize=ImmobileTrialFunctionType::rows;
21 constexpr static int dim = MobileTrialFunctionType::dim;
22
25
27 const std::shared_ptr<MobileTrialFunctionType> cM; // Mobile defect concentration
28 const std::shared_ptr<MobileEvalFunctionType> cMe;
29
31 const std::shared_ptr<ImmobileTrialFunctionType> cI; // Immobile loop concentration
32 const std::shared_ptr<ImmobileEvalFunctionType> cIe;
33
34 const Eigen::Matrix<double,mSize,1> inFactors;
35 const Eigen::Matrix<double,mSize,1> outFactors;
36
37 /**********************************************************************/
38 ImmobileSinkRate(const std::shared_ptr<MobileTrialFunctionType>& cM_in, const std::shared_ptr<ImmobileTrialFunctionType>& cI_in, const ClusterDynamicsParameters<3>& cdp_in, const PolycrystallineMaterialBase& mat_in) :
39 /* init */ cdp(cdp_in),
40 /* init */ mat(mat_in),
41 /* init */ cM(cM_in),
42 /* init */ cMe(eval(cM_in)),
43 /* init */ cI(cI_in),
44 /* init */ cIe(eval(cI_in)),
45 // /* init */ stress(stress_in),
46 // /* init */ stresse(stress_in),
47 /* init */ inFactors((1.0/cdp.msVector.abs()).matrix()),
48 /* init */ outFactors(cdp.msVector.abs().matrix())
49 {
50
51 }
52
53 // // /**********************************************************************/
54 // Eigen::Array<double,iSize/2,mSize> biasSIPA(const Eigen::Matrix<double,3,3>& ExternalS, const size_t& gID) const
55 // {
56 // const Eigen::Matrix<double,3,3> lat(poly.grains().at(gID).latticeBasis);
57 // const Eigen::Matrix<double,3,1> a1(lat.col(0).normalized());
58 // const Eigen::Matrix<double,3,1> a2(lat.col(1).normalized());
59 // const Eigen::Matrix<double,3,1> a3((a2-a1).normalized());
60 // const Eigen::Matrix<double,3,1> c(lat.col(2).normalized());
61
62 // const Eigen::Matrix<double,iSize/2,1> temp((Eigen::Matrix<double,iSize/2,1>()<< -(ExternalS*c).dot(c)*cdp.omega/cdp.kB/cdp.T, // SIPA c
63 // /* */ -(ExternalS*a1).dot(a1)*cdp.omega/cdp.kB/cdp.T, // SIPA a1
64 // /* */ -(ExternalS*a2).dot(a2)*cdp.omega/cdp.kB/cdp.T, // SIPA a2
65 // /* */ -(ExternalS*a3).dot(a3)*cdp.omega/cdp.kB/cdp.T).finished());
66
67 // return exp((temp*cdp.speciesVector.matrix()).array());
68 // }
69
70 /**********************************************************************/
71 Eigen::Array<double,iSize/2,mSize> biasDRIFT() const
72 {
73 const Eigen::Matrix<double,iSize/2,1> temp(Eigen::MatrixXd::Constant(iSize/2,1,1.0));
74 return (temp*cdp.immobileBias.matrix()).array();
75 }
76
77 /**********************************************************************/
78 Eigen::Array<double,iSize/2,mSize> biasDAD(Eigen::Array<double,1,mSize>& p) const
79 {
80 Eigen::Array<double,iSize/2,mSize> temp(Eigen::Array<double,iSize/2,mSize>::Zero());
81 if(iSize>0)
82 {
83 for(int i=0; i<iSize/2; i++)
84 {
85 for(int j=0;j<mSize;j++)
86 {
87 temp(i,j) = i%(iSize/2)==0 ? p[j] : (p[j]+1.0/p[j]/p[j])/2.0;
88 }
89 }
90 }
91
92 return temp;
93 }
94
95 /**********************************************************************/
96 // Eigen::Matrix<double,iSize,mSize> sinkStrengths(const Eigen::Matrix<double,iSize,1>& sinkValue, const Eigen::Matrix<double,3,3>& ExternalS, const size_t& gID) const
97 Eigen::Matrix<double,iSize,mSize> sinkStrengths(const Eigen::Matrix<double,iSize,1>& sinkValue, const size_t& gID) const
98 {// Get the stress and the grainID in and compute SIPA in sink strengthes
99 // a1, a2, a3 and c can be get in poly.grains.at(grainID).latticeBasis
100
101 Eigen::Matrix<double,iSize,1> correctedSinkValue(sinkValue);
102 for(int dof=0;dof<iSize/2;dof++)
103 { // Corrected sink strength is to adjust for negative values at the barycenter of the quadratic elements where we have a sharp gradient of sink values between two end nodes
104 const double cmin = cdp.n_min(dof)*cdp.omega*correctedSinkValue(dof);
105 if(correctedSinkValue(iSize/2+dof)<cmin)
106 { // defect size cannot be smaller than a minimal value
107 correctedSinkValue(iSize/2+dof)=cmin;
108 }
109 }
110
111 const std::vector<Eigen::Matrix<double,3,3>> Dlocal(cdp.getDlocal());
112 Eigen::Array<double,1,mSize> aveD(Eigen::Array<double,1,mSize>::Zero()); // Average diffusion coefficient
113 Eigen::Array<double,1,mSize> p(Eigen::Array<double,1,mSize>::Zero()); // Diffusion difference
114 for(int k=0;k<mSize;k++)
115 {
116 aveD(k)=pow(Dlocal[k].determinant(),1.0/3.0);
117 p(k) =pow(Dlocal[k](2,2)/Dlocal[k](0,0),1.0/6.0);
118 }
119
120 // const Eigen::Array<double,iSize/2,mSize> ZSIPA(biasSIPA(ExternalS,gID));
121 const Eigen::Array<double,iSize/2,mSize> ZDRIFT(biasDRIFT());
122 const Eigen::Array<double,iSize/2,mSize> ZDAD(biasDAD(p));
123
124 //std::cout<<sinkValue.minCoeff()<<std::endl;
125 assert(correctedSinkValue.minCoeff()>=0.0 && "Sink Value is smaller than or equals 0.");
126 // std::cout<<"sinkValue: \n"<<sinkValue.transpose()<<std::endl;
127
128 // <c> cluster is in pyramidal shape at first
129 //Eigen::Array<double,iSize/2,1> loopRadius( (correctedSinkValue.template block<iSize/2,1>(iSize/2,0).array()/correctedSinkValue.template block<iSize/2,1>(0,0).array()/M_PI/cdp.immobileSpeciesBurgersMagnitude.transpose()).sqrt() );
130 //Eigen::Matrix<double,iSize/2,1> loopsDensity(2.0*M_PI*loopRadius*correctedSinkValue.template block<iSize/2,1>(0,0).array());
131 //loopRadius(0) = cdp.vclusterRadius(correctedSinkValue(iSize/2),correctedSinkValue(0));
132 //loopsDensity(0) = 0.2*4.0*M_PI*loopRadius(0)*correctedSinkValue(0);
133
134 const Eigen::Matrix<double,iSize/2,1> disDensity((Eigen::Matrix<double,iSize/2,1>()<<cdp.dislocationSinks(0), //dislocation density c
135 cdp.dislocationSinks(1), //a1
136 cdp.dislocationSinks(2), //a2
137 cdp.dislocationSinks(3)).finished());
138 const Eigen::Matrix<double,iSize/2,1> defectDensity(cdp.clusterDensity(correctedSinkValue.template block<iSize/2,1>(iSize/2,0).array(),correctedSinkValue.template block<iSize/2,1>(0,0).array()).transpose().matrix());
139 const Eigen::Array<double,iSize/2,mSize> rholD((defectDensity*aveD.matrix()).array());
140 const Eigen::Array<double,iSize/2,mSize> rhodD((disDensity*aveD.matrix()).array());
141
142 // const Eigen::Array<double,iSize/2,mSize> Zloop = ZSIPA*ZDRIFT*ZDAD;
143 const Eigen::Array<double,iSize/2,mSize> Zloop = ZDAD*ZDRIFT;
144 const Eigen::Array<double,iSize/2,mSize> Zpyr(Eigen::Array<double,iSize/2,mSize>::Ones());
145 Eigen::Array<double,iSize/2,mSize> Ztotal(Eigen::Array<double,iSize/2,mSize>::Zero());
146
147 for(int k=0;k<mSize;k++)
148 {
149 Ztotal.col(k) = cdp.sigmoidalVectorInterpolation(correctedSinkValue.template block<iSize/2,1>(iSize/2,0).array(),correctedSinkValue.template block<iSize/2,1>(0,0).array(),Zpyr.col(k),Zloop.col(k));
150 }
151
152 const Eigen::Matrix<double,iSize/2,mSize> loopStrength(Ztotal*rholD); // note that the array multiplication is element-wise
153 const Eigen::Matrix<double,iSize/2,mSize> disStrengh(Zloop*rhodD); // note that the array multiplication is element-wise
154
155 Eigen::Matrix<double,iSize,mSize> sStrengh;
156 sStrengh << loopStrength,
157 disStrengh;
158
159 return sStrengh;
160 }
161 /**********************************************************************/
162 /**********************************************************************/
163
164 template<typename ElementType, typename BaryType>
165 const Eigen::Matrix<double,rows,cols> operator() (const ElementType& ele, const BaryType& bary) const
166 {
170
171 const Eigen::Matrix<double,mSize,1> Cvalue(inFactors.asDiagonal()*(*cMe)(ele,bary)); // Local concentration
172 const Eigen::Array<double,rows,1> sinkvalue((*cIe)(ele,bary).array());
173// const Eigen::Array<double,rows/2,1> loopsDensity(2.0*M_PI*sinkvalue.template block<rows/2,1>(0,0)*sinkvalue.template block<rows/2,1>(rows/2,0));
174
175 // const Eigen::Matrix<double,6,1> tempS(stresse(ele,bary));
176 // Eigen::Matrix<double,3,3> ExternalS;
177 // ExternalS(0,0)=tempS(0); // s11
178 // ExternalS(1,1)=tempS(1); // s22
179 // ExternalS(2,2)=tempS(2); // s33
180 // ExternalS(1,0)=tempS(3); // s21
181 // ExternalS(2,1)=tempS(4); // s32
182 // ExternalS(2,0)=tempS(5); // s31
183 // ExternalS(0,1)=ExternalS(1,0); //symm
184 // ExternalS(1,2)=ExternalS(2,1); //symm
185 // ExternalS(0,2)=ExternalS(2,0); //symm
186
187 const size_t gID(*(ele.simplex.regionIDs().begin()));
188
189 const Eigen::Matrix<double,rows,mSize> sStrengh(sinkStrengths(sinkvalue,gID));
190 const Eigen::Matrix<double,mSize,mSize> speciesFactors(cdp.msVector.matrix().asDiagonal());
191 const Eigen::Array<double,rows/2,1> fluxs((sStrengh.template block<rows/2,mSize>(0,0)*(speciesFactors*Cvalue)).array());
192
193 Eigen::Matrix<double,rows,cols> temp(Eigen::Matrix<double,rows,cols>::Zero());
194 temp.template block<rows/2,cols>(rows/2,0) = (cdp.immobileSpeciesVector.transpose()*fluxs).matrix();
195
196 return temp;
197 }
198
199};
200
201
202} // namespace model
203
204#endif
auto eval(const std::shared_ptr< T > &t)
const Eigen::Matrix< double, rows, cols > operator()(const ElementType &ele, const BaryType &bary) const
EvalExpression< ImmobileTrialFunctionType > ImmobileEvalFunctionType
Eigen::Array< double, iSize/2, mSize > biasDRIFT() const
const std::shared_ptr< MobileEvalFunctionType > cMe
static constexpr int iSize
const Eigen::Matrix< double, mSize, 1 > outFactors
Eigen::Matrix< double, iSize, mSize > sinkStrengths(const Eigen::Matrix< double, iSize, 1 > &sinkValue, const size_t &gID) const
static constexpr int cols
const std::shared_ptr< ImmobileTrialFunctionType > cI
const Eigen::Matrix< double, mSize, 1 > inFactors
const PolycrystallineMaterialBase & mat
const std::shared_ptr< ImmobileEvalFunctionType > cIe
EvalExpression< MobileTrialFunctionType > MobileEvalFunctionType
const ClusterDynamicsParameters< dim > & cdp
static constexpr int mSize
static constexpr int rows
Eigen::Array< double, iSize/2, mSize > biasDAD(Eigen::Array< double, 1, mSize > &p) const
const std::shared_ptr< MobileTrialFunctionType > cM
ImmobileSinkRate(const std::shared_ptr< MobileTrialFunctionType > &cM_in, const std::shared_ptr< ImmobileTrialFunctionType > &cI_in, const ClusterDynamicsParameters< 3 > &cdp_in, const PolycrystallineMaterialBase &mat_in)
static constexpr int dim
Eigen::MatrixXd matrix(const Form &form)
int j
vertex p[3]
int k
int i
vertex temp