https://mooseframework.inl.gov
PolycrystalDiffusivity.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 "PolycrystalDiffusivity.h"
11 
13 
16 {
18  params.addClassDescription(
19  "Generates a diffusion coefficient to distinguish between the bulk, pore, grain "
20  "boundaries, and surfaces");
22  "v", "var_name_base", "op_num", "Array of coupled variables");
23  params.addParam<Real>("Dbulk", 1.0, "Diffusion coefficient for volumetric diffusion in solid");
24  params.addParam<Real>(
25  "Dvoid", 1.0, "Diffusion coefficient for diffusion within void/pore/bubble ");
26  params.addParam<Real>("Dsurf", 1.0, "Diffusion coefficient for surface diffusion");
27  params.addParam<Real>("Dgb", 1.0, "Diffusion coefficient for grain boundary diffusion");
28  params.addRequiredCoupledVar("c", "Vacancy phase variable");
29  params.addParam<Real>("surf_weight", 1.0, "Surface diffusion weight");
30  params.addParam<Real>("gb_weight", 1.0, "Grain boundary diffusion weight");
31  params.addParam<Real>("bulk_weight", 1.0, "Bulk diffusion weight");
32  params.addParam<Real>("void_weight", 1.0, "Void diffusion weight");
33  params.addParam<MaterialPropertyName>(
34  "void_switch", "hb", "Switching Function Materials for the void");
35  params.addParam<MaterialPropertyName>(
36  "solid_switch", "hm", "Switching Function Materials for the solid");
37  params.addParam<MaterialPropertyName>("diffusivity", "D", "The name of the diffusion property");
38  return params;
39 }
40 
43  _c(coupledValue("c")),
44  _c_name(coupledName("c", 0)),
45  _op_num(coupledComponents("v")),
46  _vals(_op_num),
47  _diff_name(getParam<MaterialPropertyName>("diffusivity")),
48  _diff(declareProperty<Real>(_diff_name)),
49  _dDdc(isCoupledConstant(_c_name) ? nullptr
50  : &declarePropertyDerivative<Real>(_diff_name, _c_name)),
51  _hb(getMaterialProperty<Real>("void_switch")),
52  _hm(getMaterialProperty<Real>("solid_switch")),
53  _dhbdc(getMaterialPropertyDerivative<Real>("void_switch", _c_name)),
54  _dhmdc(getMaterialPropertyDerivative<Real>("solid_switch", _c_name)),
55  _dhbdv(_op_num),
56  _dhmdv(_op_num),
57  _diff_bulk(getParam<Real>("Dbulk")),
58  _diff_void(getParam<Real>("Dvoid")),
59  _diff_surf(getParam<Real>("Dsurf")),
60  _diff_gb(getParam<Real>("Dgb")),
61  _s_weight(getParam<Real>("surf_weight")),
62  _gb_weight(getParam<Real>("gb_weight")),
63  _b_weight(getParam<Real>("bulk_weight")),
64  _v_weight(getParam<Real>("void_weight"))
65 {
66  if (_op_num == 0)
67  paramError("op_num", "Model requires a non zero number of order parameters.");
68 
69  _dDdv.resize(_op_num);
70  for (MooseIndex(_op_num) op_index = 0; op_index < _op_num; ++op_index)
71  {
72  _vals[op_index] = &coupledValue("v", op_index);
73  const VariableName op_name = coupledName("v", op_index);
74  if (!isCoupledConstant("v"))
75  _dDdv[op_index] = &declarePropertyDerivative<Real>(_diff_name, coupledName("v", op_index));
76  _dhbdv[op_index] = &getMaterialPropertyDerivative<Real>("void_switch", op_index);
77  _dhmdv[op_index] = &getMaterialPropertyDerivative<Real>("solid_switch", op_index);
78  }
79 }
80 
81 void
83 {
84  Real SumEtaij = 0.0;
85  Real SumEtaj = 0.0;
86  for (const auto i : make_range(_op_num))
87  for (const auto j : make_range(i + 1, _op_num))
88  {
89  SumEtaij += 18.0 * (*_vals[i])[_qp] * (*_vals[i])[_qp] * (*_vals[j])[_qp] * (*_vals[j])[_qp];
90  SumEtaj += 18.0 * ((*_vals[i])[_qp] * (*_vals[j])[_qp] * (*_vals[j])[_qp] +
91  (*_vals[j])[_qp] * (*_vals[i])[_qp] * (*_vals[i])[_qp]);
92  }
93  Real c = _c[_qp];
94  c = std::abs(c) > 1.0 ? 1.0 : (c < 0.0 ? std::abs(c) : c);
95  const Real mc = 1.0 - c;
96 
97  // Compute diffusion function
99  30.0 * _diff_surf * _s_weight * c * c * mc * mc + _diff_gb * SumEtaij * _gb_weight;
100 
101  if (_dDdc)
102  (*_dDdc)[_qp] = _b_weight * _diff_bulk * _dhmdc[_qp] + _v_weight * _diff_void * _dhbdc[_qp] +
103  30.0 * _diff_surf * _s_weight * (2.0 * c * mc * mc - 2.0 * c * c * mc);
104  for (const auto op_index : make_range(_op_num))
105  if (_dDdv[op_index])
106  (*_dDdv[op_index])[_qp] = _b_weight * _diff_bulk * (*_dhmdv[op_index])[_qp] +
107  _v_weight * _diff_void * (*_dhbdv[op_index])[_qp] +
108  _diff_gb * SumEtaj * _gb_weight;
109 }
const Real _diff_bulk
Input parameters.
std::vector< const MaterialProperty< Real > * > _dhbdv
virtual bool isCoupledConstant(const std::string &var_name) const
VariableName coupledName(const std::string &var_name, unsigned int comp=0) const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const MaterialProperty< Real > & _hm
registerMooseObject("PhaseFieldApp", PolycrystalDiffusivity)
std::vector< const VariableValue * > _vals
MaterialProperty< Real > * _dDdc
std::vector< MaterialProperty< Real > * > _dDdv
std::vector< const MaterialProperty< Real > * > _dhmdv
virtual const VariableValue & coupledValue(const std::string &var_name, unsigned int comp=0) const
static InputParameters validParams()
MaterialProperty< Real > & _diff
void paramError(const std::string &param, Args... args) const
Generates a diffusion function to distinguish between the solid, void, grain boundary, and surface diffusion rates.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
const VariableValue & _c
Variable values for concentration and order parameters.
const MaterialPropertyName _diff_name
Mateiral property and its derivatives declarations.
const MaterialProperty< Real > & _dhbdc
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void addRequiredCoupledVarWithAutoBuild(const std::string &name, const std::string &base_name, const std::string &num_name, const std::string &doc_string)
static InputParameters validParams()
IntRange< T > make_range(T beg, T end)
void addClassDescription(const std::string &doc_string)
const MaterialProperty< Real > & _dhmdc
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
PolycrystalDiffusivity(const InputParameters &parameters)
const MaterialProperty< Real > & _hb
Switching function material and its derivatives.