www.mooseframework.org
ACSwitching.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 "ACSwitching.h"
11 
12 registerMooseObject("PhaseFieldApp", ACSwitching);
13 
14 template <>
15 InputParameters
17 {
18  InputParameters params = ACBulk<Real>::validParams();
19  params.addClassDescription(
20  "Kernel for Allen-Cahn equation that adds derivatives of switching functions and energies");
21  params.addRequiredParam<std::vector<MaterialPropertyName>>(
22  "Fj_names", "List of free energies for each phase. Place in same order as hj_names!");
23  params.addRequiredParam<std::vector<MaterialPropertyName>>(
24  "hj_names", "Switching Function Materials that provide h. Place in same order as Fj_names!");
25  return params;
26 }
27 
28 ACSwitching::ACSwitching(const InputParameters & parameters)
29  : ACBulk<Real>(parameters),
30  _nvar(_coupled_moose_vars.size()),
31  _etai_name(_var.name()),
32  _Fj_names(getParam<std::vector<MaterialPropertyName>>("Fj_names")),
33  _num_j(_Fj_names.size()),
34  _prop_Fj(_num_j),
35  _prop_dFjdarg(_num_j),
36  _hj_names(getParam<std::vector<MaterialPropertyName>>("hj_names")),
37  _prop_dhjdetai(_num_j),
38  _prop_d2hjdetai2(_num_j),
39  _prop_d2hjdetaidarg(_num_j)
40 {
41  // check passed in parameter vectors
42  if (_num_j != _hj_names.size())
43  paramError("hj_names", "Need to pass in as many hj_names as Fj_names");
44 
45  // reserve space and set phase material properties
46  for (unsigned int n = 0; n < _num_j; ++n)
47  {
48  // get phase free energy
49  _prop_Fj[n] = &getMaterialPropertyByName<Real>(_Fj_names[n]);
50  _prop_dFjdarg[n].resize(_nvar);
51 
52  // get switching derivatives wrt eta_i, the nonlinear variable
53  _prop_dhjdetai[n] = &getMaterialPropertyDerivative<Real>(_hj_names[n], _etai_name);
54  _prop_d2hjdetai2[n] =
55  &getMaterialPropertyDerivative<Real>(_hj_names[n], _etai_name, _etai_name);
56  _prop_d2hjdetaidarg[n].resize(_nvar);
57 
58  for (unsigned int i = 0; i < _nvar; ++i)
59  {
60  MooseVariableFEBase * cvar = _coupled_moose_vars[i];
61  // Get derivatives of all Fj wrt all coupled variables
62  _prop_dFjdarg[n][i] = &getMaterialPropertyDerivative<Real>(_Fj_names[n], cvar->name());
63 
64  // Get second derivatives of all hj wrt eta_i and all coupled variables
65  _prop_d2hjdetaidarg[n][i] =
66  &getMaterialPropertyDerivative<Real>(_hj_names[n], _etai_name, cvar->name());
67  }
68  }
69 }
70 
71 void
72 ACSwitching::initialSetup()
73 {
75 
76  for (unsigned int n = 0; n < _num_j; ++n)
77  {
78  validateNonlinearCoupling<Real>(_Fj_names[n]);
79  validateNonlinearCoupling<Real>(_hj_names[n]);
80  }
81 }
82 
83 Real
84 ACSwitching::computeDFDOP(PFFunctionType type)
85 {
86  Real sum = 0.0;
87 
88  switch (type)
89  {
90  case Residual:
91  for (unsigned int n = 0; n < _num_j; ++n)
92  sum += (*_prop_dhjdetai[n])[_qp] * (*_prop_Fj[n])[_qp];
93 
94  return sum;
95 
96  case Jacobian:
97  for (unsigned int n = 0; n < _num_j; ++n)
98  sum += (*_prop_d2hjdetai2[n])[_qp] * (*_prop_Fj[n])[_qp];
99 
100  return _phi[_j][_qp] * sum;
101  }
102 
103  mooseError("Invalid type passed in to ACSwitching::computeDFDOP");
104 }
105 
106 Real
107 ACSwitching::computeQpOffDiagJacobian(unsigned int jvar)
108 {
109  // get the coupled variable jvar is referring to
110  const unsigned int cvar = mapJvarToCvar(jvar);
111 
112  // first get dependence of mobility _L on other variables using parent class
113  // member function
115 
116  // Then add dependence of ACSwitching on other variables
117  Real sum = 0.0;
118  for (unsigned int n = 0; n < _num_j; ++n)
119  sum += (*_prop_d2hjdetaidarg[n][cvar])[_qp] * (*_prop_Fj[n])[_qp] +
120  (*_prop_dhjdetai[n])[_qp] * (*_prop_dFjdarg[n][cvar])[_qp];
121 
122  res += _L[_qp] * sum * _phi[_j][_qp] * _test[_i][_qp];
123 
124  return res;
125 }
ACBulk::computeQpOffDiagJacobian
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
Definition: ACBulk.h:116
ACBulk
This is the Allen-Cahn equation base class that implements the bulk or local energy term of the equat...
Definition: ACBulk.h:24
ACSwitching.h
validParams< ACSwitching >
InputParameters validParams< ACSwitching >()
Definition: ACSwitching.C:16
name
const std::string name
Definition: Setup.h:21
ACBulk::initialSetup
virtual void initialSetup()
Definition: ACBulk.h:85
registerMooseObject
registerMooseObject("PhaseFieldApp", ACSwitching)
ACBulk::validParams
static InputParameters validParams()
Definition: ACBulk.h:74