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 1011 : SwitchingFunctionMultiPhaseMaterialTempl<is_ad>::validParams() 19 : { 20 1011 : InputParameters params = Material::validParams(); 21 2022 : params.addRequiredParam<MaterialPropertyName>( 22 : "h_name", "Name of the switching function material property for the given phase"); 23 2022 : params.addRequiredCoupledVar("phase_etas", "Vector of order parameters for the given phase"); 24 2022 : params.addRequiredCoupledVar("all_etas", "Vector of all order parameters for all phases"); 25 1011 : params.addClassDescription("Calculates the switching function for a given phase for a " 26 : "multi-phase, multi-order parameter model"); 27 1011 : return params; 28 0 : } 29 : 30 : template <bool is_ad> 31 777 : SwitchingFunctionMultiPhaseMaterialTempl<is_ad>::SwitchingFunctionMultiPhaseMaterialTempl( 32 : const InputParameters & parameters) 33 : : DerivativeMaterialInterface<Material>(parameters), 34 1554 : _h_name(this->getParam<MaterialPropertyName>("h_name")), 35 777 : _num_eta_p(coupledComponents("phase_etas")), 36 777 : _eta_p(coupledGenericValues<is_ad>("phase_etas")), 37 777 : _eta_p_names(coupledNames("phase_etas")), 38 777 : _num_eta(coupledComponents("all_etas")), 39 777 : _eta(coupledGenericValues<is_ad>("all_etas")), 40 777 : _eta_names(coupledNames("all_etas")), 41 777 : _is_p(_num_eta), 42 777 : _prop_h(declareGenericProperty<Real, is_ad>(_h_name)), 43 777 : _prop_dh(_num_eta), 44 1554 : _prop_d2h(_num_eta) 45 : { 46 : // Declare h derivative properties 47 3108 : for (unsigned int i = 0; i < _num_eta; ++i) 48 2331 : _prop_d2h[i].resize(_num_eta, NULL); 49 : 50 3108 : for (unsigned int i = 0; i < _num_eta; ++i) 51 : { 52 2331 : _prop_dh[i] = &this->template declarePropertyDerivative<Real, is_ad>(_h_name, _eta_names[i]); 53 7281 : for (unsigned int j = i; j < _num_eta; ++j) 54 : { 55 4950 : _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 3108 : for (unsigned int i = 0; i < _num_eta; ++i) 62 : { 63 : _is_p[i] = false; 64 5751 : for (unsigned int j = 0; j < _num_eta_p; ++j) 65 : { 66 3420 : if (_eta_names[i] == _eta_p_names[j]) 67 : _is_p[i] = true; 68 : } 69 : } 70 777 : } 71 : 72 : template <bool is_ad> 73 : void 74 2598080 : SwitchingFunctionMultiPhaseMaterialTempl<is_ad>::computeQpProperties() 75 : { 76 335480 : GenericReal<is_ad> sum_p = 0.0; 77 335480 : GenericReal<is_ad> sum_all = 0.0; 78 : 79 6339900 : for (unsigned int i = 0; i < _num_eta_p; ++i) 80 4245040 : sum_p += (*_eta_p[i])[_qp] * (*_eta_p[i])[_qp]; 81 : 82 10081720 : for (unsigned int i = 0; i < _num_eta; ++i) 83 8490080 : sum_all += (*_eta[i])[_qp] * (*_eta[i])[_qp]; 84 : 85 2262600 : GenericReal<is_ad> sum_notp = sum_all - sum_p; 86 : 87 2598080 : _prop_h[_qp] = sum_p / sum_all; 88 : 89 10081720 : for (unsigned int i = 0; i < _num_eta; ++i) 90 : { 91 : // First derivatives 92 7483640 : if (_is_p[i]) 93 4245040 : (*_prop_dh[i])[_qp] = 2.0 * (*_eta[i])[_qp] * sum_notp / (sum_all * sum_all); 94 : else 95 4245040 : (*_prop_dh[i])[_qp] = -2.0 * (*_eta[i])[_qp] * sum_p / (sum_all * sum_all); 96 : 97 : // Second derivatives 98 31886160 : for (unsigned int j = 0; j < _num_eta; ++j) 99 : { 100 24402520 : if (i == j) 101 : { 102 7483640 : if (_is_p[i]) 103 4245040 : (*_prop_d2h[i][j])[_qp] = 104 4748260 : (2.0 * sum_all * sum_notp - 8.0 * (*_eta[i])[_qp] * (*_eta[i])[_qp] * sum_notp) / 105 3238600 : (sum_all * sum_all * sum_all); 106 : else 107 4245040 : (*_prop_d2h[i][j])[_qp] = 108 4748260 : (-2.0 * sum_p * sum_all + 8.0 * (*_eta[i])[_qp] * (*_eta[i])[_qp] * sum_p) / 109 3238600 : (sum_all * sum_all * sum_all); 110 : } 111 16918880 : else if (_is_p[i] && _is_p[j]) 112 3909360 : (*_prop_d2h[i][j])[_qp] = 113 3909360 : -8.0 * (*_eta[i])[_qp] * (*_eta[j])[_qp] * sum_notp / (sum_all * sum_all * sum_all); 114 13345000 : else if (!_is_p[i] && !_is_p[j]) 115 3909360 : (*_prop_d2h[i][j])[_qp] = 116 3909360 : 8.0 * (*_eta[i])[_qp] * (*_eta[j])[_qp] * sum_p / (sum_all * sum_all * sum_all); 117 : else 118 12454960 : (*_prop_d2h[i][j])[_qp] = (4.0 * sum_all - 8.0 * sum_notp) * (*_eta[i])[_qp] * 119 9771120 : (*_eta[j])[_qp] / (sum_all * sum_all * sum_all); 120 : } 121 : } 122 2598080 : } 123 : 124 : // explicit instantiation 125 : template class SwitchingFunctionMultiPhaseMaterialTempl<true>; 126 : template class SwitchingFunctionMultiPhaseMaterialTempl<false>;