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 492 : ACGrGrMultiTempl<is_ad>::validParams() 18 : { 19 492 : InputParameters params = ACGrGrMultiBase<is_ad>::validParams(); 20 492 : params.addClassDescription("Multi-phase poly-crystalline Allen-Cahn Kernel"); 21 984 : 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 492 : return params; 26 0 : } 27 : 28 : template <bool is_ad> 29 264 : ACGrGrMultiTempl<is_ad>::ACGrGrMultiTempl(const InputParameters & parameters) 30 : : ACGrGrMultiBase<is_ad>(parameters), 31 528 : _gamma_names(this->template getParam<std::vector<MaterialPropertyName>>("gamma_names")), 32 264 : _num_j(_gamma_names.size()), 33 528 : _prop_gammas(_num_j) 34 : { 35 : // check passed in parameter vectors 36 528 : 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 702 : for (unsigned int n = 0; n < _num_j; ++n) 42 438 : _prop_gammas[n] = &this->template getGenericMaterialProperty<Real, is_ad>(_gamma_names[n]); 43 264 : } 44 : 45 178 : ACGrGrMulti::ACGrGrMulti(const InputParameters & parameters) 46 : : ACGrGrMultiTempl<false>(parameters), 47 356 : _uname(this->template getParam<NonlinearVariableName>("variable")), 48 178 : _dmudu(this->template getMaterialPropertyDerivative<Real>("mu", _uname)), 49 356 : _vname(this->template getParam<std::vector<VariableName>>("v")), 50 356 : _dmudEtaj(_num_j) 51 : { 52 470 : for (unsigned int n = 0; n < _num_j; ++n) 53 292 : _dmudEtaj[n] = &this->template getMaterialPropertyDerivative<Real>("mu", _vname[n]); 54 178 : } 55 : 56 : Real 57 36976040 : ACGrGrMulti::computeDFDOP(PFFunctionType type) 58 : { 59 : // Sum all other order parameters 60 : Real SumGammaEtaj = 0.0; 61 106843120 : for (const auto i : make_range(_op_num)) 62 69867080 : 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 36976040 : switch (type) 66 : { 67 26593256 : case Residual: 68 : { 69 26593256 : return _mu[_qp] * computedF0du(); 70 : } 71 : 72 10382784 : case Jacobian: 73 : { 74 10382784 : Real d2f0du2 = 3.0 * _u[_qp] * _u[_qp] - 1.0 + 2.0 * SumGammaEtaj; 75 10382784 : 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 34928820 : ADACGrGrMulti::computeDFDOP() 85 : { 86 : // Sum all other order parameters 87 34928820 : ADReal SumGammaEtaj = 0.0; 88 70293660 : for (const auto i : make_range(_op_num)) 89 70729680 : SumGammaEtaj += (*_prop_gammas[i])[_qp] * (*_vals[i])[_qp] * (*_vals[i])[_qp]; 90 : 91 69857640 : return _mu[_qp] * computedF0du(); 92 : } 93 : 94 : Real 95 75409472 : ACGrGrMulti::computeQpOffDiagJacobian(unsigned int jvar) 96 : { 97 110124608 : for (unsigned int i = 0; i < _op_num; ++i) 98 110124608 : if (jvar == _vals_var[i]) 99 : { 100 : // Derivative of SumGammaEtaj 101 75409472 : const Real dSumGammaEtaj = 2.0 * (*_prop_gammas[i])[_qp] * (*_vals[i])[_qp]; 102 75409472 : const Real dDFDOP = _mu[_qp] * 2.0 * _u[_qp] * dSumGammaEtaj; 103 : 104 75409472 : return _L[_qp] * _test[_i][_qp] * _phi[_j][_qp] * 105 75409472 : (dDFDOP + (*_dmudEtaj[i])[_qp] * computedF0du()); 106 : } 107 : 108 : return 0.0; 109 : } 110 : 111 : template <bool is_ad> 112 : GenericReal<is_ad> 113 147314332 : ACGrGrMultiTempl<is_ad>::computedF0du() 114 : { 115 34928820 : GenericReal<is_ad> SumGammaEtaj = 0.0; 116 397385996 : for (const auto i : make_range(_op_num)) 117 285436504 : SumGammaEtaj += (*_prop_gammas[i])[_qp] * (*_vals[i])[_qp] * (*_vals[i])[_qp]; 118 : 119 217171972 : 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>;