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 "SLKKSPhaseConcentration.h" 11 : 12 : registerMooseObject("PhaseFieldApp", SLKKSPhaseConcentration); 13 : 14 : InputParameters 15 0 : SLKKSPhaseConcentration::validParams() 16 : { 17 0 : auto params = Kernel::validParams(); 18 0 : params.addClassDescription( 19 : "Sublattice KKS model kernel to enforce the decomposition of concentration into " 20 : "phase and sublattice concentrations The non-linear variable of this kernel is a sublattice " 21 : "concentration of phase b."); 22 0 : params.addRequiredCoupledVar("ca", "Phase a sublattice concentrations"); 23 0 : params.addRequiredParam<std::vector<Real>>("aa", "Phase a sublattice site fraction"); 24 0 : params.addRequiredCoupledVar( 25 : "cb", "Phase b sublattice concentrations (except for the kernel variable)"); 26 0 : params.addRequiredParam<std::vector<Real>>("ab", "Phase b sublattice site fraction"); 27 0 : params.addRequiredParam<Real>("a", 28 : "Sublattice site fraction for the kernel variable (in phase b)"); 29 0 : params.addRequiredCoupledVar("c", "Global concentration"); 30 0 : params.addRequiredCoupledVar("eta", "Phase a/b order parameter"); 31 0 : params.addParam<MaterialPropertyName>( 32 : "h_name", "h", "Base name for the switching function h(eta)"); 33 0 : return params; 34 0 : } 35 : 36 : // Phase interpolation func 37 0 : SLKKSPhaseConcentration::SLKKSPhaseConcentration(const InputParameters & parameters) 38 : : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters), 39 0 : _nca(coupledComponents("ca")), 40 0 : _ca(_nca), 41 0 : _a_ca(getParam<std::vector<Real>>("aa")), 42 0 : _ca_map(getParameterJvarMap("ca")), 43 0 : _ncb(coupledComponents("cb")), 44 0 : _cb(_ncb), 45 0 : _a_cb(getParam<std::vector<Real>>("ab")), 46 0 : _cb_map(getParameterJvarMap("cb")), 47 0 : _a_u(getParam<Real>("a")), 48 0 : _c(coupledValue("c")), 49 0 : _c_var(coupled("c")), 50 0 : _eta(coupledValue("eta")), 51 0 : _eta_var(coupled("eta")), 52 0 : _prop_h(getMaterialProperty<Real>("h_name")), 53 0 : _prop_dh(getMaterialPropertyDerivative<Real>("h_name", coupledName("eta", 0))) 54 : { 55 0 : if (_a_ca.size() != _nca) 56 0 : paramError("aa", "Specify one sublattice site fraction per sublattice concentration variable"); 57 0 : if (_a_cb.size() != _ncb) 58 0 : paramError("ab", "Specify one sublattice site fraction per sublattice concentration variable"); 59 : 60 : // check and re-normalize sublattice A site fractions 61 : Real sum = 0.0; 62 0 : for (std::size_t i = 0; i < _nca; ++i) 63 0 : sum += _a_ca[i]; 64 0 : if (sum <= 0.0) 65 0 : paramError("aa", "The sum of the aa values must be greater than zero"); 66 0 : for (std::size_t i = 0; i < _nca; ++i) 67 0 : _a_ca[i] /= sum; 68 : 69 : // check and re-normalize sublattice B site fractions 70 0 : sum = _a_u; 71 0 : for (std::size_t i = 0; i < _ncb; ++i) 72 0 : sum += _a_cb[i]; 73 0 : if (sum <= 0.0) 74 0 : paramError("ab", "The sum of the ab values and k must be greater than zero"); 75 0 : for (std::size_t i = 0; i < _ncb; ++i) 76 0 : _a_cb[i] /= sum; 77 0 : _a_u /= sum; 78 : 79 : // fetch coupled concentrations 80 0 : for (std::size_t i = 0; i < _nca; ++i) 81 0 : _ca[i] = &coupledValue("ca", i); 82 0 : for (std::size_t i = 0; i < _ncb; ++i) 83 0 : _cb[i] = &coupledValue("cb", i); 84 0 : } 85 : 86 : Real 87 0 : SLKKSPhaseConcentration::computeQpResidual() 88 : { 89 0 : computeSums(); 90 0 : return _test[_i][_qp] * ((1.0 - _prop_h[_qp]) * _casum + _prop_h[_qp] * _cbsum - _c[_qp]); 91 : } 92 : 93 : Real 94 0 : SLKKSPhaseConcentration::computeQpJacobian() 95 : { 96 0 : return _test[_i][_qp] * _prop_h[_qp] * _phi[_j][_qp] * _a_u; 97 : } 98 : 99 : Real 100 0 : SLKKSPhaseConcentration::computeQpOffDiagJacobian(unsigned int jvar) 101 : { 102 0 : if (jvar == _c_var) 103 0 : return -_test[_i][_qp] * _phi[_j][_qp]; 104 : 105 0 : if (jvar == _eta_var) 106 : { 107 0 : computeSums(); 108 0 : return _test[_i][_qp] * (_cbsum - _casum) * _prop_dh[_qp] * _phi[_j][_qp]; 109 : } 110 : 111 0 : auto cavar = mapJvarToCvar(jvar, _ca_map); 112 0 : if (cavar >= 0) 113 0 : return _test[_i][_qp] * (1.0 - _prop_h[_qp]) * _phi[_j][_qp] * _a_ca[cavar]; 114 : 115 0 : auto cbvar = mapJvarToCvar(jvar, _cb_map); 116 0 : if (cbvar >= 0) 117 0 : return _test[_i][_qp] * _prop_h[_qp] * _phi[_j][_qp] * _a_cb[cbvar]; 118 : 119 : return 0.0; 120 : } 121 : 122 : void 123 0 : SLKKSPhaseConcentration::computeSums() 124 : { 125 0 : _casum = 0.0; 126 0 : for (std::size_t i = 0; i < _nca; ++i) 127 0 : _casum += (*_ca[i])[_qp] * _a_ca[i]; 128 : 129 0 : _cbsum = _u[_qp] * _a_u; 130 0 : for (std::size_t i = 0; i < _ncb; ++i) 131 0 : _cbsum += (*_cb[i])[_qp] * _a_cb[i]; 132 0 : }