LCOV - code coverage report
Current view: top level - src/materials - GrandPotentialInterface.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 45 51 88.2 %
Date: 2025-09-04 07:55:36 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          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 "GrandPotentialInterface.h"
      11             : #include "Conversion.h"
      12             : #include "IndirectSort.h"
      13             : #include "libmesh/utility.h"
      14             : 
      15             : registerMooseObject("PhaseFieldApp", GrandPotentialInterface);
      16             : 
      17             : InputParameters
      18          47 : GrandPotentialInterface::validParams()
      19             : {
      20          47 :   InputParameters params = Material::validParams();
      21          47 :   params.addClassDescription("Calculate Grand Potential interface parameters for a specified "
      22             :                              "interfacial free energy and width");
      23          94 :   params.addRequiredParam<std::vector<Real>>("sigma", "Interfacial free energies");
      24          94 :   params.addRequiredRangeCheckedParam<Real>(
      25             :       "width", "width > 0", "Interfacial width (for the interface with gamma = 1.5)");
      26          94 :   params.addParam<std::vector<MaterialPropertyName>>(
      27             :       "gamma_names",
      28             :       "Interfacial / grain boundary gamma parameter names (leave empty for gamma0... gammaN)");
      29          94 :   params.addParam<MaterialPropertyName>("kappa_name", "kappa", "Gradient interface parameter name");
      30          94 :   params.addParam<MaterialPropertyName>("mu_name", "mu", "Grain growth bulk energy parameter name");
      31          94 :   params.addParam<unsigned int>(
      32             :       "sigma_index",
      33             :       "Sigma index to choose gamma = 1.5 for. Omit this to automatically chose the median sigma.");
      34          94 :   params.addParamNamesToGroup("mu_name sigma_index", "Advanced");
      35          47 :   return params;
      36           0 : }
      37             : 
      38          36 : GrandPotentialInterface::GrandPotentialInterface(const InputParameters & parameters)
      39             :   : Material(parameters),
      40          36 :     _sigma(getParam<std::vector<Real>>("sigma")),
      41          72 :     _width(getParam<Real>("width")),
      42          36 :     _n_pair(_sigma.size()),
      43          36 :     _gamma(_n_pair),
      44          72 :     _gamma_name(getParam<std::vector<MaterialPropertyName>>("gamma_names")),
      45          36 :     _gamma_prop(_n_pair),
      46          72 :     _kappa_prop(declareProperty<Real>(getParam<MaterialPropertyName>("kappa_name"))),
      47         108 :     _mu_prop(declareProperty<Real>(getParam<MaterialPropertyName>("mu_name")))
      48             : {
      49             :   // error check parameters
      50          36 :   if (_n_pair == 0)
      51           0 :     paramError("sigma", "Specify at least one interfacial energy");
      52             : 
      53          36 :   if (_gamma_name.size() != 0 && _gamma_name.size() != _n_pair)
      54           0 :     paramError("gamma_names",
      55             :                "Specify either as many entries are sigma values or none at all for auto-naming the "
      56             :                "gamma material properties.");
      57             : 
      58             :   // automatic names for the gamma properties
      59          36 :   if (_gamma_name.size() == 0)
      60           0 :     for (unsigned int i = 0; i < _n_pair; i++)
      61           0 :       _gamma_name[i] = "gamma" + Moose::stringify(i);
      62             : 
      63             :   // declare gamma material properties
      64         108 :   for (unsigned int i = 0; i < _n_pair; i++)
      65          72 :     _gamma_prop[i] = &declareProperty<Real>(_gamma_name[i]);
      66             : 
      67             :   // determine median interfacial free energy (or use explicit user choice)
      68             :   unsigned int median;
      69          72 :   if (isParamValid("sigma_index"))
      70           0 :     median = getParam<unsigned int>("sigma_index");
      71             :   else
      72             :   {
      73             :     std::vector<size_t> indices;
      74          36 :     Moose::indirectSort(_sigma.begin(), _sigma.end(), indices);
      75          36 :     median = indices[(indices.size() - 1) / 2];
      76          36 :   }
      77             : 
      78             :   // set the median gamma to 1.5 and use analytical expression for kappa and mu (m)
      79          36 :   _gamma[median] = 1.5;
      80          36 :   _kappa = 3.0 / 4.0 * _sigma[median] * _width;
      81          36 :   _mu = 6.0 * _sigma[median] / _width;
      82             : 
      83             :   // set all other gammas
      84         108 :   for (unsigned int i = 0; i < _n_pair; ++i)
      85             :   {
      86             :     // skip the already calculated median value
      87          72 :     if (i == median)
      88             :       continue;
      89             : 
      90          36 :     const Real g = _sigma[i] / std::sqrt(_mu * _kappa);
      91             : 
      92             :     // estimate for gamma from polynomial expansion
      93          36 :     Real gamma = 1.0 / (-5.288 * Utility::pow<8>(g) - 0.09364 * Utility::pow<6>(g) +
      94          36 :                         9.965 * Utility::pow<4>(g) - 8.183 * Utility::pow<2>(g) + 2.007);
      95             : 
      96          36 :     _gamma[i] = gamma;
      97             :   }
      98          36 : }
      99             : 
     100             : void
     101           6 : GrandPotentialInterface::computeQpProperties()
     102             : {
     103           6 :   _kappa_prop[_qp] = _kappa;
     104           6 :   _mu_prop[_qp] = _mu;
     105          18 :   for (unsigned int i = 0; i < _n_pair; ++i)
     106          12 :     (*_gamma_prop[i])[_qp] = _gamma[i];
     107           6 : }

Generated by: LCOV version 1.14