LCOV - code coverage report
Current view: top level - src/materials - SwitchingFunctionMultiPhaseMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #30119 (aa6062) with base 79f9bd Lines: 61 62 98.4 %
Date: 2025-03-20 17:26:41 Functions: 6 6 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 "SwitchingFunctionMultiPhaseMaterial.h"
      11             : #include "MooseException.h"
      12             : 
      13             : registerMooseObject("PhaseFieldApp", SwitchingFunctionMultiPhaseMaterial);
      14             : registerMooseObject("PhaseFieldApp", ADSwitchingFunctionMultiPhaseMaterial);
      15             : 
      16             : template <bool is_ad>
      17             : InputParameters
      18         475 : SwitchingFunctionMultiPhaseMaterialTempl<is_ad>::validParams()
      19             : {
      20         475 :   InputParameters params = Material::validParams();
      21         950 :   params.addRequiredParam<MaterialPropertyName>(
      22             :       "h_name", "Name of the switching function material property for the given phase");
      23         950 :   params.addRequiredCoupledVar("phase_etas", "Vector of order parameters for the given phase");
      24         950 :   params.addRequiredCoupledVar("all_etas", "Vector of all order parameters for all phases");
      25         475 :   params.addClassDescription("Calculates the switching function for a given phase for a "
      26             :                              "multi-phase, multi-order parameter model");
      27         475 :   return params;
      28           0 : }
      29             : 
      30             : template <bool is_ad>
      31         375 : SwitchingFunctionMultiPhaseMaterialTempl<is_ad>::SwitchingFunctionMultiPhaseMaterialTempl(
      32             :     const InputParameters & parameters)
      33             :   : DerivativeMaterialInterface<Material>(parameters),
      34         750 :     _h_name(this->getParam<MaterialPropertyName>("h_name")),
      35         375 :     _num_eta_p(coupledComponents("phase_etas")),
      36         375 :     _eta_p(coupledGenericValues<is_ad>("phase_etas")),
      37         375 :     _eta_p_names(coupledNames("phase_etas")),
      38         375 :     _num_eta(coupledComponents("all_etas")),
      39         375 :     _eta(coupledGenericValues<is_ad>("all_etas")),
      40         375 :     _eta_names(coupledNames("all_etas")),
      41         375 :     _is_p(_num_eta),
      42         375 :     _prop_h(declareGenericProperty<Real, is_ad>(_h_name)),
      43         375 :     _prop_dh(_num_eta),
      44         750 :     _prop_d2h(_num_eta)
      45             : {
      46             :   // Declare h derivative properties
      47        1500 :   for (unsigned int i = 0; i < _num_eta; ++i)
      48        1125 :     _prop_d2h[i].resize(_num_eta, NULL);
      49             : 
      50        1500 :   for (unsigned int i = 0; i < _num_eta; ++i)
      51             :   {
      52        1125 :     _prop_dh[i] = &this->template declarePropertyDerivative<Real, is_ad>(_h_name, _eta_names[i]);
      53        3495 :     for (unsigned int j = i; j < _num_eta; ++j)
      54             :     {
      55        2370 :       _prop_d2h[i][j] = _prop_d2h[j][i] = &this->template declarePropertyDerivative<Real, is_ad>(
      56             :           _h_name, _eta_names[i], _eta_names[j]);
      57             :     }
      58             :   }
      59             : 
      60             :   // Determine which order parameters in the list of all etas belong to phase p
      61        1500 :   for (unsigned int i = 0; i < _num_eta; ++i)
      62             :   {
      63        1125 :     _is_p[i] = false;
      64        2730 :     for (unsigned int j = 0; j < _num_eta_p; ++j)
      65             :     {
      66        1605 :       if (_eta_names[i] == _eta_p_names[j])
      67             :         _is_p[i] = true;
      68             :     }
      69             :   }
      70         375 : }
      71             : 
      72             : template <bool is_ad>
      73             : void
      74    52117800 : SwitchingFunctionMultiPhaseMaterialTempl<is_ad>::computeQpProperties()
      75             : {
      76    51062400 :   GenericReal<is_ad> sum_p = 0.0;
      77    51062400 :   GenericReal<is_ad> sum_all = 0.0;
      78             : 
      79   130214400 :   for (unsigned int i = 0; i < _num_eta_p; ++i)
      80   154690200 :     sum_p += (*_eta_p[i])[_qp] * (*_eta_p[i])[_qp];
      81             : 
      82   208311000 :   for (unsigned int i = 0; i < _num_eta; ++i)
      83   309380400 :     sum_all += (*_eta[i])[_qp] * (*_eta[i])[_qp];
      84             : 
      85     1055400 :   GenericReal<is_ad> sum_notp = sum_all - sum_p;
      86             : 
      87    52117800 :   _prop_h[_qp] = sum_p / sum_all;
      88             : 
      89   208311000 :   for (unsigned int i = 0; i < _num_eta; ++i)
      90             :   {
      91             :     // First derivatives
      92   156193200 :     if (_is_p[i])
      93   154690200 :       (*_prop_dh[i])[_qp] = 2.0 * (*_eta[i])[_qp] * sum_notp / (sum_all * sum_all);
      94             :     else
      95   154690200 :       (*_prop_dh[i])[_qp] = -2.0 * (*_eta[i])[_qp] * sum_p / (sum_all * sum_all);
      96             : 
      97             :     // Second derivatives
      98   625618800 :     for (unsigned int j = 0; j < _num_eta; ++j)
      99             :     {
     100   469425600 :       if (i == j)
     101             :       {
     102   156193200 :         if (_is_p[i])
     103   154690200 :           (*_prop_d2h[i][j])[_qp] =
     104   231283800 :               (2.0 * sum_all * sum_notp - 8.0 * (*_eta[i])[_qp] * (*_eta[i])[_qp] * sum_notp) /
     105     1503000 :               (sum_all * sum_all * sum_all);
     106             :         else
     107   154690200 :           (*_prop_d2h[i][j])[_qp] =
     108   231283800 :               (-2.0 * sum_p * sum_all + 8.0 * (*_eta[i])[_qp] * (*_eta[i])[_qp] * sum_p) /
     109     1503000 :               (sum_all * sum_all * sum_all);
     110             :       }
     111   313232400 :       else if (_is_p[i] && _is_p[j])
     112   103603200 :         (*_prop_d2h[i][j])[_qp] =
     113   103603200 :             -8.0 * (*_eta[i])[_qp] * (*_eta[j])[_qp] * sum_notp / (sum_all * sum_all * sum_all);
     114   260691600 :       else if (!_is_p[i] && !_is_p[j])
     115   103603200 :         (*_prop_d2h[i][j])[_qp] =
     116   103603200 :             8.0 * (*_eta[i])[_qp] * (*_eta[j])[_qp] * sum_p / (sum_all * sum_all * sum_all);
     117             :       else
     118   616650000 :         (*_prop_d2h[i][j])[_qp] = (4.0 * sum_all - 8.0 * sum_notp) * (*_eta[i])[_qp] *
     119   208150800 :                                   (*_eta[j])[_qp] / (sum_all * sum_all * sum_all);
     120             :     }
     121             :   }
     122    52117800 : }
     123             : 
     124             : // explicit instantiation
     125             : template class SwitchingFunctionMultiPhaseMaterialTempl<true>;
     126             : template class SwitchingFunctionMultiPhaseMaterialTempl<false>;

Generated by: LCOV version 1.14