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 "SLKKSMultiPhaseBase.h" 11 : 12 : InputParameters 13 84 : SLKKSMultiPhaseBase::validParams() 14 : { 15 84 : auto params = Kernel::validParams(); 16 168 : params.addRequiredCoupledVar("cs", "Array of sublattice concentrations phase for all phases"); 17 168 : params.addCoupledVar("eta", "Order parameters for all phases"); 18 168 : params.addRequiredParam<std::vector<unsigned int>>("ns", "Number of sublattices in each phase"); 19 168 : params.addRequiredParam<std::vector<Real>>("as", "Sublattice site fractions n all phases"); 20 168 : params.addRequiredParam<std::vector<MaterialPropertyName>>( 21 : "h_names", "Switching Function Materials for all phases"); 22 84 : return params; 23 0 : } 24 : 25 : // Phase interpolation func 26 45 : SLKKSMultiPhaseBase::SLKKSMultiPhaseBase(const InputParameters & parameters) 27 : : DerivativeMaterialInterface<JvarMapKernelInterface<KernelValue>>(parameters), 28 45 : _ncs(coupledComponents("cs")), 29 45 : _cs(_ncs), 30 45 : _cs_map(getParameterJvarMap("cs")), 31 90 : _ns(getParam<std::vector<unsigned int>>("ns")), 32 45 : _neta(coupledComponents("eta")), 33 45 : _eta_names(_neta), 34 45 : _eta_map(getParameterJvarMap("eta")), 35 90 : _a_cs(getParam<std::vector<Real>>("as")), 36 135 : _h_names(getParam<std::vector<MaterialPropertyName>>("h_names")), 37 45 : _nh(_h_names.size()), 38 45 : _phase(_ncs), 39 45 : _c(coupledValue("c")), 40 90 : _c_var(coupled("c")) 41 : { 42 : // consistent number of phases? 43 45 : if (_ns.size() != _nh) 44 0 : paramError("ns", 45 : "Need to pass in as many switching functions (parameter `h_names`) as size of " 46 : "number of sublattices in each phase (parameter `ns`)"); 47 : 48 : // sum up ns numbers 49 : unsigned int nssum = 0; 50 135 : for (auto i : _ns) 51 : { 52 90 : if (i == 0) 53 0 : paramError("ns", "All sublattice counts must be larger than zero"); 54 90 : nssum += i; 55 : } 56 : 57 45 : if (nssum != _ncs) 58 0 : paramError("ns", "Numbers need to sum up to the number of passed in cs variables"); 59 45 : if (_ncs == 0) 60 0 : paramError("cs", "Need to supply at least 1 phase sublattice concentration"); 61 : 62 : // get order parameter names 63 135 : for (std::size_t i = 0; i < _neta; ++i) 64 180 : _eta_names[i] = coupledName("eta", i); 65 : 66 : // Load concentration variables into the arrays 67 225 : for (std::size_t i = 0; i < _ncs; ++i) 68 180 : _cs[i] = &coupledValue("cs", i); 69 : 70 : // normalize sublattice counts within each phase 71 : std::size_t k = 0; 72 135 : for (std::size_t i = 0; i < _nh; ++i) 73 : { 74 : // sum site counts 75 90 : Real sum = _a_cs[k]; 76 180 : for (unsigned int j = 1; j < _ns[i]; ++j) 77 90 : sum += _a_cs[j + k]; 78 90 : if (sum <= 0) 79 0 : paramError("as", "Sum of sublattice site counts in each phase must be larger than zero"); 80 : 81 : // normalize 82 270 : for (unsigned int j = 0; j < _ns[i]; ++j) 83 : { 84 180 : _a_cs[j + k] /= sum; 85 : 86 : // remember phase index 87 180 : _phase[j + k] = i; 88 : } 89 : 90 : // next phase 91 90 : k += _ns[i]; 92 : } 93 : 94 : // consistency checks 95 45 : if (k != _ncs) 96 0 : mooseError("Internal error"); 97 45 : }