www.mooseframework.org
SwitchingFunctionMultiPhaseMaterial.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<Material>();
19  params.addRequiredParam<MaterialPropertyName>(
20  "h_name", "Name of the switching function material property for the given phase");
21  params.addRequiredCoupledVar("phase_etas", "Vector of order parameters for the given phase");
22  params.addRequiredCoupledVar("all_etas", "Vector of all order parameters for all phases");
23  params.addClassDescription("Calculates the switching function for a given phase for a "
24  "multi-phase, multi-order parameter model");
25  return params;
26 }
27 
29  const InputParameters & parameters)
30  : DerivativeMaterialInterface<Material>(parameters),
31  _h_name(getParam<MaterialPropertyName>("h_name")),
32  _num_eta_p(coupledComponents("phase_etas")),
33  _eta_p(_num_eta_p),
34  _eta_p_names(_num_eta_p),
35  _num_eta(coupledComponents("all_etas")),
36  _eta(_num_eta),
37  _eta_names(_num_eta),
38  _is_p(_num_eta),
39  _prop_h(declareProperty<Real>(_h_name)),
40  _prop_dh(_num_eta),
41  _prop_d2h(_num_eta)
42 {
43  // Fetch eta values and names for phase etas
44  for (unsigned int i = 0; i < _num_eta_p; ++i)
45  {
46  _eta_p[i] = &coupledValue("phase_etas", i);
47  _eta_p_names[i] = getVar("phase_etas", i)->name();
48  }
49 
50  // Declare h derivative properties, fetch eta values for all eta
51  for (unsigned int i = 0; i < _num_eta; ++i)
52  {
53  _prop_d2h[i].resize(_num_eta);
54  _eta_names[i] = getVar("all_etas", i)->name();
55  }
56 
57  for (unsigned int i = 0; i < _num_eta; ++i)
58  {
59  _prop_dh[i] = &declarePropertyDerivative<Real>(_h_name, _eta_names[i]);
60  _eta[i] = &coupledValue("all_etas", i);
61  for (unsigned int j = i; j < _num_eta; ++j)
62  {
63  _prop_d2h[i][j] = _prop_d2h[j][i] =
64  &declarePropertyDerivative<Real>(_h_name, _eta_names[i], _eta_names[j]);
65  }
66  }
67 
68  // Determine which order parameters in the list of all etas belong to phase p
69  for (unsigned int i = 0; i < _num_eta; ++i)
70  {
71  _is_p[i] = false;
72  for (unsigned int j = 0; j < _num_eta_p; ++j)
73  {
74  if (_eta_names[i] == _eta_p_names[j])
75  _is_p[i] = true;
76  }
77  }
78 }
79 
80 void
82 {
83  Real sum_p = 0.0;
84  Real sum_all = 0.0;
85 
86  for (unsigned int i = 0; i < _num_eta_p; ++i)
87  sum_p += (*_eta_p[i])[_qp] * (*_eta_p[i])[_qp];
88 
89  for (unsigned int i = 0; i < _num_eta; ++i)
90  sum_all += (*_eta[i])[_qp] * (*_eta[i])[_qp];
91 
92  Real sum_notp = sum_all - sum_p;
93 
94  _prop_h[_qp] = sum_p / sum_all;
95 
96  for (unsigned int i = 0; i < _num_eta; ++i)
97  {
98  // First derivatives
99  if (_is_p[i])
100  (*_prop_dh[i])[_qp] = 2.0 * (*_eta[i])[_qp] * sum_notp / (sum_all * sum_all);
101  else
102  (*_prop_dh[i])[_qp] = -2.0 * (*_eta[i])[_qp] * sum_p / (sum_all * sum_all);
103 
104  // Second derivatives
105  for (unsigned int j = 0; j < _num_eta; ++j)
106  {
107  if (i == j)
108  {
109  if (_is_p[i])
110  (*_prop_d2h[i][j])[_qp] =
111  (2.0 * sum_all * sum_notp - 8.0 * (*_eta[i])[_qp] * (*_eta[i])[_qp] * sum_notp) /
112  (sum_all * sum_all * sum_all);
113  else
114  (*_prop_d2h[i][j])[_qp] =
115  (-2.0 * sum_p * sum_all + 8.0 * (*_eta[i])[_qp] * (*_eta[i])[_qp] * sum_p) /
116  (sum_all * sum_all * sum_all);
117  }
118  else if (_is_p[i] && _is_p[j])
119  (*_prop_d2h[i][j])[_qp] =
120  -8.0 * (*_eta[i])[_qp] * (*_eta[j])[_qp] * sum_notp / (sum_all * sum_all * sum_all);
121  else if (!_is_p[i] && !_is_p[j])
122  (*_prop_d2h[i][j])[_qp] =
123  8.0 * (*_eta[i])[_qp] * (*_eta[j])[_qp] * sum_p / (sum_all * sum_all * sum_all);
124  else
125  (*_prop_d2h[i][j])[_qp] = (4.0 * sum_all - 8.0 * sum_notp) * (*_eta[i])[_qp] *
126  (*_eta[j])[_qp] / (sum_all * sum_all * sum_all);
127  }
128  }
129 }
SwitchingFunctionMultiPhaseMaterial::_prop_d2h
std::vector< std::vector< MaterialProperty< Real > * > > _prop_d2h
Definition: SwitchingFunctionMultiPhaseMaterial.h:55
SwitchingFunctionMultiPhaseMaterial::_eta_p_names
std::vector< VariableName > _eta_p_names
Definition: SwitchingFunctionMultiPhaseMaterial.h:42
SwitchingFunctionMultiPhaseMaterial::_num_eta
unsigned int _num_eta
Order parameters for all phases (including alpha)
Definition: SwitchingFunctionMultiPhaseMaterial.h:45
SwitchingFunctionMultiPhaseMaterial::_h_name
MaterialPropertyName _h_name
Name of the function.
Definition: SwitchingFunctionMultiPhaseMaterial.h:37
SwitchingFunctionMultiPhaseMaterial::_eta_p
std::vector< const VariableValue * > _eta_p
Definition: SwitchingFunctionMultiPhaseMaterial.h:41
SwitchingFunctionMultiPhaseMaterial::_eta_names
std::vector< VariableName > _eta_names
Definition: SwitchingFunctionMultiPhaseMaterial.h:47
SwitchingFunctionMultiPhaseMaterial
SwitchingFunctionMultiPhaseMaterial is a switching function for a multi-phase, multi-order parameter ...
Definition: SwitchingFunctionMultiPhaseMaterial.h:28
registerMooseObject
registerMooseObject("PhaseFieldApp", SwitchingFunctionMultiPhaseMaterial)
SwitchingFunctionMultiPhaseMaterial::_prop_h
MaterialProperty< Real > & _prop_h
Switching function and derivatives.
Definition: SwitchingFunctionMultiPhaseMaterial.h:53
validParams< SwitchingFunctionMultiPhaseMaterial >
InputParameters validParams< SwitchingFunctionMultiPhaseMaterial >()
Definition: SwitchingFunctionMultiPhaseMaterial.C:16
SwitchingFunctionMultiPhaseMaterial::_is_p
std::vector< bool > _is_p
List of which order parameters in the full list of all etas belong to phase p.
Definition: SwitchingFunctionMultiPhaseMaterial.h:50
SwitchingFunctionMultiPhaseMaterial::computeQpProperties
virtual void computeQpProperties()
Definition: SwitchingFunctionMultiPhaseMaterial.C:81
SwitchingFunctionMultiPhaseMaterial::_prop_dh
std::vector< MaterialProperty< Real > * > _prop_dh
Definition: SwitchingFunctionMultiPhaseMaterial.h:54
SwitchingFunctionMultiPhaseMaterial::_eta
std::vector< const VariableValue * > _eta
Definition: SwitchingFunctionMultiPhaseMaterial.h:46
SwitchingFunctionMultiPhaseMaterial::SwitchingFunctionMultiPhaseMaterial
SwitchingFunctionMultiPhaseMaterial(const InputParameters &parameters)
Definition: SwitchingFunctionMultiPhaseMaterial.C:28
SwitchingFunctionMultiPhaseMaterial.h
SwitchingFunctionMultiPhaseMaterial::_num_eta_p
unsigned int _num_eta_p
Order parameters for phase alpha.
Definition: SwitchingFunctionMultiPhaseMaterial.h:40