Line data Source code
1 : //* This file is part of the MOOSE framework
2 : //* https://mooseframework.inl.gov
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 "DerivativeTwoPhaseMaterial.h"
11 :
12 : registerMooseObject("PhaseFieldApp", DerivativeTwoPhaseMaterial);
13 :
14 : InputParameters
15 141 : DerivativeTwoPhaseMaterial::validParams()
16 : {
17 141 : InputParameters params = DerivativeFunctionMaterialBase::validParams();
18 141 : params.addClassDescription(
19 : "Two phase material that combines two single phase materials using a switching function.");
20 :
21 : // Two base materials
22 282 : params.addRequiredParam<MaterialPropertyName>("fa_name", "Phase A material (at eta=0)");
23 282 : params.addRequiredParam<MaterialPropertyName>("fb_name", "Phase A material (at eta=1)");
24 282 : params.addParam<MaterialPropertyName>(
25 : "h", "h", "Switching Function Material that provides h(eta)");
26 282 : params.addParam<MaterialPropertyName>("g", "g", "Barrier Function Material that provides g(eta)");
27 :
28 : // All arguments of the phase free energies
29 282 : params.addCoupledVar("args", "Vector of variable arguments of fa and fb");
30 282 : params.deprecateCoupledVar("args", "coupled_variables", "02/27/2024");
31 282 : params.addCoupledVar("displacement_gradients",
32 : "Vector of displacement gradient variables (see "
33 : "Modules/PhaseField/DisplacementGradients "
34 : "action)");
35 :
36 : // Order parameter which determines the phase
37 282 : params.addRequiredCoupledVar("eta", "Order parameter");
38 :
39 : // Variables with applied tolerances and their tolerance values
40 282 : params.addParam<Real>("W", 0.0, "Energy barrier for the phase transformation from A to B");
41 :
42 141 : return params;
43 0 : }
44 :
45 108 : DerivativeTwoPhaseMaterial::DerivativeTwoPhaseMaterial(const InputParameters & parameters)
46 : : DerivativeFunctionMaterialBase(parameters),
47 108 : _eta(coupledValue("eta")),
48 108 : _eta_name(coupledName("eta", 0)),
49 108 : _eta_var(coupled("eta")),
50 216 : _h(getMaterialProperty<Real>("h")),
51 108 : _dh(getMaterialPropertyDerivative<Real>("h", _eta_name)),
52 108 : _d2h(getMaterialPropertyDerivative<Real>("h", _eta_name, _eta_name)),
53 108 : _d3h(getMaterialPropertyDerivative<Real>("h", _eta_name, _eta_name, _eta_name)),
54 216 : _g(getMaterialProperty<Real>("g")),
55 108 : _dg(getMaterialPropertyDerivative<Real>("g", _eta_name)),
56 108 : _d2g(getMaterialPropertyDerivative<Real>("g", _eta_name, _eta_name)),
57 108 : _d3g(getMaterialPropertyDerivative<Real>("g", _eta_name, _eta_name, _eta_name)),
58 216 : _W(getParam<Real>("W")),
59 216 : _prop_Fa(getMaterialProperty<Real>("fa_name")),
60 324 : _prop_Fb(getMaterialProperty<Real>("fb_name"))
61 : {
62 : // reserve space for phase A and B material properties
63 108 : _prop_dFa.resize(_nargs);
64 108 : _prop_d2Fa.resize(_nargs);
65 108 : _prop_d3Fa.resize(_nargs);
66 108 : _prop_dFb.resize(_nargs);
67 108 : _prop_d2Fb.resize(_nargs);
68 108 : _prop_d3Fb.resize(_nargs);
69 288 : for (unsigned int i = 0; i < _nargs; ++i)
70 : {
71 180 : _prop_dFa[i] = &getMaterialPropertyDerivative<Real>("fa_name", _arg_names[i]);
72 180 : _prop_dFb[i] = &getMaterialPropertyDerivative<Real>("fb_name", _arg_names[i]);
73 :
74 180 : _prop_d2Fa[i].resize(_nargs);
75 180 : _prop_d2Fb[i].resize(_nargs);
76 :
77 : // TODO: maybe we should reserve and initialize to NULL...
78 180 : if (_third_derivatives)
79 : {
80 0 : _prop_d3Fa[i].resize(_nargs);
81 0 : _prop_d3Fb[i].resize(_nargs);
82 : }
83 :
84 504 : for (unsigned int j = 0; j < _nargs; ++j)
85 : {
86 324 : _prop_d2Fa[i][j] =
87 648 : &getMaterialPropertyDerivative<Real>("fa_name", _arg_names[i], _arg_names[j]);
88 324 : _prop_d2Fb[i][j] =
89 648 : &getMaterialPropertyDerivative<Real>("fb_name", _arg_names[i], _arg_names[j]);
90 :
91 324 : if (_third_derivatives)
92 : {
93 0 : _prop_d3Fa[i][j].resize(_nargs);
94 0 : _prop_d3Fb[i][j].resize(_nargs);
95 :
96 0 : for (unsigned int k = 0; k < _nargs; ++k)
97 : {
98 0 : _prop_d3Fa[i][j][k] = &getMaterialPropertyDerivative<Real>(
99 0 : "fa_name", _arg_names[i], _arg_names[j], _arg_names[k]);
100 0 : _prop_d3Fb[i][j][k] = &getMaterialPropertyDerivative<Real>(
101 : "fb_name", _arg_names[i], _arg_names[j], _arg_names[k]);
102 : }
103 : }
104 : }
105 : }
106 108 : }
107 :
108 : void
109 108 : DerivativeTwoPhaseMaterial::initialSetup()
110 : {
111 324 : validateCoupling<Real>("fa_name");
112 216 : validateCoupling<Real>("fb_name");
113 108 : }
114 :
115 : Real
116 1346592 : DerivativeTwoPhaseMaterial::computeF()
117 : {
118 1346592 : return _h[_qp] * _prop_Fb[_qp] + (1.0 - _h[_qp]) * _prop_Fa[_qp] + _W * _g[_qp];
119 : }
120 :
121 : Real
122 1691584 : DerivativeTwoPhaseMaterial::computeDF(unsigned int i_var)
123 : {
124 1691584 : if (i_var == _eta_var)
125 1346592 : return _dh[_qp] * (_prop_Fb[_qp] - _prop_Fa[_qp]) + _W * _dg[_qp];
126 : else
127 : {
128 : unsigned int i = argIndex(i_var);
129 344992 : return _h[_qp] * (*_prop_dFb[i])[_qp] + (1.0 - _h[_qp]) * (*_prop_dFa[i])[_qp];
130 : }
131 : }
132 :
133 : Real
134 2036576 : DerivativeTwoPhaseMaterial::computeD2F(unsigned int i_var, unsigned int j_var)
135 : {
136 2036576 : if (i_var == _eta_var && j_var == _eta_var)
137 1346592 : return _d2h[_qp] * (_prop_Fb[_qp] - _prop_Fa[_qp]) + _W * _d2g[_qp];
138 :
139 : unsigned int i = argIndex(i_var);
140 : unsigned int j = argIndex(j_var);
141 :
142 689984 : if (i_var == _eta_var)
143 0 : return _dh[_qp] * ((*_prop_dFb[j])[_qp] - (*_prop_dFa[j])[_qp]);
144 689984 : if (j_var == _eta_var)
145 344992 : return _dh[_qp] * ((*_prop_dFb[i])[_qp] - (*_prop_dFa[i])[_qp]);
146 :
147 344992 : return _h[_qp] * (*_prop_d2Fb[i][j])[_qp] + (1.0 - _h[_qp]) * (*_prop_d2Fa[i][j])[_qp];
148 : }
149 :
150 : Real
151 0 : DerivativeTwoPhaseMaterial::computeD3F(unsigned int i_var, unsigned int j_var, unsigned int k_var)
152 : {
153 0 : if (i_var == _eta_var && j_var == _eta_var && k_var == _eta_var)
154 0 : return _d3h[_qp] * (_prop_Fb[_qp] - _prop_Fa[_qp]) + _W * _d3g[_qp];
155 :
156 : unsigned int i = argIndex(i_var);
157 : unsigned int j = argIndex(j_var);
158 : unsigned int k = argIndex(k_var);
159 :
160 0 : if (j_var == _eta_var && k_var == _eta_var)
161 0 : return _d2h[_qp] * ((*_prop_dFb[i])[_qp] - (*_prop_dFa[i])[_qp]);
162 0 : if (i_var == _eta_var && k_var == _eta_var)
163 0 : return _d2h[_qp] * ((*_prop_dFb[j])[_qp] - (*_prop_dFa[j])[_qp]);
164 0 : if (i_var == _eta_var && j_var == _eta_var)
165 0 : return _d2h[_qp] * ((*_prop_dFb[k])[_qp] - (*_prop_dFa[k])[_qp]);
166 :
167 0 : if (i_var == _eta_var)
168 0 : return _dh[_qp] * (*_prop_d2Fb[j][k])[_qp] + (1.0 - _dh[_qp]) * (*_prop_d2Fa[j][k])[_qp];
169 0 : if (j_var == _eta_var)
170 0 : return _dh[_qp] * (*_prop_d2Fb[i][k])[_qp] + (1.0 - _dh[_qp]) * (*_prop_d2Fa[i][k])[_qp];
171 0 : if (k_var == _eta_var)
172 0 : return _dh[_qp] * (*_prop_d2Fb[i][j])[_qp] + (1.0 - _dh[_qp]) * (*_prop_d2Fa[i][j])[_qp];
173 :
174 0 : return _h[_qp] * (*_prop_d3Fb[i][j][k])[_qp] + (1.0 - _h[_qp]) * (*_prop_d3Fa[i][j][k])[_qp];
175 : }
|