https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SwitchingFunctionMultiPhaseMaterial.C
Go to the documentation of this file.
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
11#include "MooseException.h"
12
15
16template <bool is_ad>
19{
21 params.addRequiredParam<MaterialPropertyName>(
22 "h_name", "Name of the switching function material property for the given phase");
23 params.addRequiredCoupledVar("phase_etas", "Vector of order parameters for the given phase");
24 params.addRequiredCoupledVar("all_etas", "Vector of all order parameters for all phases");
25 params.addClassDescription("Calculates the switching function for a given phase for a "
26 "multi-phase, multi-order parameter model");
27 return params;
28}
29
30template <bool is_ad>
32 const InputParameters & parameters)
34 _h_name(this->getParam<MaterialPropertyName>("h_name")),
35 _num_eta_p(coupledComponents("phase_etas")),
36 _eta_p(coupledGenericValues<is_ad>("phase_etas")),
37 _eta_p_names(coupledNames("phase_etas")),
38 _num_eta(coupledComponents("all_etas")),
39 _eta(coupledGenericValues<is_ad>("all_etas")),
40 _eta_names(coupledNames("all_etas")),
41 _is_p(_num_eta),
42 _prop_h(declareGenericProperty<Real, is_ad>(_h_name)),
43 _prop_dh(_num_eta),
44 _prop_d2h(_num_eta)
45{
46 // Declare h derivative properties
47 for (unsigned int i = 0; i < _num_eta; ++i)
48 _prop_d2h[i].resize(_num_eta, NULL);
49
50 for (unsigned int i = 0; i < _num_eta; ++i)
51 {
52 _prop_dh[i] = &this->template declarePropertyDerivative<Real, is_ad>(_h_name, _eta_names[i]);
53 for (unsigned int j = i; j < _num_eta; ++j)
54 {
55 _prop_d2h[i][j] = _prop_d2h[j][i] = &this->template declarePropertyDerivative<Real, is_ad>(
57 }
58 }
59
60 // Determine which order parameters in the list of all etas belong to phase p
61 for (unsigned int i = 0; i < _num_eta; ++i)
62 {
63 _is_p[i] = false;
64 for (unsigned int j = 0; j < _num_eta_p; ++j)
65 {
66 if (_eta_names[i] == _eta_p_names[j])
67 _is_p[i] = true;
68 }
69 }
70}
71
72template <bool is_ad>
73void
75{
76 GenericReal<is_ad> sum_p = 0.0;
77 GenericReal<is_ad> sum_all = 0.0;
78
79 for (unsigned int i = 0; i < _num_eta_p; ++i)
80 sum_p += (*_eta_p[i])[_qp] * (*_eta_p[i])[_qp];
81
82 for (unsigned int i = 0; i < _num_eta; ++i)
83 sum_all += (*_eta[i])[_qp] * (*_eta[i])[_qp];
84
85 GenericReal<is_ad> sum_notp = sum_all - sum_p;
86
87 _prop_h[_qp] = sum_p / sum_all;
88
89 for (unsigned int i = 0; i < _num_eta; ++i)
90 {
91 // First derivatives
92 if (_is_p[i])
93 (*_prop_dh[i])[_qp] = 2.0 * (*_eta[i])[_qp] * sum_notp / (sum_all * sum_all);
94 else
95 (*_prop_dh[i])[_qp] = -2.0 * (*_eta[i])[_qp] * sum_p / (sum_all * sum_all);
96
97 // Second derivatives
98 for (unsigned int j = 0; j < _num_eta; ++j)
99 {
100 if (i == j)
101 {
102 if (_is_p[i])
103 (*_prop_d2h[i][j])[_qp] =
104 (2.0 * sum_all * sum_notp - 8.0 * (*_eta[i])[_qp] * (*_eta[i])[_qp] * sum_notp) /
105 (sum_all * sum_all * sum_all);
106 else
107 (*_prop_d2h[i][j])[_qp] =
108 (-2.0 * sum_p * sum_all + 8.0 * (*_eta[i])[_qp] * (*_eta[i])[_qp] * sum_p) /
109 (sum_all * sum_all * sum_all);
110 }
111 else if (_is_p[i] && _is_p[j])
112 (*_prop_d2h[i][j])[_qp] =
113 -8.0 * (*_eta[i])[_qp] * (*_eta[j])[_qp] * sum_notp / (sum_all * sum_all * sum_all);
114 else if (!_is_p[i] && !_is_p[j])
115 (*_prop_d2h[i][j])[_qp] =
116 8.0 * (*_eta[i])[_qp] * (*_eta[j])[_qp] * sum_p / (sum_all * sum_all * sum_all);
117 else
118 (*_prop_d2h[i][j])[_qp] = (4.0 * sum_all - 8.0 * sum_notp) * (*_eta[i])[_qp] *
119 (*_eta[j])[_qp] / (sum_all * sum_all * sum_all);
120 }
121 }
122}
123
124// explicit instantiation
Moose::GenericType< Real, is_ad > GenericReal
registerMooseObject("PhaseFieldApp", SwitchingFunctionMultiPhaseMaterial)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
static InputParameters validParams()
SwitchingFunctionMultiPhaseMaterial is a switching function for a multi-phase, multi-order parameter ...
MaterialPropertyName _h_name
Name of the function.
const unsigned int _num_eta
Order parameters for all phases (including alpha)
const unsigned int _num_eta_p
Order parameters for phase alpha.
std::vector< std::vector< GenericMaterialProperty< Real, is_ad > * > > _prop_d2h
std::vector< GenericMaterialProperty< Real, is_ad > * > _prop_dh
std::vector< bool > _is_p
List of which order parameters in the full list of all etas belong to phase p.
SwitchingFunctionMultiPhaseMaterialTempl(const InputParameters &parameters)