https://mooseframework.inl.gov
Loading...
Searching...
No Matches
GrandPotentialInterface.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 "Conversion.h"
12#include "IndirectSort.h"
14
15#include <algorithm>
16
18
21{
24 params.addClassDescription("Calculate Grand Potential interface parameters for a specified "
25 "interfacial free energy and width");
26 params.addRequiredParam<std::vector<Real>>("sigma", "Interfacial free energies");
28 "width", "width > 0", "Interfacial width (for the interface with gamma = 1.5)");
29 params.addParam<std::vector<MaterialPropertyName>>(
30 "gamma_names",
31 "Interfacial / grain boundary gamma parameter names (leave empty for gamma0... gammaN)");
32 params.addParam<MaterialPropertyName>("kappa_name", "kappa", "Gradient interface parameter name");
33 params.addParam<MaterialPropertyName>("mu_name", "mu", "Grain growth bulk energy parameter name");
34 MooseEnum reference_sigma("max median", "max");
35 params.addParam<MooseEnum>(
36 "reference_sigma",
37 reference_sigma,
38 "Interface that is assigned gamma = 1.5 and the interfacial width 'width': the one with the "
39 "largest (max) or the median (median) interfacial free energy");
40 params.addParam<unsigned int>("sigma_index",
41 "Sigma index to choose gamma = 1.5 for. Omit this to choose it "
42 "according to reference_sigma.");
43 params.addParamNamesToGroup("mu_name reference_sigma sigma_index", "Advanced");
44 return params;
45}
46
48 : Material(parameters),
49 _sigma(getParam<std::vector<Real>>("sigma")),
50 _width(getParam<Real>("width")),
51 _n_pair(_sigma.size()),
52 _gamma(_n_pair),
53 _gamma_name(getParam<std::vector<MaterialPropertyName>>("gamma_names")),
54 _gamma_prop(_n_pair),
55 _kappa_prop(declareProperty<Real>(getParam<MaterialPropertyName>("kappa_name"))),
56 _mu_prop(declareProperty<Real>(getParam<MaterialPropertyName>("mu_name")))
57{
58 // error check parameters
59 if (_n_pair == 0)
60 paramError("sigma", "Specify at least one interfacial energy");
61
62 if (_gamma_name.size() != 0 && _gamma_name.size() != _n_pair)
63 paramError("gamma_names",
64 "Specify either as many entries are sigma values or none at all for auto-naming the "
65 "gamma material properties.");
66
67 // automatic names for the gamma properties
68 if (_gamma_name.size() == 0)
69 for (unsigned int i = 0; i < _n_pair; i++)
70 _gamma_name[i] = "gamma" + Moose::stringify(i);
71
72 // declare gamma material properties
73 for (unsigned int i = 0; i < _n_pair; i++)
74 _gamma_prop[i] = &declareProperty<Real>(_gamma_name[i]);
75
76 // determine the reference interfacial free energy (or use explicit user choice). With the
77 // largest one as reference all other interfaces have gamma < 1.5 and are wider than 'width'.
78 unsigned int reference;
79 if (isParamValid("sigma_index"))
80 reference = getParam<unsigned int>("sigma_index");
81 else if (getParam<MooseEnum>("reference_sigma") == "max")
82 reference = std::max_element(_sigma.begin(), _sigma.end()) - _sigma.begin();
83 else
84 {
85 std::vector<size_t> indices;
86 Moose::indirectSort(_sigma.begin(), _sigma.end(), indices);
87 reference = indices[(indices.size() - 1) / 2];
88 }
89
90 // set the reference gamma to 1.5 and use analytical expression for kappa and mu (m)
91 _gamma[reference] = 1.5;
92 _kappa = 3.0 / 4.0 * _sigma[reference] * _width;
93 _mu = 6.0 * _sigma[reference] / _width;
94
95 const auto fit = getParam<MooseEnum>("interface_fit").getEnum<MoelansInterfaceFits::Fit>();
96
97 // set all other gammas
98 for (unsigned int i = 0; i < _n_pair; ++i)
99 {
100 // skip the already calculated reference value
101 if (i == reference)
102 continue;
103
104 const Real g = _sigma[i] / std::sqrt(_mu * _kappa);
105 if (!MoelansInterfaceFits::inRange(g * g, fit))
106 paramError("sigma",
107 "The interfacial free energy ",
108 _sigma[i],
109 " gives g = ",
110 g,
111 ", which is outside the range 0.098 <= g <= 0.766 (0.53 <= gamma <= 40) covered "
112 "by interface_fit = moelans2022.");
113
114 // estimate for gamma from polynomial expansion
115 _gamma[i] = 1.0 / MoelansInterfaceFits::inverseGamma(g * g, fit);
116 }
117}
118
119void
121{
123 _mu_prop[_qp] = _mu;
124 for (unsigned int i = 0; i < _n_pair; ++i)
125 (*_gamma_prop[i])[_qp] = _gamma[i];
126}
registerMooseObject("PhaseFieldApp", GrandPotentialInterface)
Calculate Grand Potential interface parameters for a specified interfacial free energy and width.
std::vector< MaterialPropertyName > _gamma_name
gamma material property names
std::vector< Real > _gamma
Calculated gamma parameter values.
MaterialProperty< Real > & _kappa_prop
MaterialProperty< Real > & _mu_prop
const Real _width
Interface width for the reference interface.
const std::vector< Real > _sigma
list of interfacial free energies
std::vector< MaterialProperty< Real > * > _gamma_prop
Material properties for all interface pairs.
virtual void computeQpProperties() override
const unsigned int _n_pair
number of interface pairs
GrandPotentialInterface(const InputParameters &parameters)
static InputParameters validParams()
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
unsigned int _qp
static InputParameters validParams()
void paramError(const std::string &param, Args... args) const
bool isParamValid(const std::string &name) const
Fit
Fits selectable through the "interface_fit" parameter.
Real inverseGamma(Real g2, Fit fit)
1/gamma as a function of g^2
InputParameters validParams()
Parameters for objects using these fits.
bool inRange(Real g2, Fit fit)
Whether g^2 lies within the range the fit was made for.
std::string stringify(const T &t)
void indirectSort(RandomAccessIterator beg, RandomAccessIterator end, std::vector< size_t > &b)