Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
SecondOrderReaction.h
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_SecondOrderReaction_H_
9#define model_SecondOrderReaction_H_
10
11//#include <DefectiveCrystal/MicrostructureContainer.h>
12//#include <ClusterDynamics/ClusterDynamicsParameters.h>
13//#include <ClusterDynamics/ClusterDynamicsBase.h>
14//#include <SimpleNullSpaceSolver.h>
15//#include <FixedDirichletSolver.h>
16//#include <DefectiveCrystal/UniformController.h>
17#include <Eigen/Dense>
18#include <EvalFunction.h>
20
21namespace model
22{
23
24template <typename TrialFunctionType>
25struct SecondOrderReaction : public EvalFunction<SecondOrderReaction<TrialFunctionType>>
26{
27
28 constexpr static int rows=TrialFunctionType::rows;
29 constexpr static int cols=rows;
30 constexpr static int dim=TrialFunctionType::dim;
31 constexpr static int mSize=rows;
32
34// const ODESystem& odeS;
35
36// typedef TrialFunction<'c',4,FiniteElementType> TrialFunctionType;
38 const std::shared_ptr<TrialFunctionType> c; // concentration field
39 const std::shared_ptr<EvalFunctionType> ce;
40 const Eigen::Matrix<double,rows,1> inFactors;
41 const Eigen::Matrix<double,rows,1> outFactors;
42
43 /**********************************************************************/
44 SecondOrderReaction(const std::shared_ptr<TrialFunctionType>& c_in, const ClusterDynamicsParameters<dim>& cdp_in) :
45 /* init */ cdp(cdp_in),
46 /* init */ c(c_in),
47 /* init */ ce(eval(c_in)),
48 /* init */ inFactors((1.0/cdp.msVector.abs()).matrix()),
49 /* init */ outFactors(cdp.msVector.abs().matrix())
50 {
51
52 }
53
54// std::vector<Eigen::Matrix<double,mSize,mSize>> buildR2(const Eigen::Matrix<double,mSize,1>& cin) const
55// {
56// Eigen::Array<double,1,mSize> rn(Eigen::Array<double,1,mSize>::Zero());
57// for(int k=0;k<mSize;k++)
58// {
59// if(fabs(cdp.msVector(k)-1)<FLT_EPSILON || fabs(cdp.msVector(k)+1)<FLT_EPSILON)
60// {
61// rn(k)=pow(3.0*cdp.omega/4.0/M_PI,1.0/3.0);
62// }
63// else
64// {
65// rn(k)=pow(fabs(cdp.msVector(k)*cdp.omega/cdp.b/M_PI),1.0/2.0);
66// }
67// }
68//
69// const std::vector<Eigen::Matrix<double,3,3>> Dlocal(cdp.getDlocal());
70//
71// std::vector<Eigen::Matrix<double,mSize,mSize>> tempR2(cdp.R2);
72//
73// if(cdp.use0DsinkStrength)
74// {
75// for(int k=0;k<mSize;++k)
76// {
77// // Add 1D interaction rate
78// for(const auto& pair: cdp.reactionMap)
79// {
80// const auto key=pair.first;
81// if(k==key.first || k==key.second)
82// {// (key.first, key.second) consume k_specie
83// if( cdp.msVector(key.second)>1.0 )
84// { // 3D immobile + 1D mobile
85// tempR2[k](key.first ,key.second) -= pair.second*M_PI*M_PI*pow(rn(key.second),4.0)*(Dlocal[key.second](0,0))/cdp.omega/cdp.omega*cin(key.first);
86// tempR2[k](key.second,key.first) -= pair.second*M_PI*M_PI*pow(rn(key.second),4.0)*(Dlocal[key.second](0,0))/cdp.omega/cdp.omega*cin(key.first);
87// }
88// }
89// else if( fabs(cdp.msVector(key.first)+cdp.msVector(key.second)-cdp.msVector(k))<FLT_EPSILON )
90// {// (key.first, key.second) generate k_specie
91// if( cdp.msVector(key.second)>1.0 )
92// { // 3D mobile + 1D immobile
93// const double same= (key.first==key.second) ? 0.5 : 1.0;
94// tempR2[k](key.first ,key.second) += same*pair.second*M_PI*M_PI*pow(rn(key.second),4.0)*(Dlocal[key.second](0,0))/cdp.omega/cdp.omega*cin(key.first);
95// tempR2[k](key.second,key.first) += same*pair.second*M_PI*M_PI*pow(rn(key.second),4.0)*(Dlocal[key.second](0,0))/cdp.omega/cdp.omega*cin(key.first);
96// }
97// }
98// }
99// }
100// }
101//
102// return tempR2;
103// }
104
105 /**********************************************************************/
106 template<typename ElementType, typename BaryType>
107 const Eigen::Matrix<double,rows,cols> operator() (const ElementType& ele, const BaryType& bary) const
108 {
112 // dot(c_a) = R1_ab*cb -> t_a*dot(c_a) = t_a*R1_ab* d(cb)
113
114 // Assume R2_abg=R2_agb
115 // dot(c_a) = 1/2*R2_abg*cb*cg -> t_a*dot(c_a) = 1/2*t_a*(R2_abg*d(cb)*cg+R2_abg*cb*d(cg)) = t_a*(R2_abg*cg)*d(cb)
116 const Eigen::Matrix<double,rows,1> cvalue(inFactors.asDiagonal()*(*ce)(ele,bary));
117// std::vector<Eigen::Matrix<double,rows,cols>> R2V(buildR2(cvalue));
118
119 Eigen::Matrix<double,rows,cols> temp(Eigen::Matrix<double,rows,cols>::Zero());
120 for(size_t r=0;r<rows;++r)
121 {
122// temp.row(r)=R2V[r]*cvalue;
123 temp.row(r)=cdp.R2[r]*cvalue;
124 }
125
126 return outFactors.asDiagonal()*(temp)*inFactors.asDiagonal();
127 }
128
129};
130
131}
132#endif
133
auto eval(const std::shared_ptr< T > &t)
const Eigen::Matrix< double, rows, 1 > outFactors
const Eigen::Matrix< double, rows, 1 > inFactors
EvalExpression< TrialFunctionType > EvalFunctionType
const std::shared_ptr< EvalFunctionType > ce
const ClusterDynamicsParameters< dim > & cdp
const Eigen::Matrix< double, rows, cols > operator()(const ElementType &ele, const BaryType &bary) const
const std::shared_ptr< TrialFunctionType > c
SecondOrderReaction(const std::shared_ptr< TrialFunctionType > &c_in, const ClusterDynamicsParameters< dim > &cdp_in)
Eigen::MatrixXd matrix(const Form &form)
vertex temp