https://mooseframework.inl.gov
NestedKKSSplitCHCRes.C
Go to the documentation of this file.
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 "NestedKKSSplitCHCRes.h"
11 
13 
16 {
18  params.addClassDescription(
19  "KKS model kernel for the split Bulk Cahn-Hilliard term. This kernel operates on the "
20  "physical concentration 'c' as the non-linear variable.");
21  params.addCoupledVar("all_etas", "Phase parameters for all phases.");
22  params.addRequiredCoupledVar("global_cs", "The interpolated concentrations c, b, etc.");
23  params.addCoupledVar("w", "Chemical potential non-linear helper variable for the split solve.");
24  params.addParam<std::vector<MaterialPropertyName>>(
25  "ca_names",
26  "Phase concentrations in the frist phase of all_etas. The order must match global_cs, for "
27  "example, c1, b1, etc.");
28  params.addParam<MaterialPropertyName>("fa_name", "Free energy of the first phase in all_etas.");
29  return params;
30 }
31 
34  _eta_names(coupledNames("all_etas")),
35  _num_j(_eta_names.size()),
36  _eta_map(getParameterJvarMap("all_etas")),
37  _c_names(coupledNames("global_cs")),
38  _num_c(coupledComponents("global_cs")),
39  _c_map(getParameterJvarMap("global_cs")),
40  _o(-1),
41  _w_var(coupled("w")),
42  _w(coupledValue("w")),
43  _ca_names(getParam<std::vector<MaterialPropertyName>>("ca_names")),
44  _Fa_name(getParam<MaterialPropertyName>("fa_name")),
45  _dFadca(_num_c),
46  _d2Fadcadba(_num_c),
47  _dcadb(_num_c),
48  _dcadetaj(_num_c),
49  _d2Fadcadarg(_n_args)
50 
51 {
52  for (const auto i : make_range(_num_c))
53  {
54  // Set _o to the position of the nonlinear variable in the list of global_cs
55  if (coupled("global_cs", i) == _var.number())
56  _o = i;
57  }
58 
59  // _dcideta and _dcidb are computed in KKSPhaseConcentrationDerivatives
60  for (const auto m : make_range(_num_c))
61  {
62  _dcadetaj[m].resize(_num_j);
63  for (const auto n : make_range(_num_j))
64  _dcadetaj[m][n] = &getMaterialPropertyDerivative<Real>(_ca_names[m], _eta_names[n]);
65 
66  _dcadb[m].resize(_num_c);
67  for (const auto n : make_range(_num_c))
68  _dcadb[m][n] = &getMaterialPropertyDerivative<Real>(_ca_names[m], _c_names[n]);
69  }
70 
71  // _dFaca and _d2Fadcadba are computed in KKSPhaseConcentrationMaterial
72  for (const auto m : make_range(_num_c))
73  {
74  _dFadca[m] = &getMaterialPropertyDerivative<Real>(_Fa_name, _ca_names[m]);
75  _d2Fadcadba[m] = &getMaterialPropertyDerivative<Real>(_Fa_name, _ca_names[_o], _ca_names[m]);
76  }
77 
78  // _d2Fadcadarg is computed in KKSPhaseConcentrationMaterial
79  for (const auto m : make_range(_n_args))
80  _d2Fadcadarg[m] = &getMaterialPropertyDerivative<Real>(_Fa_name, _ca_names[_o], m);
81 }
82 
83 Real
85 {
86  return ((*_dFadca[_o])[_qp] - _w[_qp]) * _test[_i][_qp];
87 }
88 
89 Real
91 {
92  Real sum = 0.0;
93 
94  for (const auto m : make_range(_num_c))
95  sum += (*_d2Fadcadba[m])[_qp] * (*_dcadb[m][_o])[_qp];
96 
97  return sum * _phi[_j][_qp] * _test[_i][_qp];
98 }
99 
100 Real
102 {
103  Real sum = 0.0;
104 
105  // treat w variable explicitly
106  if (jvar == _w_var)
107  return -_phi[_j][_qp] * _test[_i][_qp];
108 
109  // if b is the coupled variable
110  auto compvar = mapJvarToCvar(jvar, _c_map);
111  if (compvar >= 0)
112  {
113  for (const auto m : make_range(_num_c))
114  sum += (*_d2Fadcadba[m])[_qp] * (*_dcadb[m][compvar])[_qp];
115 
116  return sum * _phi[_j][_qp] * _test[_i][_qp];
117  }
118 
119  // if order parameters are the coupled variables
120  auto etavar = mapJvarToCvar(jvar, _eta_map);
121  if (etavar >= 0)
122  {
123  for (const auto m : make_range(_num_c))
124  sum += (*_d2Fadcadba[m])[_qp] * (*_dcadetaj[m][etavar])[_qp];
125 
126  return sum * _phi[_j][_qp] * _test[_i][_qp];
127  }
128 
129  // for all other vars get the coupled variable jvar is referring to
130  const unsigned int cvar = mapJvarToCvar(jvar);
131  return (*_d2Fadcadarg[cvar])[_qp] * _phi[_j][_qp] * _test[_i][_qp];
132 }
const VariableValue & _w
virtual unsigned int coupled(const std::string &var_name, unsigned int comp=0) const
const unsigned int _w_var
Chemical potential.
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
unsigned int number() const
const MaterialPropertyName _Fa_name
Free energy.
registerMooseObject("PhaseFieldApp", NestedKKSSplitCHCRes)
NestedKKSSplitCHCRes(const InputParameters &parameters)
static InputParameters validParams()
const std::vector< MaterialPropertyName > _ca_names
Phase concentration of the first phase in _eta_names.
std::vector< std::vector< const MaterialProperty< Real > * > > _dcadetaj
Derivative of the phase concentrations wrt phase parameter .
In the KKS split form for the term .
virtual Real computeQpResidual() override
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override
static InputParameters validParams()
const unsigned int _num_c
Number of global concentrations.
std::vector< const MaterialProperty< Real > * > _d2Fadcadba
Second derivative of the free energy function .
std::vector< const MaterialProperty< Real > * > _d2Fadcadarg
Second derivative of the free energy function wrt phase concentration and a coupled variable...
void addCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
const std::vector< VariableName > _eta_names
Phase parameters.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< std::vector< const MaterialProperty< Real > * > > _dcadb
Derivative of the phase concentrations wrt global concentrations .
IntRange< T > make_range(T beg, T end)
const unsigned int _num_j
Number of phase parameters.
void addClassDescription(const std::string &doc_string)
virtual Real computeQpJacobian() override
const std::vector< VariableName > _c_names
Global concentrations.
std::vector< const MaterialProperty< Real > * > _dFadca
Derivative of the free energy function .