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