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 "KKSMultiPhaseConcentration.h" 11 : 12 : registerMooseObject("PhaseFieldApp", KKSMultiPhaseConcentration); 13 : 14 : InputParameters 15 92 : KKSMultiPhaseConcentration::validParams() 16 : { 17 92 : InputParameters params = KernelValue::validParams(); 18 92 : params.addClassDescription( 19 : "KKS multi-phase model kernel to enforce $c = h_1c_1 + h_2c_2 + h_3c_3 + \\dots$" 20 : ". The non-linear variable of this kernel is $c_n$, the final phase " 21 : "concentration in the list."); 22 184 : params.addRequiredCoupledVar( 23 : "cj", "Array of phase concentrations cj. Place in same order as hj_names!"); 24 184 : params.addRequiredCoupledVar("c", "Physical concentration"); 25 184 : params.addCoupledVar("etas", "Order parameters for all phases"); 26 184 : params.addRequiredParam<std::vector<MaterialPropertyName>>( 27 : "hj_names", "Switching Function Materials that provide $h(\\eta_1, \\eta_2,\\dots)$"); 28 92 : return params; 29 0 : } 30 : 31 : // Phase interpolation func 32 48 : KKSMultiPhaseConcentration::KKSMultiPhaseConcentration(const InputParameters & parameters) 33 : : DerivativeMaterialInterface<JvarMapKernelInterface<KernelValue>>(parameters), 34 48 : _num_j(coupledComponents("cj")), 35 48 : _cj(coupledValues("cj")), 36 48 : _cj_map(getParameterJvarMap("cj")), 37 48 : _k(-1), 38 48 : _c(coupledValue("c")), 39 48 : _c_var(coupled("c")), 40 96 : _hj_names(getParam<std::vector<MaterialPropertyName>>("hj_names")), 41 48 : _prop_hj(_hj_names.size()), 42 48 : _eta_names(coupledComponents("etas")), 43 48 : _eta_map(getParameterJvarMap("etas")), 44 96 : _prop_dhjdetai(_num_j) 45 : { 46 : // Check to make sure the the number of hj's is the same as the number of cj's 47 48 : if (_num_j != _hj_names.size()) 48 0 : paramError("hj_names", "Need to pass in as many hj_names as cjs"); 49 : // Check to make sure the the number of etas is the same as the number of cj's 50 48 : if (_num_j != _eta_names.size()) 51 0 : paramError("etas", "Need to pass in as many etas as cjs"); 52 : 53 48 : if (_num_j == 0) 54 0 : mooseError("Need to supply at least 1 phase concentration cj in KKSMultiPhaseConcentration", 55 : name()); 56 : 57 : // get order parameter names and variable indices 58 156 : for (unsigned int i = 0; i < _num_j; ++i) 59 216 : _eta_names[i] = coupledName("etas", i); 60 : 61 : // Load concentration variables into the arrays 62 156 : for (unsigned int m = 0; m < _num_j; ++m) 63 : { 64 108 : _prop_hj[m] = &getMaterialPropertyByName<Real>(_hj_names[m]); 65 108 : _prop_dhjdetai[m].resize(_num_j); 66 : // Set _k to the position of the nonlinear variable in the list of cj's 67 108 : if (coupled("cj", m) == _var.number()) 68 48 : _k = m; 69 : 70 : // Get derivatives of switching functions wrt order parameters 71 360 : for (unsigned int n = 0; n < _num_j; ++n) 72 252 : _prop_dhjdetai[m][n] = &getMaterialPropertyDerivative<Real>(_hj_names[m], _eta_names[n]); 73 : } 74 : 75 : // Check to make sure the nonlinear variable is set to one of the cj's 76 48 : if (_k < 0) 77 0 : mooseError("Need to set nonlinear variable to one of the cj's in KKSMultiPhaseConcentration", 78 : name()); 79 48 : } 80 : 81 : Real 82 792280 : KKSMultiPhaseConcentration::precomputeQpResidual() 83 : { 84 : // R = sum_i (h_i * c_i) - c 85 : Real sum_ch = 0.0; 86 2820040 : for (unsigned int m = 0; m < _num_j; ++m) 87 2027760 : sum_ch += (*_cj[m])[_qp] * (*_prop_hj[m])[_qp]; 88 : 89 792280 : return sum_ch - _c[_qp]; 90 : } 91 : 92 : Real 93 460160 : KKSMultiPhaseConcentration::precomputeQpJacobian() 94 : { 95 460160 : return (*_prop_hj[_k])[_qp] * _phi[_j][_qp]; 96 : } 97 : 98 : Real 99 8934400 : KKSMultiPhaseConcentration::computeQpOffDiagJacobian(unsigned int jvar) 100 : { 101 8934400 : if (jvar == _c_var) 102 1585920 : return -_test[_i][_qp] * _phi[_j][_qp]; 103 : 104 7348480 : auto cjvar = mapJvarToCvar(jvar, _cj_map); 105 7348480 : if (cjvar >= 0) 106 2917120 : return _test[_i][_qp] * (*_prop_hj[cjvar])[_qp] * _phi[_j][_qp]; 107 : 108 4431360 : auto etavar = mapJvarToCvar(jvar, _eta_map); 109 4431360 : if (etavar >= 0) 110 : { 111 : Real sum = 0.0; 112 : 113 17287680 : for (unsigned int n = 0; n < _num_j; ++n) 114 12856320 : sum += (*_prop_dhjdetai[n][etavar])[_qp] * (*_cj[n])[_qp]; 115 : 116 4431360 : return _test[_i][_qp] * sum * _phi[_j][_qp]; 117 : } 118 : 119 : return 0.0; 120 : }