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 "SwitchingFunctionMultiPhaseMaterial.h" 11 : #include "MooseException.h" 12 : 13 : registerMooseObject("PhaseFieldApp", SwitchingFunctionMultiPhaseMaterial); 14 : registerMooseObject("PhaseFieldApp", ADSwitchingFunctionMultiPhaseMaterial); 15 : 16 : template <bool is_ad> 17 : InputParameters 18 715 : SwitchingFunctionMultiPhaseMaterialTempl<is_ad>::validParams() 19 : { 20 715 : InputParameters params = Material::validParams(); 21 1430 : params.addRequiredParam<MaterialPropertyName>( 22 : "h_name", "Name of the switching function material property for the given phase"); 23 1430 : params.addRequiredCoupledVar("phase_etas", "Vector of order parameters for the given phase"); 24 1430 : params.addRequiredCoupledVar("all_etas", "Vector of all order parameters for all phases"); 25 715 : params.addClassDescription("Calculates the switching function for a given phase for a " 26 : "multi-phase, multi-order parameter model"); 27 715 : return params; 28 0 : } 29 : 30 : template <bool is_ad> 31 555 : SwitchingFunctionMultiPhaseMaterialTempl<is_ad>::SwitchingFunctionMultiPhaseMaterialTempl( 32 : const InputParameters & parameters) 33 : : DerivativeMaterialInterface<Material>(parameters), 34 1110 : _h_name(this->getParam<MaterialPropertyName>("h_name")), 35 555 : _num_eta_p(coupledComponents("phase_etas")), 36 555 : _eta_p(coupledGenericValues<is_ad>("phase_etas")), 37 555 : _eta_p_names(coupledNames("phase_etas")), 38 555 : _num_eta(coupledComponents("all_etas")), 39 555 : _eta(coupledGenericValues<is_ad>("all_etas")), 40 555 : _eta_names(coupledNames("all_etas")), 41 555 : _is_p(_num_eta), 42 555 : _prop_h(declareGenericProperty<Real, is_ad>(_h_name)), 43 555 : _prop_dh(_num_eta), 44 1110 : _prop_d2h(_num_eta) 45 : { 46 : // Declare h derivative properties 47 2220 : for (unsigned int i = 0; i < _num_eta; ++i) 48 1665 : _prop_d2h[i].resize(_num_eta, NULL); 49 : 50 2220 : for (unsigned int i = 0; i < _num_eta; ++i) 51 : { 52 1665 : _prop_dh[i] = &this->template declarePropertyDerivative<Real, is_ad>(_h_name, _eta_names[i]); 53 5187 : for (unsigned int j = i; j < _num_eta; ++j) 54 : { 55 3522 : _prop_d2h[i][j] = _prop_d2h[j][i] = &this->template declarePropertyDerivative<Real, is_ad>( 56 : _h_name, _eta_names[i], _eta_names[j]); 57 : } 58 : } 59 : 60 : // Determine which order parameters in the list of all etas belong to phase p 61 2220 : for (unsigned int i = 0; i < _num_eta; ++i) 62 : { 63 : _is_p[i] = false; 64 4071 : for (unsigned int j = 0; j < _num_eta_p; ++j) 65 : { 66 2406 : if (_eta_names[i] == _eta_p_names[j]) 67 : _is_p[i] = true; 68 : } 69 : } 70 555 : } 71 : 72 : template <bool is_ad> 73 : void 74 2147880 : SwitchingFunctionMultiPhaseMaterialTempl<is_ad>::computeQpProperties() 75 : { 76 290680 : GenericReal<is_ad> sum_p = 0.0; 77 290680 : GenericReal<is_ad> sum_all = 0.0; 78 : 79 5261500 : for (unsigned int i = 0; i < _num_eta_p; ++i) 80 3549640 : sum_p += (*_eta_p[i])[_qp] * (*_eta_p[i])[_qp]; 81 : 82 8375120 : for (unsigned int i = 0; i < _num_eta; ++i) 83 7099280 : sum_all += (*_eta[i])[_qp] * (*_eta[i])[_qp]; 84 : 85 1857200 : GenericReal<is_ad> sum_notp = sum_all - sum_p; 86 : 87 2147880 : _prop_h[_qp] = sum_p / sum_all; 88 : 89 8375120 : for (unsigned int i = 0; i < _num_eta; ++i) 90 : { 91 : // First derivatives 92 6227240 : if (_is_p[i]) 93 3549640 : (*_prop_dh[i])[_qp] = 2.0 * (*_eta[i])[_qp] * sum_notp / (sum_all * sum_all); 94 : else 95 3549640 : (*_prop_dh[i])[_qp] = -2.0 * (*_eta[i])[_qp] * sum_p / (sum_all * sum_all); 96 : 97 : // Second derivatives 98 26660160 : for (unsigned int j = 0; j < _num_eta; ++j) 99 : { 100 20432920 : if (i == j) 101 : { 102 6227240 : if (_is_p[i]) 103 3549640 : (*_prop_d2h[i][j])[_qp] = 104 3985660 : (2.0 * sum_all * sum_notp - 8.0 * (*_eta[i])[_qp] * (*_eta[i])[_qp] * sum_notp) / 105 2677600 : (sum_all * sum_all * sum_all); 106 : else 107 3549640 : (*_prop_d2h[i][j])[_qp] = 108 3985660 : (-2.0 * sum_p * sum_all + 8.0 * (*_eta[i])[_qp] * (*_eta[i])[_qp] * sum_p) / 109 2677600 : (sum_all * sum_all * sum_all); 110 : } 111 14205680 : else if (_is_p[i] && _is_p[j]) 112 3314160 : (*_prop_d2h[i][j])[_qp] = 113 3314160 : -8.0 * (*_eta[i])[_qp] * (*_eta[j])[_qp] * sum_notp / (sum_all * sum_all * sum_all); 114 11182200 : else if (!_is_p[i] && !_is_p[j]) 115 3314160 : (*_prop_d2h[i][j])[_qp] = 116 3314160 : 8.0 * (*_eta[i])[_qp] * (*_eta[j])[_qp] * sum_p / (sum_all * sum_all * sum_all); 117 : else 118 10484160 : (*_prop_d2h[i][j])[_qp] = (4.0 * sum_all - 8.0 * sum_notp) * (*_eta[i])[_qp] * 119 8158720 : (*_eta[j])[_qp] / (sum_all * sum_all * sum_all); 120 : } 121 : } 122 2147880 : } 123 : 124 : // explicit instantiation 125 : template class SwitchingFunctionMultiPhaseMaterialTempl<true>; 126 : template class SwitchingFunctionMultiPhaseMaterialTempl<false>;