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 45 : PFCRFFEnergyDensity::validParams() 17 : { 18 45 : InputParameters params = AuxKernel::validParams(); 19 45 : params.addClassDescription( 20 : "Computes the crystal free energy density for the RFF form of the phase field crystal model"); 21 90 : params.addRequiredCoupledVar("v", "Array of coupled variables"); 22 90 : params.addParam<Real>("a", 1.0, "Modified coefficient in Taylor series expansion"); 23 90 : params.addParam<Real>("b", 1.0, "Modified coefficient in Taylor series expansion"); 24 90 : params.addParam<Real>("c", 1.0, "Modified coefficient in Taylor series expansion"); 25 90 : params.addParam<unsigned int>( 26 90 : "num_exp_terms", 4, "Number of terms to use in the Taylor series expansion"); 27 90 : MooseEnum log_options("tolerance cancelation expansion nothing"); 28 90 : params.addRequiredParam<MooseEnum>( 29 : "log_approach", log_options, "Which approach will be used to handle the natural log"); 30 90 : params.addParam<Real>("tol", 1.0e-9, "Tolerance used when the tolerance approach is chosen"); 31 45 : return params; 32 45 : } 33 : 34 24 : PFCRFFEnergyDensity::PFCRFFEnergyDensity(const InputParameters & parameters) 35 : : AuxKernel(parameters), 36 24 : _order(coupledComponents("v")), 37 24 : _vals(coupledValues("v")), 38 48 : _a(getParam<Real>("a")), 39 48 : _b(getParam<Real>("b")), 40 48 : _c(getParam<Real>("c")), 41 48 : _num_exp_terms(getParam<unsigned int>("num_exp_terms")), 42 48 : _log_approach(getParam<MooseEnum>("log_approach")), 43 72 : _tol(getParam<Real>("tol")) 44 : { 45 24 : } 46 : 47 : Real 48 29700 : PFCRFFEnergyDensity::computeValue() 49 : { 50 : Real val = 0.0; 51 29700 : switch (_log_approach) 52 : { 53 9900 : case 0: // approach using tolerance 54 9900 : if (1.0 + (*_vals[0])[_qp] < _tol) 55 0 : val += ((1.0 + _tol) * std::log(1 + _tol)) - _tol; 56 : else 57 9900 : val += ((1.0 + (*_vals[0])[_qp]) * std::log(1 + (*_vals[0])[_qp])) - (*_vals[0])[_qp]; 58 : break; 59 : 60 9900 : case 1: // approach using cancellation 61 9900 : val += ((1.0 + (*_vals[0])[_qp]) * std::log(1.0 + (*_vals[0])[_qp])) - (*_vals[0])[_qp]; 62 9900 : break; 63 : 64 : case 2: // approach using Taylor Series Expansion 65 : Real coef = 1.0; 66 : 67 49500 : for (unsigned int i = 2; i < (2 + _num_exp_terms); i++) 68 : { 69 39600 : if (i == 2) 70 9900 : coef = _c; 71 29700 : else if (i == 3) 72 9900 : coef = _a; 73 19800 : else if (i == 4) 74 9900 : coef = _b; 75 : else 76 : coef = 1.0; 77 : 78 39600 : val += 79 39600 : 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 89100 : for (unsigned int i = 1; i < _order; ++i) 87 59400 : sumL += (*_vals[i])[_qp] * 0.5; 88 : 89 29700 : val -= ((*_vals[0])[_qp] * sumL); 90 : 91 29700 : return val; 92 : }