www.mooseframework.org
PFCRFFEnergyDensity.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
8 #include "PFCRFFEnergyDensity.h"
9 #include "libmesh/utility.h"
10 
11 template <>
12 InputParameters
14 {
15  InputParameters params = validParams<AuxKernel>();
16  params.addRequiredCoupledVar("v", "Array of coupled variables");
17  params.addParam<Real>("a", 1.0, "Modified Coefficent in Taylor Series Expanstion");
18  params.addParam<Real>("b", 1.0, "Modified Coefficent in Taylor Series Expanstion");
19  params.addParam<Real>("c", 1.0, "Modified Coefficent in Taylor Series Expanstion");
20  params.addParam<unsigned int>(
21  "num_exp_terms", 4, "This is the number of terms to use in the taylor series expansion");
22  MooseEnum log_options("tolerance cancelation expansion nothing");
23  params.addRequiredParam<MooseEnum>(
24  "log_approach", log_options, "Which approach will be used to handle the natural log");
25  params.addParam<Real>("tol", 1.0e-9, "Tolerance used when the tolerance approach is chosen");
26  return params;
27 }
28 
29 PFCRFFEnergyDensity::PFCRFFEnergyDensity(const InputParameters & parameters)
30  : AuxKernel(parameters),
31  _order(coupledComponents("v")),
32  _a(getParam<Real>("a")),
33  _b(getParam<Real>("b")),
34  _c(getParam<Real>("c")),
35  _num_exp_terms(getParam<unsigned int>("num_exp_terms")),
36  _log_approach(getParam<MooseEnum>("log_approach")),
37  _tol(getParam<Real>("tol"))
38 {
39  _vals.resize(_order);
40  for (unsigned int i = 0; i < _order; ++i)
41  _vals[i] = &coupledValue("v", i);
42 }
43 
44 Real
46 {
47  Real val = 0.0;
48  switch (_log_approach)
49  {
50  case 0: // approach using tolerence
51  if (1.0 + (*_vals[0])[_qp] < _tol)
52  val += ((1.0 + _tol) * std::log(1 + _tol)) - _tol;
53  else
54  val += ((1.0 + (*_vals[0])[_qp]) * std::log(1 + (*_vals[0])[_qp])) - (*_vals[0])[_qp];
55  break;
56 
57  case 1: // approach using cancellation
58  val += ((1.0 + (*_vals[0])[_qp]) * std::log(1.0 + (*_vals[0])[_qp])) - (*_vals[0])[_qp];
59  break;
60 
61  case 2: // approach using Taylor Series Expansion
62  Real coef = 1.0;
63 
64  for (unsigned int i = 2; i < (2 + _num_exp_terms); i++)
65  {
66  if (i == 2)
67  coef = _c;
68  else if (i == 3)
69  coef = _a;
70  else if (i == 4)
71  coef = _b;
72  else
73  coef = 1.0;
74 
75  val +=
76  coef * (std::pow(-1.0, Real(i)) / (i * (i - 1))) * std::pow((*_vals[0])[_qp], Real(i));
77  }
78  break;
79  }
80 
81  // Loop Through Variables
82  Real sumL = 0.0;
83  for (unsigned int i = 1; i < _order; ++i)
84  sumL += (*_vals[i])[_qp] * 0.5;
85 
86  val -= ((*_vals[0])[_qp] * sumL);
87 
88  return val;
89 }
PFCRFFEnergyDensity(const InputParameters &parameters)
InputParameters validParams< PFCRFFEnergyDensity >()
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
std::vector< const VariableValue * > _vals
virtual Real computeValue()