www.mooseframework.org
ACMultiInterface.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
8 #include "ACMultiInterface.h"
9 
10 // MOOSE includes
11 #include "MooseVariable.h"
12 #include "NonlinearSystem.h"
13 
14 template <>
15 InputParameters
17 {
18  InputParameters params = validParams<Kernel>();
19  params.addClassDescription("Gradient energy Allen-Cahn Kernel with cross terms");
20  params.addRequiredCoupledVar("etas", "All eta_i order parameters of the multiphase problem");
21  params.addRequiredParam<std::vector<MaterialPropertyName>>("kappa_names",
22  "The kappa used with the kernel");
23  params.addParam<MaterialPropertyName>("mob_name", "L", "The mobility used with the kernel");
24  return params;
25 }
26 
27 ACMultiInterface::ACMultiInterface(const InputParameters & parameters)
28  : Kernel(parameters),
29  _num_etas(coupledComponents("etas")),
30  _eta(_num_etas),
31  _grad_eta(_num_etas),
32  _eta_vars(_fe_problem.getNonlinearSystemBase().nVariables(), -1),
33  _kappa_names(getParam<std::vector<MaterialPropertyName>>("kappa_names")),
34  _kappa(_num_etas),
35  _L(getMaterialProperty<Real>("mob_name"))
36 {
37  if (_num_etas != _kappa_names.size())
38  mooseError("Supply the same nummber of etas and kappa_names.");
39 
40  unsigned int nvariables = _fe_problem.getNonlinearSystemBase().nVariables();
41 
42  int a = -1;
43  for (unsigned int i = 0; i < _num_etas; ++i)
44  {
45  // get all order parameters and their gradients
46  _eta[i] = &coupledValue("etas", i);
47  _grad_eta[i] = &coupledGradient("etas", i);
48 
49  // populate lookup table form jvar to _eta index
50  unsigned int var = coupled("etas", i);
51  if (var < nvariables)
52  _eta_vars[var] = i;
53 
54  // get the index of the variable the kernel is operating on
55  if (coupled("etas", i) == _var.number())
56  a = i;
57 
58  // get gradient prefactors
59  _kappa[i] = &getMaterialPropertyByName<Real>(_kappa_names[i]);
60  }
61 
62  if (a < 0)
63  mooseError("Kernel variable must be listed in etas for ACMultiInterface kernel ", name());
64  else
65  _a = a;
66 }
67 
68 Real
70 {
71  const VariableValue & _eta_a = _u;
72  const VariableGradient & _grad_eta_a = _grad_u;
73 
74  Real sum = 0.0;
75  for (unsigned int b = 0; b < _num_etas; ++b)
76  {
77  // skip the diagonal term (does not contribute)
78  if (b == _a)
79  continue;
80 
81  sum += (*_kappa[b])[_qp] *
82  (
83  // order 1 terms
84  2.0 * _test[_i][_qp] *
85  (_eta_a[_qp] * (*_grad_eta[b])[_qp] - (*_eta[b])[_qp] * _grad_eta_a[_qp]) *
86  (*_grad_eta[b])[_qp]
87  // volume terms
88  +
89  (-(_eta_a[_qp] * (*_eta[b])[_qp] * _grad_test[_i][_qp] +
90  _test[_i][_qp] * (*_eta[b])[_qp] * _grad_eta_a[_qp] +
91  _test[_i][_qp] * _eta_a[_qp] * (*_grad_eta[b])[_qp]) *
92  (*_grad_eta[b])[_qp]) -
93  (-((*_eta[b])[_qp] * (*_eta[b])[_qp] * _grad_test[_i][_qp] +
94  2.0 * _test[_i][_qp] * (*_eta[b])[_qp] * (*_grad_eta[b])[_qp]) *
95  _grad_eta_a[_qp]));
96  }
97 
98  return _L[_qp] * sum;
99 }
100 
101 Real
103 {
104  Real sum = 0.0;
105  for (unsigned int b = 0; b < _num_etas; ++b)
106  {
107  // skip the diagonal term (does not contribute)
108  if (b == _a)
109  continue;
110 
111  sum += (*_kappa[b])[_qp] * (2.0 * _test[_i][_qp] * ((_phi[_j][_qp] * (*_grad_eta[b])[_qp] -
112  (*_eta[b])[_qp] * _grad_phi[_j][_qp]) *
113  (*_grad_eta[b])[_qp]) +
114  (-(_phi[_j][_qp] * (*_eta[b])[_qp] * _grad_test[_i][_qp] +
115  _test[_i][_qp] * (*_eta[b])[_qp] * _grad_phi[_j][_qp] +
116  _test[_i][_qp] * _phi[_j][_qp] * (*_grad_eta[b])[_qp]) *
117  (*_grad_eta[b])[_qp]) -
118  (-((*_eta[b])[_qp] * (*_eta[b])[_qp] * _grad_test[_i][_qp] +
119  2.0 * _test[_i][_qp] * (*_eta[b])[_qp] * (*_grad_eta[b])[_qp]) *
120  _grad_phi[_j][_qp]));
121  }
122 
123  return _L[_qp] * sum;
124 }
125 
126 Real
128 {
129  const VariableValue & _eta_a = _u;
130  const VariableGradient & _grad_eta_a = _grad_u;
131 
132  const int b = _eta_vars[jvar];
133  if (b < 0)
134  return 0.0;
135 
136  return _L[_qp] * (*_kappa[b])[_qp] *
137  (2.0 * _test[_i][_qp] *
138  ((_eta_a[_qp] * _grad_phi[_j][_qp] - _phi[_j][_qp] * _grad_eta_a[_qp]) *
139  (*_grad_eta[b])[_qp] +
140  (_eta_a[_qp] * (*_grad_eta[b])[_qp] - (*_eta[b])[_qp] * _grad_eta_a[_qp]) *
141  _grad_phi[_j][_qp]) +
142  (-(_eta_a[_qp] * _phi[_j][_qp] * _grad_test[_i][_qp] +
143  _test[_i][_qp] * _phi[_j][_qp] * _grad_eta_a[_qp] +
144  _test[_i][_qp] * _eta_a[_qp] * _grad_phi[_j][_qp]) *
145  (*_grad_eta[b])[_qp] -
146  (_eta_a[_qp] * (*_eta[b])[_qp] * _grad_test[_i][_qp] +
147  _test[_i][_qp] * (*_eta[b])[_qp] * _grad_eta_a[_qp] +
148  _test[_i][_qp] * _eta_a[_qp] * (*_grad_eta[b])[_qp]) *
149  _grad_phi[_j][_qp]) -
150  (-(2.0 * (*_eta[b])[_qp] * _phi[_j][_qp] * _grad_test[_i][_qp] +
151  2.0 * _test[_i][_qp] *
152  (_phi[_j][_qp] * (*_grad_eta[b])[_qp] + (*_eta[b])[_qp] * _grad_phi[_j][_qp])) *
153  _grad_eta_a[_qp]));
154 }
unsigned int _a
Index of the eta this kernel is operating on.
ACMultiInterface(const InputParameters &parameters)
std::vector< int > _eta_vars
Lookup table from couple variable number into the etas vector.
unsigned int _num_etas
Order parameters.
virtual Real computeQpResidual()
InputParameters validParams< ACMultiInterface >()
std::vector< const MaterialProperty< Real > * > _kappa
std::vector< const VariableValue * > _eta
virtual Real computeQpOffDiagJacobian(unsigned int)
const MaterialProperty< Real > & _L
Mobility.
virtual Real computeQpJacobian()
std::vector< const VariableGradient * > _grad_eta
std::vector< MaterialPropertyName > _kappa_names
Interface gradient prefactor.