Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #include "ACGrGrMulti.h" 11 : 12 : registerMooseObject("PhaseFieldApp", ACGrGrMulti); 13 : registerMooseObject("PhaseFieldApp", ADACGrGrMulti); 14 : 15 : template <bool is_ad> 16 : InputParameters 17 704 : ACGrGrMultiTempl<is_ad>::validParams() 18 : { 19 704 : InputParameters params = ACGrGrMultiBase<is_ad>::validParams(); 20 704 : params.addClassDescription("Multi-phase poly-crystalline Allen-Cahn Kernel"); 21 1408 : params.addRequiredParam<std::vector<MaterialPropertyName>>( 22 : "gamma_names", 23 : "List of gamma material property names for each other order parameter. Place " 24 : "in same order as order parameters (v)!"); 25 704 : return params; 26 0 : } 27 : 28 : template <bool is_ad> 29 370 : ACGrGrMultiTempl<is_ad>::ACGrGrMultiTempl(const InputParameters & parameters) 30 : : ACGrGrMultiBase<is_ad>(parameters), 31 740 : _gamma_names(this->template getParam<std::vector<MaterialPropertyName>>("gamma_names")), 32 370 : _num_j(_gamma_names.size()), 33 740 : _prop_gammas(_num_j) 34 : { 35 : // check passed in parameter vectors 36 740 : if (_num_j != this->coupledComponents("v")) 37 0 : this->paramError( 38 : "gamma_names", 39 : "Need to pass in as many gamma_names as coupled variables in v in ACGrGrMulti"); 40 : 41 980 : for (unsigned int n = 0; n < _num_j; ++n) 42 610 : _prop_gammas[n] = &this->template getGenericMaterialProperty<Real, is_ad>(_gamma_names[n]); 43 370 : } 44 : 45 258 : ACGrGrMulti::ACGrGrMulti(const InputParameters & parameters) 46 : : ACGrGrMultiTempl<false>(parameters), 47 516 : _uname(this->template getParam<NonlinearVariableName>("variable")), 48 258 : _dmudu(this->template getMaterialPropertyDerivative<Real>("mu", _uname)), 49 516 : _vname(this->template getParam<std::vector<VariableName>>("v")), 50 516 : _dmudEtaj(_num_j) 51 : { 52 678 : for (unsigned int n = 0; n < _num_j; ++n) 53 420 : _dmudEtaj[n] = &this->template getMaterialPropertyDerivative<Real>("mu", _vname[n]); 54 258 : } 55 : 56 : Real 57 44976784 : ACGrGrMulti::computeDFDOP(PFFunctionType type) 58 : { 59 : // Sum all other order parameters 60 : Real SumGammaEtaj = 0.0; 61 130056752 : for (const auto i : make_range(_op_num)) 62 85079968 : SumGammaEtaj += (*_prop_gammas[i])[_qp] * (*_vals[i])[_qp] * (*_vals[i])[_qp]; 63 : 64 : // Calculate either the residual or Jacobian of the grain growth free energy 65 44976784 : switch (type) 66 : { 67 32581136 : case Residual: 68 : { 69 32581136 : return _mu[_qp] * computedF0du(); 70 : } 71 : 72 12395648 : case Jacobian: 73 : { 74 12395648 : Real d2f0du2 = 3.0 * _u[_qp] * _u[_qp] - 1.0 + 2.0 * SumGammaEtaj; 75 12395648 : return _phi[_j][_qp] * (_mu[_qp] * d2f0du2 + _dmudu[_qp] * computedF0du()); 76 : } 77 : 78 0 : default: 79 0 : mooseError("Invalid type passed in"); 80 : } 81 : } 82 : 83 : ADReal 84 35082420 : ADACGrGrMulti::computeDFDOP() 85 : { 86 : // Sum all other order parameters 87 35082420 : ADReal SumGammaEtaj = 0.0; 88 70668060 : for (const auto i : make_range(_op_num)) 89 71171280 : SumGammaEtaj += (*_prop_gammas[i])[_qp] * (*_vals[i])[_qp] * (*_vals[i])[_qp]; 90 : 91 70164840 : return _mu[_qp] * computedF0du(); 92 : } 93 : 94 : Real 95 90029184 : ACGrGrMulti::computeQpOffDiagJacobian(unsigned int jvar) 96 : { 97 131515776 : for (unsigned int i = 0; i < _op_num; ++i) 98 131515776 : if (jvar == _vals_var[i]) 99 : { 100 : // Derivative of SumGammaEtaj 101 90029184 : const Real dSumGammaEtaj = 2.0 * (*_prop_gammas[i])[_qp] * (*_vals[i])[_qp]; 102 90029184 : const Real dDFDOP = _mu[_qp] * 2.0 * _u[_qp] * dSumGammaEtaj; 103 : 104 90029184 : return _L[_qp] * _test[_i][_qp] * _phi[_j][_qp] * 105 90029184 : (dDFDOP + (*_dmudEtaj[i])[_qp] * computedF0du()); 106 : } 107 : 108 : return 0.0; 109 : } 110 : 111 : template <bool is_ad> 112 : GenericReal<is_ad> 113 170088388 : ACGrGrMultiTempl<is_ad>::computedF0du() 114 : { 115 35082420 : GenericReal<is_ad> SumGammaEtaj = 0.0; 116 463756364 : for (const auto i : make_range(_op_num)) 117 329253616 : SumGammaEtaj += (*_prop_gammas[i])[_qp] * (*_vals[i])[_qp] * (*_vals[i])[_qp]; 118 : 119 240253228 : return _u[_qp] * _u[_qp] * _u[_qp] - _u[_qp] + 2.0 * _u[_qp] * SumGammaEtaj; 120 : } 121 : 122 : template class ACGrGrMultiTempl<false>; 123 : template class ACGrGrMultiTempl<true>;