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

Generated by: LCOV version 1.14