11 #include "petscblaslapack.h"
12 #include "libmesh/utility.h"
25 params.addClassDescription(
26 "Crystal Plasticity base class: FCC system with power law flow rule implemented");
27 params.addRequiredParam<
int>(
"nss",
"Number of slip systems");
28 params.addParam<std::vector<Real>>(
"gprops",
"Initial values of slip system resistances");
29 params.addParam<std::vector<Real>>(
"hprops",
"Hardening properties");
30 params.addParam<std::vector<Real>>(
"flowprops",
"Parameters used in slip rate equations");
31 params.addRequiredParam<FileName>(
"slip_sys_file_name",
32 "Name of the file containing the slip system");
33 params.addParam<FileName>(
34 "slip_sys_res_prop_file_name",
36 "Name of the file containing the initial values of slip system resistances");
37 params.addParam<FileName>(
38 "slip_sys_flow_prop_file_name",
40 "Name of the file containing the values of slip rate equation parameters");
41 params.addParam<FileName>(
42 "slip_sys_hard_prop_file_name",
44 "Name of the file containing the values of hardness evolution parameters");
45 params.addParam<Real>(
"rtol", 1e-6,
"Constitutive stress residue relative tolerance");
46 params.addParam<Real>(
"abs_tol", 1e-6,
"Constitutive stress residue absolute tolerance");
47 params.addParam<Real>(
"gtol", 1e2,
"Constitutive slip system resistance residual tolerance");
48 params.addParam<Real>(
"slip_incr_tol", 2e-2,
"Maximum allowable slip in an increment");
49 params.addParam<
unsigned int>(
"maxiter", 100,
"Maximum number of iterations for stress update");
50 params.addParam<
unsigned int>(
51 "maxitergss", 100,
"Maximum number of iterations for slip system resistance update");
52 params.addParam<
unsigned int>(
53 "num_slip_sys_flowrate_props",
55 "Number of flow rate properties for a slip system");
56 params.addParam<UserObjectName>(
"read_prop_user_object",
57 "The ElementReadPropertyFile "
58 "GeneralUserObject to read element "
59 "specific property values from file");
60 MooseEnum tan_mod_options(
"exact none",
"none");
61 params.addParam<MooseEnum>(
"tan_mod_type",
63 "Type of tangent moduli for preconditioner: default elastic");
64 MooseEnum intvar_read_options(
"slip_sys_file slip_sys_res_file none",
"none");
65 params.addParam<MooseEnum>(
68 "Read from options for initial value of internal variables: Default from .i file");
69 params.addParam<
unsigned int>(
"num_slip_sys_props",
71 "Number of slip system specific properties provided in the file "
72 "containing slip system normals and directions");
73 params.addParam<
bool>(
74 "gen_random_stress_flag",
76 "Flag to generate random stress to perform time cutback on constitutive failure");
77 params.addParam<
bool>(
"input_random_scaling_var",
79 "Flag to input scaling variable: _Cijkl(0,0,0,0) when false");
80 params.addParam<Real>(
"random_scaling_var",
82 "Random scaling variable: Large value can cause non-positive definiteness");
83 params.addParam<
unsigned int>(
86 "Random integer used to generate random stress when constitutive failure occurs");
87 params.addParam<
unsigned int>(
88 "maximum_substep_iteration", 1,
"Maximum number of substep iteration");
89 params.addParam<
bool>(
"use_line_search",
false,
"Use line search in constitutive update");
90 params.addParam<Real>(
"min_line_search_step_size", 0.01,
"Minimum line search step size");
91 params.addParam<Real>(
"line_search_tol", 0.5,
"Line search bisection method tolerance");
92 params.addParam<
unsigned int>(
93 "line_search_maxiter", 20,
"Line search bisection method maximum number of iteration");
94 MooseEnum line_search_method(
"CUT_HALF BISECTION",
"CUT_HALF");
95 params.addParam<MooseEnum>(
96 "line_search_method", line_search_method,
"The method used in line search");
103 _nss(getParam<int>(
"nss")),
104 _gprops(getParam<std::vector<Real>>(
"gprops")),
105 _hprops(getParam<std::vector<Real>>(
"hprops")),
106 _flowprops(getParam<std::vector<Real>>(
"flowprops")),
107 _slip_sys_file_name(getParam<FileName>(
"slip_sys_file_name")),
108 _slip_sys_res_prop_file_name(getParam<FileName>(
"slip_sys_res_prop_file_name")),
109 _slip_sys_flow_prop_file_name(getParam<FileName>(
"slip_sys_flow_prop_file_name")),
110 _slip_sys_hard_prop_file_name(getParam<FileName>(
"slip_sys_hard_prop_file_name")),
111 _rtol(getParam<Real>(
"rtol")),
112 _abs_tol(getParam<Real>(
"abs_tol")),
113 _gtol(getParam<Real>(
"gtol")),
114 _slip_incr_tol(getParam<Real>(
"slip_incr_tol")),
115 _maxiter(getParam<unsigned int>(
"maxiter")),
116 _maxiterg(getParam<unsigned int>(
"maxitergss")),
117 _num_slip_sys_flowrate_props(getParam<unsigned int>(
"num_slip_sys_flowrate_props")),
118 _tan_mod_type(getParam<MooseEnum>(
"tan_mod_type")),
119 _intvar_read_type(getParam<MooseEnum>(
"intvar_read_type")),
120 _num_slip_sys_props(getParam<unsigned int>(
"num_slip_sys_props")),
121 _gen_rndm_stress_flag(getParam<bool>(
"gen_random_stress_flag")),
122 _input_rndm_scale_var(getParam<bool>(
"input_random_scaling_var")),
123 _rndm_scale_var(getParam<Real>(
"random_scaling_var")),
124 _rndm_seed(getParam<unsigned int>(
"random_seed")),
125 _max_substep_iter(getParam<unsigned int>(
"maximum_substep_iteration")),
126 _use_line_search(getParam<bool>(
"use_line_search")),
127 _min_lsrch_step(getParam<Real>(
"min_line_search_step_size")),
128 _lsrch_tol(getParam<Real>(
"line_search_tol")),
129 _lsrch_max_iter(getParam<unsigned int>(
"line_search_maxiter")),
130 _lsrch_method(getParam<MooseEnum>(
"line_search_method")),
140 _gss(declareProperty<std::vector<Real>>(
"gss")),
141 _gss_old(getMaterialPropertyOld<std::vector<Real>>(
143 _acc_slip(declareProperty<Real>(
"acc_slip")),
145 getMaterialPropertyOld<Real>(
"acc_slip")),
148 _deformation_gradient(getMaterialProperty<
RankTwoTensor>(
"deformation_gradient")),
149 _deformation_gradient_old(getMaterialPropertyOld<
RankTwoTensor>(
"deformation_gradient")),
150 _elasticity_tensor_name(_base_name +
"elasticity_tensor"),
151 _elasticity_tensor(getMaterialPropertyByName<
RankFourTensor>(_elasticity_tensor_name)),
153 _mo(_nss * LIBMESH_DIM),
154 _no(_nss * LIBMESH_DIM),
161 _dgss_dsliprate(_nss, _nss)
181 mooseError(
"Crystal Plasticity Error: Specify number of internal variable's initial values to "
182 "be read from slip system file");
194 _fp[_qp].setToIdentity();
237 for (
unsigned int i = 0; i <
_nss; ++i)
252 for (
unsigned int i = 0; i <
_nss; ++i)
253 if (!(file >>
_gss[_qp][i]))
254 mooseError(
"Error FiniteStrainCrystalPlasticity: Premature end of slip_sys_res_prop file");
264 mooseError(
"FiniteStrainCrystalPLasticity: Error in reading slip system resistance properties: "
265 "Specify input in .i file or in slip_sys_res_prop_file or in slip_sys_file");
269 unsigned int num_data_grp = 3;
272 for (
unsigned int i = 0; i <
_gprops.size() / num_data_grp; ++i)
277 vs =
_gprops[i * num_data_grp];
278 ve =
_gprops[i * num_data_grp + 1];
280 if (vs <= 0 || ve <= 0)
281 mooseError(
"FiniteStrainCrystalPLasticity: Indices in gss property read must be positive "
287 if (vs != floor(vs) || ve != floor(ve))
288 mooseError(
"FiniteStrainCrystalPLasticity: Error in reading slip system resistances: Values "
289 "specifying start and end number of slip system groups should be integer");
291 is = static_cast<unsigned int>(vs);
292 ie = static_cast<unsigned int>(ve);
295 mooseError(
"FiniteStrainCrystalPLasticity: Start index is = ",
297 " should be greater than end index ie = ",
299 " in slip system resistance property read");
301 for (
unsigned int j = is; j <= ie; ++j)
305 for (
unsigned int i = 0; i <
_nss; ++i)
306 if (
_gss[_qp][i] <= 0.0)
307 mooseError(
"FiniteStrainCrystalPLasticity: Value of resistance for slip system ",
324 std::vector<Real> vec;
327 for (
unsigned int i = 0; i <
_nss; ++i)
330 if (!(file >> vec[j]))
332 "Error FiniteStrainCrystalPlasticity: Premature end of slip_sys_flow_rate_param file");
346 mooseError(
"FiniteStrainCrystalPLasticity: Error in reading flow rate properties: Specify "
347 "input in .i file or a slip_sys_flow_prop_file_name");
356 for (
unsigned int i = 0; i <
_flowprops.size() / num_data_grp; ++i)
364 if (vs <= 0 || ve <= 0)
365 mooseError(
"FiniteStrainCrystalPLasticity: Indices in flow rate parameter read must be "
366 "positive integers: is = ",
371 if (vs != floor(vs) || ve != floor(ve))
372 mooseError(
"FiniteStrainCrystalPLasticity: Error in reading flow props: Values specifying "
373 "start and end number of slip system groups should be integer");
375 is = static_cast<unsigned int>(vs);
376 ie = static_cast<unsigned int>(ve);
379 mooseError(
"FiniteStrainCrystalPLasticity: Start index is = ",
381 " should be greater than end index ie = ",
383 " in flow rate parameter read");
385 for (
unsigned int j = is; j <= ie; ++j)
392 for (
unsigned int i = 0; i <
_nss; ++i)
394 if (!(
_a0(i) > 0.0 &&
_xm(i) > 0.0))
397 "FiniteStrainCrystalPlasticity: Non-positive flow rate parameters ",
_a0(i),
",",
_xm(i));
414 mooseError(
"FiniteStrainCrystalPLasticity: Error in reading hardness properties: Specify input "
415 "in .i file or a slip_sys_hard_prop_file_name");
427 Real vec[LIBMESH_DIM];
428 std::ifstream fileslipsys;
434 for (
unsigned int i = 0; i <
_nss; ++i)
437 for (
unsigned int j = 0; j < LIBMESH_DIM; ++j)
438 if (!(fileslipsys >> vec[j]))
439 mooseError(
"Crystal Plasticity Error: Premature end of file reading slip system file \n");
443 mag = Utility::pow<2>(vec[0]) + Utility::pow<2>(vec[1]) + Utility::pow<2>(vec[2]);
444 mag = std::sqrt(mag);
446 for (
unsigned j = 0; j < LIBMESH_DIM; ++j)
447 _no(i * LIBMESH_DIM + j) = vec[j] / mag;
450 for (
unsigned int j = 0; j < LIBMESH_DIM; ++j)
451 if (!(fileslipsys >> vec[j]))
452 mooseError(
"Crystal Plasticity Error: Premature end of file reading slip system file \n");
455 mag = Utility::pow<2>(vec[0]) + Utility::pow<2>(vec[1]) + Utility::pow<2>(vec[2]);
456 mag = std::sqrt(mag);
458 for (
unsigned int j = 0; j < LIBMESH_DIM; ++j)
459 _mo(i * LIBMESH_DIM + j) = vec[j] / mag;
462 for (
unsigned int j = 0; j < LIBMESH_DIM; ++j)
463 mag +=
_mo(i * LIBMESH_DIM + j) *
_no(i * LIBMESH_DIM + j);
465 if (std::abs(mag) > 1e-8)
467 "Crystal Plasicity Error: Slip direction and normal not orthonormal, System number = ",
474 mooseError(
"Crystal Plasticity Error: Premature end of file reading slip system file - "
475 "check in slip system file read input options/values\n");
494 unsigned int substep_iter = 1;
495 unsigned int num_substep = 1;
496 Real dt_original = _dt;
512 _dt = dt_original / num_substep;
514 for (
unsigned int istep = 0; istep < num_substep; ++istep)
521 if (istep == num_substep - 1)
542 mooseWarning(
"FiniteStrainCrystalPlasticity: Failure with substepping");
600 mooseError(
"FiniteStrainCrystalPlasticity: Constitutive failure");
644 std::vector<Real> gss_prev(
_nss);
662 for (
unsigned i = 0; i <
_nss; ++i)
664 gdiff = std::abs(gss_prev[i] -
_gss_tmp[i]);
675 mooseWarning(
"FiniteStrainCrystalPLasticity: Hardness Integration error gmax", gmax,
"\n");
732 unsigned int iter = 0;
735 Real rnorm, rnorm0, rnorm_prev;
742 "FiniteStrainCrystalPLasticity: Slip increment exceeds tolerance - Element number ",
750 rnorm = resid.L2norm();
756 dpk2 = -jac.invSymm() * resid;
765 "FiniteStrainCrystalPLasticity: Slip increment exceeds tolerance - Element number ",
774 rnorm = resid.L2norm();
779 mooseWarning(
"FiniteStrainCrystalPLasticity: Failed with line search");
786 rnorm = resid.L2norm();
794 mooseWarning(
"FiniteStrainCrystalPLasticity: Stress Integration error rmax = ", rnorm);
837 DenseVector<Real> hb(
_nss);
843 for (
unsigned int i = 0; i <
_nss; ++i)
849 for (
unsigned int i = 0; i <
_nss; ++i)
854 for (
unsigned int i = 0; i <
_nss; ++i)
861 for (
unsigned int j = 0; j <
_nss; ++j)
863 unsigned int iplane, jplane;
867 if (iplane == jplane)
891 RankTwoTensor iden(RankTwoTensor::initIdentity), ce, ee, ce_pk2, eqv_slip_incr, pk2_new;
895 ce =
_fe.transpose() *
_fe;
897 ce_pk2 = ce_pk2 /
_fe.det();
900 for (
unsigned int i = 0; i <
_nss; ++i)
901 _tau(i) = ce_pk2.doubleContraction(
_s0[i]);
908 eqv_slip_incr.zero();
909 for (
unsigned int i = 0; i <
_nss; ++i)
912 eqv_slip_incr = iden - eqv_slip_incr;
916 ce =
_fe.transpose() *
_fe;
930 std::vector<RankTwoTensor> dtaudpk2(
_nss), dfpinvdslip(
_nss);
932 for (
unsigned int i = 0; i <
_nss; ++i)
934 dtaudpk2[i] =
_s0[i];
938 for (
unsigned int i = 0; i < LIBMESH_DIM; ++i)
939 for (
unsigned int j = 0; j < LIBMESH_DIM; ++j)
940 for (
unsigned int k = 0; k < LIBMESH_DIM; ++k)
943 for (
unsigned int i = 0; i < LIBMESH_DIM; ++i)
944 for (
unsigned int j = 0; j < LIBMESH_DIM; ++j)
945 for (
unsigned int k = 0; k < LIBMESH_DIM; ++k)
947 deedfe(i, j, k, i) = deedfe(i, j, k, i) +
_fe(k, j) * 0.5;
948 deedfe(i, j, k, j) = deedfe(i, j, k, j) +
_fe(k, i) * 0.5;
951 for (
unsigned int i = 0; i <
_nss; ++i)
952 dfpinvdpk2 += (dfpinvdslip[i] *
_dslipdtau(i)).outerProduct(dtaudpk2[i]);
955 RankFourTensor::IdentityFour() - (
_elasticity_tensor[_qp] * deedfe * dfedfpinv * dfpinvdpk2);
962 for (
unsigned int i = 0; i <
_nss; ++i)
965 std::copysign(1.0,
_tau(i)) * _dt;
970 mooseWarning(
"Maximum allowable slip increment exceeded ", std::abs(
_slip_incr(i)));
976 for (
unsigned int i = 0; i <
_nss; ++i)
995 PetscScalar cmat[LIBMESH_DIM][LIBMESH_DIM], work[10];
996 PetscReal w[LIBMESH_DIM];
997 PetscBLASInt nd = LIBMESH_DIM, lwork = 10, info;
999 c = a.transpose() * a;
1001 for (
unsigned int i = 0; i < LIBMESH_DIM; ++i)
1002 for (
unsigned int j = 0; j < LIBMESH_DIM; ++j)
1003 cmat[i][j] = c(i, j);
1005 LAPACKsyev_(
"V",
"U", &nd, &cmat[0][0], &nd, w, work, &lwork, &info);
1008 mooseError(
"FiniteStrainCrystalPLasticity: DSYEV function call in getMatRot function failed");
1012 for (
unsigned int i = 0; i < LIBMESH_DIM; ++i)
1013 diag(i, i) = std::sqrt(w[i]);
1015 for (
unsigned int i = 0; i < LIBMESH_DIM; ++i)
1016 for (
unsigned int j = 0; j < LIBMESH_DIM; ++j)
1017 evec(i, j) = cmat[i][j];
1019 rot = a * ((evec.transpose() * diag * evec).inverse());
1050 DenseVector<Real> mo(LIBMESH_DIM *
_nss), no(LIBMESH_DIM *
_nss);
1053 for (
unsigned int i = 0; i <
_nss; ++i)
1055 for (
unsigned int j = 0; j < LIBMESH_DIM; ++j)
1057 mo(i * LIBMESH_DIM + j) = 0.0;
1058 for (
unsigned int k = 0; k < LIBMESH_DIM; ++k)
1059 mo(i * LIBMESH_DIM + j) =
1060 mo(i * LIBMESH_DIM + j) +
_crysrot[_qp](j, k) *
_mo(i * LIBMESH_DIM + k);
1063 for (
unsigned int j = 0; j < LIBMESH_DIM; ++j)
1065 no(i * LIBMESH_DIM + j) = 0.0;
1066 for (
unsigned int k = 0; k < LIBMESH_DIM; ++k)
1067 no(i * LIBMESH_DIM + j) =
1068 no(i * LIBMESH_DIM + j) +
_crysrot[_qp](j, k) *
_no(i * LIBMESH_DIM + k);
1073 for (
unsigned int i = 0; i <
_nss; ++i)
1074 for (
unsigned int j = 0; j < LIBMESH_DIM; ++j)
1075 for (
unsigned int k = 0; k < LIBMESH_DIM; ++k)
1076 _s0[i](j, k) = mo(i * LIBMESH_DIM + j) * no(i * LIBMESH_DIM + k);
1088 for (
unsigned int i = 0; i < LIBMESH_DIM; ++i)
1089 for (
unsigned int j = 0; j < LIBMESH_DIM; ++j)
1090 for (
unsigned int k = 0; k < LIBMESH_DIM; ++k)
1092 deedfe(i, j, k, i) = deedfe(i, j, k, i) +
_fe(k, j) * 0.5;
1093 deedfe(i, j, k, j) = deedfe(i, j, k, j) +
_fe(k, i) * 0.5;
1101 for (
unsigned int i = 0; i < LIBMESH_DIM; ++i)
1102 for (
unsigned int j = 0; j < LIBMESH_DIM; ++j)
1103 for (
unsigned int l = 0; l < LIBMESH_DIM; ++l)
1105 tan_mod(i, j, i, l) = tan_mod(i, j, i, l) + pk2fet(l, j);
1106 tan_mod(i, j, j, l) = tan_mod(i, j, j, l) + fepk2(i, l);
1109 tan_mod += dsigdpk2dfe;
1111 Real je =
_fe.det();
1140 rnorm = resid.L2norm();
1150 unsigned int count = 0;
1155 Real rnorm = 1000.0;
1159 Real s_b = resid.doubleContraction(dpk2);
1160 Real rnorm1 = resid.L2norm();
1163 Real s_a = resid.doubleContraction(dpk2);
1164 Real rnorm0 = resid.L2norm();
1167 if ((rnorm1 / rnorm0) <
_lsrch_tol || s_a * s_b > 0)
1176 step = 0.5 * (step_b + step_a);
1179 s_m = resid.doubleContraction(dpk2);
1180 rnorm = resid.L2norm();
1182 if (s_m * s_a < 0.0)
1187 if (s_m * s_b < 0.0)
1202 mooseError(
"Line search meothod is not provided.");