LCOV - code coverage report
Current view: top level - src/auxkernels - PFCRFFEnergyDensity.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 45 46 97.8 %
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 "PFCRFFEnergyDensity.h"
      11             : #include "libmesh/utility.h"
      12             : 
      13             : registerMooseObject("PhaseFieldApp", PFCRFFEnergyDensity);
      14             : 
      15             : InputParameters
      16          69 : PFCRFFEnergyDensity::validParams()
      17             : {
      18          69 :   InputParameters params = AuxKernel::validParams();
      19          69 :   params.addClassDescription(
      20             :       "Computes the crystal free energy density for the RFF form of the phase field crystal model");
      21         138 :   params.addRequiredCoupledVar("v", "Array of coupled variables");
      22         138 :   params.addParam<Real>("a", 1.0, "Modified coefficient in Taylor series expansion");
      23         138 :   params.addParam<Real>("b", 1.0, "Modified coefficient in Taylor series expansion");
      24         138 :   params.addParam<Real>("c", 1.0, "Modified coefficient in Taylor series expansion");
      25         138 :   params.addParam<unsigned int>(
      26         138 :       "num_exp_terms", 4, "Number of terms to use in the Taylor series expansion");
      27         138 :   MooseEnum log_options("tolerance cancelation expansion nothing");
      28         138 :   params.addRequiredParam<MooseEnum>(
      29             :       "log_approach", log_options, "Which approach will be used to handle the natural log");
      30         138 :   params.addParam<Real>("tol", 1.0e-9, "Tolerance used when the tolerance approach is chosen");
      31          69 :   return params;
      32          69 : }
      33             : 
      34          36 : PFCRFFEnergyDensity::PFCRFFEnergyDensity(const InputParameters & parameters)
      35             :   : AuxKernel(parameters),
      36          36 :     _order(coupledComponents("v")),
      37          36 :     _vals(coupledValues("v")),
      38          72 :     _a(getParam<Real>("a")),
      39          72 :     _b(getParam<Real>("b")),
      40          72 :     _c(getParam<Real>("c")),
      41          72 :     _num_exp_terms(getParam<unsigned int>("num_exp_terms")),
      42          72 :     _log_approach(getParam<MooseEnum>("log_approach")),
      43         108 :     _tol(getParam<Real>("tol"))
      44             : {
      45          36 : }
      46             : 
      47             : Real
      48       35100 : PFCRFFEnergyDensity::computeValue()
      49             : {
      50             :   Real val = 0.0;
      51       35100 :   switch (_log_approach)
      52             :   {
      53       11700 :     case 0: // approach using tolerance
      54       11700 :       if (1.0 + (*_vals[0])[_qp] < _tol)
      55           0 :         val += ((1.0 + _tol) * std::log(1 + _tol)) - _tol;
      56             :       else
      57       11700 :         val += ((1.0 + (*_vals[0])[_qp]) * std::log(1 + (*_vals[0])[_qp])) - (*_vals[0])[_qp];
      58             :       break;
      59             : 
      60       11700 :     case 1: // approach using cancellation
      61       11700 :       val += ((1.0 + (*_vals[0])[_qp]) * std::log(1.0 + (*_vals[0])[_qp])) - (*_vals[0])[_qp];
      62       11700 :       break;
      63             : 
      64             :     case 2: // approach using Taylor Series Expansion
      65             :       Real coef = 1.0;
      66             : 
      67       58500 :       for (unsigned int i = 2; i < (2 + _num_exp_terms); i++)
      68             :       {
      69       46800 :         if (i == 2)
      70       11700 :           coef = _c;
      71       35100 :         else if (i == 3)
      72       11700 :           coef = _a;
      73       23400 :         else if (i == 4)
      74       11700 :           coef = _b;
      75             :         else
      76             :           coef = 1.0;
      77             : 
      78       46800 :         val +=
      79       46800 :             coef * (std::pow(-1.0, Real(i)) / (i * (i - 1))) * std::pow((*_vals[0])[_qp], Real(i));
      80             :       }
      81             :       break;
      82             :   }
      83             : 
      84             :   // Loop Through Variables
      85             :   Real sumL = 0.0;
      86      105300 :   for (unsigned int i = 1; i < _order; ++i)
      87       70200 :     sumL += (*_vals[i])[_qp] * 0.5;
      88             : 
      89       35100 :   val -= ((*_vals[0])[_qp] * sumL);
      90             : 
      91       35100 :   return val;
      92             : }

Generated by: LCOV version 1.14