https://mooseframework.inl.gov
Loading...
Searching...
No Matches
GBAnisotropyBase.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
10#include "GBAnisotropyBase.h"
11#include "MooseMesh.h"
12
13#include <fstream>
14
17{
20 params.addCoupledVar("T", 300.0, "Temperature in Kelvin");
21 params.addParam<Real>("length_scale", 1.0e-9, "Length scale in m, where default is nm");
22 params.addParam<Real>("time_scale", 1.0e-9, "Time scale in s, where default is ns");
23 params.addParam<Real>("molar_volume_value",
24 7.11e-6,
25 "molar volume of material in m^3/mol, by default it's the value of copper");
26 params.addParam<Real>(
27 "delta_sigma", 0.1, "factor determining inclination dependence of GB energy");
28 params.addParam<Real>(
29 "delta_mob", 0.1, "factor determining inclination dependence of GB mobility");
30 params.addRequiredParam<FileName>("Anisotropic_GB_file_name",
31 "Name of the file containing: 1)GB mobility prefactor; 2) GB "
32 "migration activation energy; 3)GB energy");
33 params.addRequiredParam<bool>("inclination_anisotropy",
34 "The GB anisotropy inclination would be considered if true");
36 "v", "var_name_base", "op_num", "Array of coupled variables");
37 return params;
38}
39
41 : Material(parameters),
42 _mesh_dimension(_mesh.dimension()),
43 _length_scale(getParam<Real>("length_scale")),
44 _time_scale(getParam<Real>("time_scale")),
45 _M_V(getParam<Real>("molar_volume_value")),
46 _delta_sigma(getParam<Real>("delta_sigma")),
47 _delta_mob(getParam<Real>("delta_mob")),
48 _Anisotropic_GB_file_name(getParam<FileName>("Anisotropic_GB_file_name")),
49 _inclination_anisotropy(getParam<bool>("inclination_anisotropy")),
50 _interface_fit(getParam<MooseEnum>("interface_fit").getEnum<MoelansInterfaceFits::Fit>()),
51 _T(coupledValue("T")),
52 _kappa(declareProperty<Real>("kappa_op")),
53 _gamma(declareProperty<Real>("gamma_asymm")),
54 _L(declareProperty<Real>("L")),
55 _mu(declareProperty<Real>("mu")),
56 _molar_volume(declareProperty<Real>("molar_volume")),
57 _entropy_diff(declareProperty<Real>("entropy_diff")),
58 _act_wGB(declareProperty<Real>("act_wGB")),
59 _kb(8.617343e-5), // Boltzmann constant in eV/K
60 _JtoeV(6.24150974e18), // Joule to eV conversion
61 _mu_qp(0.0),
62 _op_num(coupledComponents("v")),
63 _vals(coupledValues("v")),
64 _grad_vals(coupledGradients("v"))
65{
66 // reshape vectors
67 _sigma.resize(_op_num);
68 _mob.resize(_op_num);
69 _Q.resize(_op_num);
70 _kappa_gamma.resize(_op_num);
71 _a_g2.resize(_op_num);
72
73 for (unsigned int op = 0; op < _op_num; ++op)
74 {
75 _sigma[op].resize(_op_num);
76 _mob[op].resize(_op_num);
77 _Q[op].resize(_op_num);
78 _kappa_gamma[op].resize(_op_num);
79 _a_g2[op].resize(_op_num);
80 }
81
82 // Read in data from "Anisotropic_GB_file_name"
83 std::ifstream inFile(_Anisotropic_GB_file_name.c_str());
84
85 if (!inFile)
86 paramError("Anisotropic_GB_file_name", "Can't open GB anisotropy input file");
87
88 for (unsigned int i = 0; i < 2; ++i)
89 inFile.ignore(255, '\n'); // ignore line
90
91 Real data;
92 for (unsigned int i = 0; i < 3 * _op_num; ++i)
93 {
94 std::vector<Real> row; // create an empty row of double values
95 for (unsigned int j = 0; j < _op_num; ++j)
96 {
97 inFile >> data;
98 row.push_back(data);
99 }
100
101 if (i < _op_num)
102 _sigma[i] = row; // unit: J/m^2
103
104 else if (i < 2 * _op_num)
105 _mob[i - _op_num] = row; // unit: m^4/(J*s)
106
107 else
108 _Q[i - 2 * _op_num] = row; // unit: eV
109 }
110
111 inFile.close();
112}
113
114void
116{
117 Real sum_kappa = 0.0;
118 Real sum_gamma = 0.0;
119 Real sum_L = 0.0;
120 Real Val = 0.0;
121 Real sum_val = 0.0;
122 Real f_sigma = 1.0;
123 Real f_mob = 1.0;
124 Real gamma_value = 0.0;
125
126 for (unsigned int m = 0; m < _op_num - 1; ++m)
127 {
128 for (unsigned int n = m + 1; n < _op_num; ++n) // m<n
129 {
130 gamma_value = _kappa_gamma[n][m];
131
133 {
134 if (_mesh_dimension == 3)
135 mooseError("This material doesn't support inclination dependence for 3D for now!");
136
137 Real phi_ave = libMesh::pi * n / (2.0 * _op_num);
138 Real sin_phi = std::sin(2.0 * phi_ave);
139 Real cos_phi = std::cos(2.0 * phi_ave);
140
141 Real a = (*_grad_vals[m])[_qp](0) - (*_grad_vals[n])[_qp](0);
142 Real b = (*_grad_vals[m])[_qp](1) - (*_grad_vals[n])[_qp](1);
143 Real ab = a * a + b * b + 1.0e-7; // for the sake of numerical convergence, the smaller the
144 // more accurate, but more difficult to converge
145
146 Real cos_2phi = cos_phi * (a * a - b * b) / ab + sin_phi * 2.0 * a * b / ab;
147 Real cos_4phi = 2.0 * cos_2phi * cos_2phi - 1.0;
148
149 f_sigma = 1.0 + _delta_sigma * cos_4phi;
150 f_mob = 1.0 + _delta_mob * cos_4phi;
151
152 Real g2 = _a_g2[n][m] * f_sigma;
153 checkFitRange(g2);
154 gamma_value = 1.0 / MoelansInterfaceFits::inverseGamma(g2, _interface_fit);
155 }
156
157 Val = (100000.0 * ((*_vals[m])[_qp]) * ((*_vals[m])[_qp]) + 0.01) *
158 (100000.0 * ((*_vals[n])[_qp]) * ((*_vals[n])[_qp]) + 0.01);
159
160 sum_val += Val;
161 sum_kappa += _kappa_gamma[m][n] * f_sigma * Val;
162 sum_gamma += gamma_value * Val;
163 // Following comes from substituting Eq. (36c) from the paper into (36b)
164 sum_L += Val * _mob[m][n] * std::exp(-_Q[m][n] / (_kb * _T[_qp])) * f_mob * _mu_qp *
165 _a_g2[n][m] / _sigma[m][n];
166 }
167 }
168
169 _kappa[_qp] = sum_kappa / sum_val;
170 _gamma[_qp] = sum_gamma / sum_val;
171 _L[_qp] = sum_L / sum_val;
172 _mu[_qp] = _mu_qp;
173
175 _M_V / (_length_scale * _length_scale * _length_scale); // m^3/mol converted to ls^3/mol
176 _entropy_diff[_qp] = 9.5 * _JtoeV; // J/(K mol) converted to eV(K mol)
177 _act_wGB[_qp] = 0.5e-9 / _length_scale; // 0.5 nm
178}
179
180void
182{
184 mooseError("The grain boundary energies give g = ",
185 std::sqrt(g2),
186 ", which is outside the range 0.098 <= g <= 0.766 (0.53 <= gamma <= 40) covered by "
187 "interface_fit = moelans2022.");
188}
MaterialProperty< Real > & _act_wGB
const unsigned int _mesh_dimension
const FileName _Anisotropic_GB_file_name
void checkFitRange(Real g2) const
Error if g^2 lies outside the range covered by the selected interface fit.
virtual void computeQpProperties()
const std::vector< const VariableGradient * > _grad_vals
MaterialProperty< Real > & _gamma
std::vector< std::vector< Real > > _a_g2
MaterialProperty< Real > & _molar_volume
const VariableValue & _T
const MoelansInterfaceFits::Fit _interface_fit
Polynomial fits used to compute gamma and the diffuse interface width.
std::vector< std::vector< Real > > _Q
GBAnisotropyBase(const InputParameters &parameters)
MaterialProperty< Real > & _entropy_diff
std::vector< std::vector< Real > > _sigma
MaterialProperty< Real > & _mu
const Real _length_scale
const unsigned int _op_num
const Real _delta_sigma
static InputParameters validParams()
std::vector< std::vector< Real > > _mob
const std::vector< const VariableValue * > _vals
MaterialProperty< Real > & _kappa
MaterialProperty< Real > & _L
const bool _inclination_anisotropy
std::vector< std::vector< Real > > _kappa_gamma
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 addCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredCoupledVarWithAutoBuild(const std::string &name, const std::string &base_name, const std::string &num_name, const std::string &doc_string)
unsigned int _qp
static InputParameters validParams()
void paramError(const std::string &param, Args... args) const
void mooseError(Args &&... args) const
Polynomial fits for the interface relations of the multi-order-parameter model of Moelans et al....
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.
const Real pi