LCOV - code coverage report
Current view: top level - src/materials - DerivativeMultiPhaseBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 73 75 97.3 %
Date: 2025-09-04 07:55:36 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         223 : DerivativeMultiPhaseBase::validParams()
      14             : {
      15         223 :   InputParameters params = DerivativeFunctionMaterialBase::validParams();
      16             : 
      17             :   // Phase materials 1-n
      18         446 :   params.addRequiredParam<std::vector<MaterialPropertyName>>(
      19             :       "fi_names", "List of free energies for the n phases");
      20         446 :   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         446 :   params.addCoupledVar("args", "Vector of variable arguments of the fi free energies");
      25         446 :   params.deprecateCoupledVar("args", "coupled_variables", "02/27/2024");
      26         446 :   params.addCoupledVar("displacement_gradients",
      27             :                        "Vector of displacement gradient variables (see "
      28             :                        "Modules/PhaseField/DisplacementGradients "
      29             :                        "action)");
      30             : 
      31             :   // Barrier
      32         446 :   params.addParam<MaterialPropertyName>(
      33             :       "g", "g", "Barrier Function Material that provides g(eta_i)");
      34         446 :   params.addParam<Real>("W", 0.0, "Energy barrier for the phase transformation from A to B");
      35             : 
      36         223 :   return params;
      37           0 : }
      38             : 
      39         171 : DerivativeMultiPhaseBase::DerivativeMultiPhaseBase(const InputParameters & parameters)
      40             :   : DerivativeFunctionMaterialBase(parameters),
      41         171 :     _eta_index(_nargs, -1),
      42         171 :     _num_etas(coupledComponents("etas")),
      43         171 :     _eta_names(_num_etas),
      44         171 :     _eta_vars(_num_etas),
      45         513 :     _fi_names(getParam<std::vector<MaterialPropertyName>>("fi_names")),
      46         171 :     _num_fi(_fi_names.size()),
      47         171 :     _prop_Fi(_num_fi),
      48         171 :     _prop_dFi(_num_fi),
      49         171 :     _prop_d2Fi(_num_fi),
      50         171 :     _prop_d3Fi(_num_fi),
      51         513 :     _hi_names(getParam<std::vector<MaterialPropertyName>>("hi_names")),
      52         171 :     _num_hi(_hi_names.size()),
      53         171 :     _hi(_num_hi),
      54         342 :     _g(getMaterialProperty<Real>("g")),
      55         171 :     _dg(_num_etas),
      56         171 :     _d2g(_num_etas),
      57         171 :     _d3g(_num_etas),
      58         513 :     _W(getParam<Real>("W"))
      59             : {
      60             :   // check passed in parameter vectors
      61         171 :   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         612 :   for (unsigned int i = 0; i < _num_etas; ++i)
      66             :   {
      67         441 :     _eta_names[i] = coupledName("etas", i);
      68         441 :     _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         882 :     _eta_index[argIndex(_eta_vars[i])] = i;
      73             : 
      74             :     // barrier function derivatives
      75         441 :     _dg[i] = &getMaterialPropertyDerivative<Real>("g", _eta_names[i]);
      76         441 :     _d2g[i].resize(_num_etas);
      77         441 :     if (_third_derivatives)
      78          81 :       _d3g[i].resize(_num_etas);
      79             : 
      80        1620 :     for (unsigned int j = 0; j < _num_etas; ++j)
      81             :     {
      82        1179 :       _d2g[i][j] = &getMaterialPropertyDerivative<Real>("g", _eta_names[i], _eta_names[j]);
      83             : 
      84        1179 :       if (_third_derivatives)
      85             :       {
      86         243 :         _d3g[i][j].resize(_num_etas);
      87         972 :         for (unsigned int k = 0; k < _num_etas; ++k)
      88         729 :           _d3g[i][j][k] = &getMaterialPropertyDerivative<Real>(
      89         729 :               "g", _eta_names[i], _eta_names[j], _eta_names[k]);
      90             :       }
      91             :     }
      92             :   }
      93             : 
      94             :   // reserve space and set phase material properties
      95         612 :   for (unsigned int n = 0; n < _num_fi; ++n)
      96             :   {
      97             :     // get phase free energy
      98         441 :     _prop_Fi[n] = &getMaterialPropertyByName<Real>(_fi_names[n]);
      99         441 :     _prop_dFi[n].resize(_nargs);
     100         441 :     _prop_d2Fi[n].resize(_nargs);
     101         441 :     _prop_d3Fi[n].resize(_nargs);
     102             : 
     103             :     // get switching function
     104         441 :     _hi[n] = &getMaterialPropertyByName<Real>(_hi_names[n]);
     105             : 
     106        1845 :     for (unsigned int i = 0; i < _nargs; ++i)
     107             :     {
     108        1404 :       _prop_dFi[n][i] = &getMaterialPropertyDerivative<Real>(_fi_names[n], _arg_names[i]);
     109        1404 :       _prop_d2Fi[n][i].resize(_nargs);
     110             : 
     111        1404 :       if (_third_derivatives)
     112         324 :         _prop_d3Fi[n][i].resize(_nargs);
     113             : 
     114        5940 :       for (unsigned int j = 0; j < _nargs; ++j)
     115             :       {
     116        4536 :         _prop_d2Fi[n][i][j] =
     117        4536 :             &getMaterialPropertyDerivative<Real>(_fi_names[n], _arg_names[i], _arg_names[j]);
     118             : 
     119        4536 :         if (_third_derivatives)
     120             :         {
     121        1296 :           _prop_d3Fi[n][i][j].resize(_nargs);
     122             : 
     123        6480 :           for (unsigned int k = 0; k < _nargs; ++k)
     124        5184 :             _prop_d3Fi[n][i][j][k] = &getMaterialPropertyDerivative<Real>(
     125        5184 :                 _fi_names[n], _arg_names[i], _arg_names[j], _arg_names[k]);
     126             :         }
     127             :       }
     128             :     }
     129             :   }
     130         171 : }
     131             : 
     132             : void
     133         144 : DerivativeMultiPhaseBase::initialSetup()
     134             : {
     135         504 :   for (unsigned int n = 0; n < _num_fi; ++n)
     136        1080 :     validateCoupling<Real>(_fi_names[n]);
     137         144 : }
     138             : 
     139             : Real
     140     1792720 : DerivativeMultiPhaseBase::computeF()
     141             : {
     142             :   Real F = 0.0;
     143     6248560 :   for (unsigned n = 0; n < _num_fi; ++n)
     144     4455840 :     F += (*_hi[n])[_qp] * (*_prop_Fi[n])[_qp];
     145     1792720 :   return F + _W * _g[_qp];
     146             : }

Generated by: LCOV version 1.14