www.mooseframework.org
CoupledSwitchingTimeDerivative.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<CoupledTimeDerivative>();
19  params.addClassDescription(
20  "Coupled time derivative Kernel that multiplies the time derivative by "
21  "$\\frac{dh_\\alpha}{d\\eta_i} F_\\alpha + \\frac{dh_\\beta}{d\\eta_i} F_\\beta + \\dots)");
22  params.addRequiredParam<std::vector<MaterialPropertyName>>(
23  "Fj_names", "List of functions for each phase. Place in same order as hj_names!");
24  params.addRequiredParam<std::vector<MaterialPropertyName>>(
25  "hj_names", "Switching Function Materials that provide h. Place in same order as Fj_names!");
26  params.addCoupledVar("args", "Vector of arguments of Fj and hj");
27  return params;
28 }
29 
31  : DerivativeMaterialInterface<JvarMapKernelInterface<CoupledTimeDerivative>>(parameters),
32  _nvar(_coupled_moose_vars.size()), // number of coupled variables
33  _v_name(getVar("v", 0)->name()),
34  _Fj_names(getParam<std::vector<MaterialPropertyName>>("Fj_names")),
35  _num_j(_Fj_names.size()),
36  _prop_Fj(_num_j),
37  _prop_dFjdv(_num_j),
38  _prop_dFjdarg(_num_j),
39  _hj_names(getParam<std::vector<MaterialPropertyName>>("hj_names")),
40  _prop_dhjdetai(_num_j),
41  _prop_d2hjdetai2(_num_j),
42  _prop_d2hjdetaidarg(_num_j)
43 {
44  // check passed in parameter vectors
45  if (_num_j != _hj_names.size())
46  paramError("hj_names", "Need to pass in as many hj_names as Fj_names");
47 
48  // reserve space and set phase material properties
49  for (unsigned int n = 0; n < _num_j; ++n)
50  {
51  // get phase free energy and derivatives
52  _prop_Fj[n] = &getMaterialPropertyByName<Real>(_Fj_names[n]);
53  _prop_dFjdv[n] = &getMaterialPropertyDerivative<Real>(_Fj_names[n], _var.name());
54  _prop_dFjdarg[n].resize(_nvar);
55 
56  // get switching function and derivatives wrt eta_i, the nonlinear variable
57  _prop_dhjdetai[n] = &getMaterialPropertyDerivative<Real>(_hj_names[n], _v_name);
58  _prop_d2hjdetai2[n] = &getMaterialPropertyDerivative<Real>(_hj_names[n], _v_name, _v_name);
59  _prop_d2hjdetaidarg[n].resize(_nvar);
60 
61  for (unsigned int i = 0; i < _nvar; ++i)
62  {
63  MooseVariableFEBase * cvar = _coupled_moose_vars[i];
64  // Get derivatives of all Fj wrt all coupled variables
65  _prop_dFjdarg[n][i] = &getMaterialPropertyDerivative<Real>(_Fj_names[n], cvar->name());
66 
67  // Get second derivatives of all hj wrt eta_i and all coupled variables
68  _prop_d2hjdetaidarg[n][i] =
69  &getMaterialPropertyDerivative<Real>(_hj_names[n], _v_name, cvar->name());
70  }
71  }
72 }
73 
74 void
76 {
77  for (unsigned int n = 0; n < _num_j; ++n)
78  {
79  validateNonlinearCoupling<Real>(_Fj_names[n]);
80  validateNonlinearCoupling<Real>(_hj_names[n]);
81  }
82 }
83 
84 Real
86 {
87  Real sum = 0.0;
88  for (unsigned int n = 0; n < _num_j; ++n)
89  sum += (*_prop_dhjdetai[n])[_qp] * (*_prop_Fj[n])[_qp];
90 
91  return CoupledTimeDerivative::computeQpResidual() * sum;
92 }
93 
94 Real
96 {
97  Real sum = 0.0;
98  for (unsigned int n = 0; n < _num_j; ++n)
99  sum += (*_prop_dhjdetai[n])[_qp] * (*_prop_dFjdv[n])[_qp];
100 
101  return CoupledTimeDerivative::computeQpResidual() * sum * _phi[_j][_qp];
102 }
103 
104 Real
106 {
107  // get the coupled variable jvar is referring to
108  const unsigned int cvar = mapJvarToCvar(jvar);
109 
110  if (jvar == _v_var)
111  {
112  Real sum = 0.0;
113 
114  for (unsigned int n = 0; n < _num_j; ++n)
115  sum +=
116  ((*_prop_d2hjdetai2[n])[_qp] * _v_dot[_qp] + (*_prop_dhjdetai[n])[_qp] * _dv_dot[_qp]) *
117  (*_prop_Fj[n])[_qp];
118 
119  return _phi[_j][_qp] * sum * _test[_i][_qp];
120  }
121 
122  Real sum = 0.0;
123  for (unsigned int n = 0; n < _num_j; ++n)
124  sum += (*_prop_d2hjdetaidarg[n][cvar])[_qp] * (*_prop_Fj[n])[_qp] +
125  (*_prop_dhjdetai[n])[_qp] * (*_prop_dFjdarg[n][cvar])[_qp];
126 
127  return CoupledTimeDerivative::computeQpResidual() * sum * _phi[_j][_qp];
128 }
CoupledSwitchingTimeDerivative::_prop_dhjdetai
std::vector< const MaterialProperty< Real > * > _prop_dhjdetai
Derivatives of the switching functions wrt the order parameter for this kernel.
Definition: CoupledSwitchingTimeDerivative.h:70
CoupledSwitchingTimeDerivative::_prop_dFjdarg
std::vector< std::vector< const MaterialProperty< Real > * > > _prop_dFjdarg
Derivatives of the functions (needed for off-diagonal Jacobians)
Definition: CoupledSwitchingTimeDerivative.h:64
CoupledSwitchingTimeDerivative::computeQpJacobian
virtual Real computeQpJacobian()
Definition: CoupledSwitchingTimeDerivative.C:95
CoupledSwitchingTimeDerivative::_prop_Fj
std::vector< const MaterialProperty< Real > * > _prop_Fj
Values of the functions for each phase .
Definition: CoupledSwitchingTimeDerivative.h:58
CoupledSwitchingTimeDerivative::_Fj_names
std::vector< MaterialPropertyName > _Fj_names
Names of functions for each phase .
Definition: CoupledSwitchingTimeDerivative.h:52
CoupledSwitchingTimeDerivative::_prop_d2hjdetai2
std::vector< const MaterialProperty< Real > * > _prop_d2hjdetai2
Second derivatives of the switching functions wrt the order parameter for this kernel.
Definition: CoupledSwitchingTimeDerivative.h:73
CoupledSwitchingTimeDerivative
This kernel adds a contribution where are the phases, are the switching functions,...
Definition: CoupledSwitchingTimeDerivative.h:32
CoupledSwitchingTimeDerivative::CoupledSwitchingTimeDerivative
CoupledSwitchingTimeDerivative(const InputParameters &parameters)
Definition: CoupledSwitchingTimeDerivative.C:30
name
const std::string name
Definition: Setup.h:21
CoupledSwitchingTimeDerivative::_prop_dFjdv
std::vector< const MaterialProperty< Real > * > _prop_dFjdv
Derivatives of the functions wrt the nonlinear variable for this kernel.
Definition: CoupledSwitchingTimeDerivative.h:61
CoupledSwitchingTimeDerivative::_prop_d2hjdetaidarg
std::vector< std::vector< const MaterialProperty< Real > * > > _prop_d2hjdetaidarg
Second derivatives of the switching functions (needed for off-diagonal Jacobians)
Definition: CoupledSwitchingTimeDerivative.h:76
CoupledSwitchingTimeDerivative::_hj_names
std::vector< MaterialPropertyName > _hj_names
switching function names
Definition: CoupledSwitchingTimeDerivative.h:67
CoupledSwitchingTimeDerivative::_nvar
const unsigned int _nvar
Number of coupled variables.
Definition: CoupledSwitchingTimeDerivative.h:45
CoupledSwitchingTimeDerivative::computeQpOffDiagJacobian
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
Definition: CoupledSwitchingTimeDerivative.C:105
CoupledSwitchingTimeDerivative.h
CoupledSwitchingTimeDerivative::_v_name
const VariableName _v_name
name of order parameter that derivatives are taken wrt (needed to retrieve the derivative material pr...
Definition: CoupledSwitchingTimeDerivative.h:49
registerMooseObject
registerMooseObject("PhaseFieldApp", CoupledSwitchingTimeDerivative)
CoupledSwitchingTimeDerivative::initialSetup
virtual void initialSetup()
Definition: CoupledSwitchingTimeDerivative.C:75
CoupledSwitchingTimeDerivative::computeQpResidual
virtual Real computeQpResidual()
Definition: CoupledSwitchingTimeDerivative.C:85
CoupledSwitchingTimeDerivative::_num_j
const unsigned int _num_j
Number of phases.
Definition: CoupledSwitchingTimeDerivative.h:55
validParams< CoupledSwitchingTimeDerivative >
InputParameters validParams< CoupledSwitchingTimeDerivative >()
Definition: CoupledSwitchingTimeDerivative.C:16