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