www.mooseframework.org
MatReaction.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 #include "MatReaction.h"
8 
9 template <>
10 InputParameters
12 {
13  InputParameters params = validParams<Kernel>();
14  params.addCoupledVar("v",
15  "Set this to make v a coupled variable, otherwise it will use the "
16  "kernel's nonlinear variable for v");
17  params.addClassDescription("Kernel to add -L*v, where L=reaction rate, v=variable");
18  params.addParam<MaterialPropertyName>("mob_name", "L", "The reaction rate used with the kernel");
19  params.addCoupledVar("args", "Vector of nonlinear variable arguments this object depends on");
20  return params;
21 }
22 
23 MatReaction::MatReaction(const InputParameters & parameters)
24  : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters),
25  _is_coupled(isCoupled("v")),
26  _v_name(_is_coupled ? getVar("v", 0)->name() : _var.name()),
27  _v(_is_coupled ? coupledValue("v") : _u),
28  _v_var(_is_coupled ? coupled("v") : _var.number()),
29  _L(getMaterialProperty<Real>("mob_name")),
30  _eta_name(_var.name()),
31  _dLdop(getMaterialPropertyDerivative<Real>("mob_name", _eta_name)),
32  _dLdv(getMaterialPropertyDerivative<Real>("mob_name", _v_name)),
33  _nvar(_coupled_moose_vars.size()),
34  _dLdarg(_nvar)
35 {
36  // Get reaction rate derivatives
37  for (unsigned int i = 0; i < _nvar; ++i)
38  {
39  MooseVariable * ivar = _coupled_moose_vars[i];
40  _dLdarg[i] = &getMaterialPropertyDerivative<Real>("mob_name", ivar->name());
41  }
42 }
43 
44 void
46 {
47  validateNonlinearCoupling<Real>("mob_name");
48 }
49 
50 Real
52 {
53  return -_L[_qp] * _test[_i][_qp] * _v[_qp];
54 }
55 
56 Real
58 {
59  if (_is_coupled)
60  return -_dLdop[_qp] * _v[_qp] * _phi[_j][_qp] * _test[_i][_qp];
61 
62  return -(_L[_qp] + _dLdop[_qp] * _v[_qp]) * _phi[_j][_qp] * _test[_i][_qp];
63 }
64 
65 Real
67 {
68  // first handle the case where jvar is a coupled variable v being added to residual
69  // the first term in the sum just multiplies by L which is always needed
70  // the second term accounts for cases where L depends on v
71  if ((jvar == _v_var) && _is_coupled)
72  return -(_L[_qp] + _dLdv[_qp] * _v[_qp]) * _test[_i][_qp] * _phi[_j][_qp];
73 
74  // for all other vars get the coupled variable jvar is referring to
75  const unsigned int cvar = mapJvarToCvar(jvar);
76 
77  return -(*_dLdarg[cvar])[_qp] * _v[_qp] * _test[_i][_qp] * _phi[_j][_qp];
78 }
const unsigned int _nvar
number of coupled variables
Definition: MatReaction.h:61
virtual void initialSetup()
Definition: MatReaction.C:45
MatReaction(const InputParameters &parameters)
Definition: MatReaction.C:23
unsigned int _v_var
Definition: MatReaction.h:46
const MaterialProperty< Real > & _dLdv
Reaction rate derivative w.r.t. the variable being added by this kernel.
Definition: MatReaction.h:58
InputParameters validParams< MatReaction >()
Definition: MatReaction.C:11
const MaterialProperty< Real > & _dLdop
Reaction rate derivative w.r.t. order parameter.
Definition: MatReaction.h:55
virtual Real computeQpResidual()
Definition: MatReaction.C:51
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
Definition: MatReaction.C:66
const bool _is_coupled
is the kernel used in a coupled form?
Definition: MatReaction.h:36
std::vector< const MaterialProperty< Real > * > _dLdarg
Reaction rate derivatives w.r.t. other coupled variables.
Definition: MatReaction.h:64
const MaterialProperty< Real > & _L
Reaction rate.
Definition: MatReaction.h:49
const VariableValue & _v
Definition: MatReaction.h:45
virtual Real computeQpJacobian()
Definition: MatReaction.C:57