LCOV - code coverage report
Current view: top level - src/materials - DerivativeMultiPhaseBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #32971 (54bef8) with base c6cf66 Lines: 72 74 97.3 %
Date: 2026-05-29 20:38:39 Functions: 4 4 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 "DerivativeMultiPhaseBase.h"
      11             : 
      12             : InputParameters
      13         151 : DerivativeMultiPhaseBase::validParams()
      14             : {
      15         151 :   InputParameters params = DerivativeFunctionMaterialBase::validParams();
      16             : 
      17             :   // Phase materials 1-n
      18         302 :   params.addRequiredParam<std::vector<MaterialPropertyName>>(
      19             :       "fi_names", "List of free energies for the n phases");
      20         302 :   params.addParam<std::vector<MaterialPropertyName>>(
      21             :       "hi_names", "Switching Function Materials that provide h(eta_i)");
      22             : 
      23             :   // All arguments of the phase free energies
      24         302 :   params.addCoupledVar("coupled_variables", "Vector of variable arguments of the fi free energies");
      25         302 :   params.addCoupledVar("displacement_gradients",
      26             :                        "Vector of displacement gradient variables (see "
      27             :                        "Modules/PhaseField/DisplacementGradients "
      28             :                        "action)");
      29             : 
      30             :   // Barrier
      31         302 :   params.addParam<MaterialPropertyName>(
      32             :       "g", "g", "Barrier Function Material that provides g(eta_i)");
      33         302 :   params.addParam<Real>("W", 0.0, "Energy barrier for the phase transformation from A to B");
      34             : 
      35         151 :   return params;
      36           0 : }
      37             : 
      38         117 : DerivativeMultiPhaseBase::DerivativeMultiPhaseBase(const InputParameters & parameters)
      39             :   : DerivativeFunctionMaterialBase(parameters),
      40         117 :     _eta_index(_nargs, -1),
      41         117 :     _num_etas(coupledComponents("etas")),
      42         117 :     _eta_names(_num_etas),
      43         117 :     _eta_vars(_num_etas),
      44         351 :     _fi_names(getParam<std::vector<MaterialPropertyName>>("fi_names")),
      45         117 :     _num_fi(_fi_names.size()),
      46         117 :     _prop_Fi(_num_fi),
      47         117 :     _prop_dFi(_num_fi),
      48         117 :     _prop_d2Fi(_num_fi),
      49         117 :     _prop_d3Fi(_num_fi),
      50         351 :     _hi_names(getParam<std::vector<MaterialPropertyName>>("hi_names")),
      51         117 :     _num_hi(_hi_names.size()),
      52         117 :     _hi(_num_hi),
      53         234 :     _g(getMaterialProperty<Real>("g")),
      54         117 :     _dg(_num_etas),
      55         117 :     _d2g(_num_etas),
      56         117 :     _d3g(_num_etas),
      57         351 :     _W(getParam<Real>("W"))
      58             : {
      59             :   // check passed in parameter vectors
      60         117 :   if (_num_fi != _num_hi)
      61           0 :     mooseError("Need to pass in as many hi_names as fi_names in DerivativeMultiPhaseBase ", name());
      62             : 
      63             :   // get order parameter names and libmesh variable names, set barrier function derivatives
      64         420 :   for (unsigned int i = 0; i < _num_etas; ++i)
      65             :   {
      66         303 :     _eta_names[i] = coupledName("etas", i);
      67         303 :     _eta_vars[i] = coupled("etas", i);
      68             : 
      69             :     // for each coupled variable we need to know if it was coupled through "etas"
      70             :     // and - if so - which coupled component of "etas" it comes from
      71         606 :     _eta_index[argIndex(_eta_vars[i])] = i;
      72             : 
      73             :     // barrier function derivatives
      74         303 :     _dg[i] = &getMaterialPropertyDerivative<Real>("g", _eta_names[i]);
      75         303 :     _d2g[i].resize(_num_etas);
      76         303 :     if (_third_derivatives)
      77          63 :       _d3g[i].resize(_num_etas);
      78             : 
      79        1116 :     for (unsigned int j = 0; j < _num_etas; ++j)
      80             :     {
      81         813 :       _d2g[i][j] = &getMaterialPropertyDerivative<Real>("g", _eta_names[i], _eta_names[j]);
      82             : 
      83         813 :       if (_third_derivatives)
      84             :       {
      85         189 :         _d3g[i][j].resize(_num_etas);
      86         756 :         for (unsigned int k = 0; k < _num_etas; ++k)
      87         567 :           _d3g[i][j][k] = &getMaterialPropertyDerivative<Real>(
      88         567 :               "g", _eta_names[i], _eta_names[j], _eta_names[k]);
      89             :       }
      90             :     }
      91             :   }
      92             : 
      93             :   // reserve space and set phase material properties
      94         420 :   for (unsigned int n = 0; n < _num_fi; ++n)
      95             :   {
      96             :     // get phase free energy
      97         303 :     _prop_Fi[n] = &getMaterialPropertyByName<Real>(_fi_names[n]);
      98         303 :     _prop_dFi[n].resize(_nargs);
      99         303 :     _prop_d2Fi[n].resize(_nargs);
     100         303 :     _prop_d3Fi[n].resize(_nargs);
     101             : 
     102             :     // get switching function
     103         303 :     _hi[n] = &getMaterialPropertyByName<Real>(_hi_names[n]);
     104             : 
     105        1275 :     for (unsigned int i = 0; i < _nargs; ++i)
     106             :     {
     107         972 :       _prop_dFi[n][i] = &getMaterialPropertyDerivative<Real>(_fi_names[n], _arg_names[i]);
     108         972 :       _prop_d2Fi[n][i].resize(_nargs);
     109             : 
     110         972 :       if (_third_derivatives)
     111         252 :         _prop_d3Fi[n][i].resize(_nargs);
     112             : 
     113        4140 :       for (unsigned int j = 0; j < _nargs; ++j)
     114             :       {
     115        3168 :         _prop_d2Fi[n][i][j] =
     116        3168 :             &getMaterialPropertyDerivative<Real>(_fi_names[n], _arg_names[i], _arg_names[j]);
     117             : 
     118        3168 :         if (_third_derivatives)
     119             :         {
     120        1008 :           _prop_d3Fi[n][i][j].resize(_nargs);
     121             : 
     122        5040 :           for (unsigned int k = 0; k < _nargs; ++k)
     123        4032 :             _prop_d3Fi[n][i][j][k] = &getMaterialPropertyDerivative<Real>(
     124        4032 :                 _fi_names[n], _arg_names[i], _arg_names[j], _arg_names[k]);
     125             :         }
     126             :       }
     127             :     }
     128             :   }
     129         117 : }
     130             : 
     131             : void
     132          96 : DerivativeMultiPhaseBase::initialSetup()
     133             : {
     134         336 :   for (unsigned int n = 0; n < _num_fi; ++n)
     135         720 :     validateCoupling<Real>(_fi_names[n]);
     136          96 : }
     137             : 
     138             : Real
     139     1453280 : DerivativeMultiPhaseBase::computeF()
     140             : {
     141             :   Real F = 0.0;
     142     5047040 :   for (unsigned n = 0; n < _num_fi; ++n)
     143     3593760 :     F += (*_hi[n])[_qp] * (*_prop_Fi[n])[_qp];
     144     1453280 :   return F + _W * _g[_qp];
     145             : }

Generated by: LCOV version 1.14