www.mooseframework.org
PFCRFFEnergyDensity.C
Go to the documentation of this file.
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 "PFCRFFEnergyDensity.h"
11 #include "libmesh/utility.h"
12 
14 
17 {
19  params.addRequiredCoupledVar("v", "Array of coupled variables");
20  params.addParam<Real>("a", 1.0, "Modified Coefficent in Taylor series expansion");
21  params.addParam<Real>("b", 1.0, "Modified Coefficent in Taylor series expansion");
22  params.addParam<Real>("c", 1.0, "Modified Coefficent in Taylor series expansion");
23  params.addParam<unsigned int>(
24  "num_exp_terms", 4, "Number of terms to use in the Taylor series expansion");
25  MooseEnum log_options("tolerance cancelation expansion nothing");
27  "log_approach", log_options, "Which approach will be used to handle the natural log");
28  params.addParam<Real>("tol", 1.0e-9, "Tolerance used when the tolerance approach is chosen");
29  return params;
30 }
31 
33  : AuxKernel(parameters),
34  _order(coupledComponents("v")),
35  _vals(coupledValues("v")),
36  _a(getParam<Real>("a")),
37  _b(getParam<Real>("b")),
38  _c(getParam<Real>("c")),
39  _num_exp_terms(getParam<unsigned int>("num_exp_terms")),
40  _log_approach(getParam<MooseEnum>("log_approach")),
41  _tol(getParam<Real>("tol"))
42 {
43 }
44 
45 Real
47 {
48  Real val = 0.0;
49  switch (_log_approach)
50  {
51  case 0: // approach using tolerence
52  if (1.0 + (*_vals[0])[_qp] < _tol)
53  val += ((1.0 + _tol) * std::log(1 + _tol)) - _tol;
54  else
55  val += ((1.0 + (*_vals[0])[_qp]) * std::log(1 + (*_vals[0])[_qp])) - (*_vals[0])[_qp];
56  break;
57 
58  case 1: // approach using cancellation
59  val += ((1.0 + (*_vals[0])[_qp]) * std::log(1.0 + (*_vals[0])[_qp])) - (*_vals[0])[_qp];
60  break;
61 
62  case 2: // approach using Taylor Series Expansion
63  Real coef = 1.0;
64 
65  for (unsigned int i = 2; i < (2 + _num_exp_terms); i++)
66  {
67  if (i == 2)
68  coef = _c;
69  else if (i == 3)
70  coef = _a;
71  else if (i == 4)
72  coef = _b;
73  else
74  coef = 1.0;
75 
76  val +=
77  coef * (std::pow(-1.0, Real(i)) / (i * (i - 1))) * std::pow((*_vals[0])[_qp], Real(i));
78  }
79  break;
80  }
81 
82  // Loop Through Variables
83  Real sumL = 0.0;
84  for (unsigned int i = 1; i < _order; ++i)
85  sumL += (*_vals[i])[_qp] * 0.5;
86 
87  val -= ((*_vals[0])[_qp] * sumL);
88 
89  return val;
90 }
registerMooseObject("PhaseFieldApp", PFCRFFEnergyDensity)
const std::vector< const VariableValue * > _vals
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const unsigned int _order
PFCRFFEnergyDensity(const InputParameters &parameters)
void addRequiredParam(const std::string &name, const std::string &doc_string)
static InputParameters validParams()
const unsigned int _num_exp_terms
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static InputParameters validParams()
virtual Real computeValue()
MooseUnits pow(const MooseUnits &, int)
void ErrorVector unsigned int
const MooseEnum _log_approach