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 
15 template <>
16 InputParameters
18 {
19  InputParameters params = validParams<AuxKernel>();
20  params.addRequiredCoupledVar("v", "Array of coupled variables");
21  params.addParam<Real>("a", 1.0, "Modified Coefficent in Taylor series expansion");
22  params.addParam<Real>("b", 1.0, "Modified Coefficent in Taylor series expansion");
23  params.addParam<Real>("c", 1.0, "Modified Coefficent in Taylor series expansion");
24  params.addParam<unsigned int>(
25  "num_exp_terms", 4, "Number of terms to use in the Taylor series expansion");
26  MooseEnum log_options("tolerance cancelation expansion nothing");
27  params.addRequiredParam<MooseEnum>(
28  "log_approach", log_options, "Which approach will be used to handle the natural log");
29  params.addParam<Real>("tol", 1.0e-9, "Tolerance used when the tolerance approach is chosen");
30  return params;
31 }
32 
33 PFCRFFEnergyDensity::PFCRFFEnergyDensity(const InputParameters & parameters)
34  : AuxKernel(parameters),
35  _order(coupledComponents("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  _vals.resize(_order);
44  for (unsigned int i = 0; i < _order; ++i)
45  _vals[i] = &coupledValue("v", i);
46 }
47 
48 Real
50 {
51  Real val = 0.0;
52  switch (_log_approach)
53  {
54  case 0: // approach using tolerence
55  if (1.0 + (*_vals[0])[_qp] < _tol)
56  val += ((1.0 + _tol) * std::log(1 + _tol)) - _tol;
57  else
58  val += ((1.0 + (*_vals[0])[_qp]) * std::log(1 + (*_vals[0])[_qp])) - (*_vals[0])[_qp];
59  break;
60 
61  case 1: // approach using cancellation
62  val += ((1.0 + (*_vals[0])[_qp]) * std::log(1.0 + (*_vals[0])[_qp])) - (*_vals[0])[_qp];
63  break;
64 
65  case 2: // approach using Taylor Series Expansion
66  Real coef = 1.0;
67 
68  for (unsigned int i = 2; i < (2 + _num_exp_terms); i++)
69  {
70  if (i == 2)
71  coef = _c;
72  else if (i == 3)
73  coef = _a;
74  else if (i == 4)
75  coef = _b;
76  else
77  coef = 1.0;
78 
79  val +=
80  coef * (std::pow(-1.0, Real(i)) / (i * (i - 1))) * std::pow((*_vals[0])[_qp], Real(i));
81  }
82  break;
83  }
84 
85  // Loop Through Variables
86  Real sumL = 0.0;
87  for (unsigned int i = 1; i < _order; ++i)
88  sumL += (*_vals[i])[_qp] * 0.5;
89 
90  val -= ((*_vals[0])[_qp] * sumL);
91 
92  return val;
93 }
PFCRFFEnergyDensity::_b
Real _b
Definition: PFCRFFEnergyDensity.h:32
PFCRFFEnergyDensity::computeValue
virtual Real computeValue()
Definition: PFCRFFEnergyDensity.C:49
registerMooseObject
registerMooseObject("PhaseFieldApp", PFCRFFEnergyDensity)
pow
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
Definition: ExpressionBuilder.h:673
PFCRFFEnergyDensity::_order
unsigned int _order
Definition: PFCRFFEnergyDensity.h:28
PFCRFFEnergyDensity
Definition: PFCRFFEnergyDensity.h:20
PFCRFFEnergyDensity::_c
Real _c
Definition: PFCRFFEnergyDensity.h:33
PFCRFFEnergyDensity::_log_approach
MooseEnum _log_approach
Definition: PFCRFFEnergyDensity.h:35
PFCRFFEnergyDensity::_vals
std::vector< const VariableValue * > _vals
Definition: PFCRFFEnergyDensity.h:29
validParams< PFCRFFEnergyDensity >
InputParameters validParams< PFCRFFEnergyDensity >()
Definition: PFCRFFEnergyDensity.C:17
PFCRFFEnergyDensity::_tol
Real _tol
Definition: PFCRFFEnergyDensity.h:36
PFCRFFEnergyDensity::PFCRFFEnergyDensity
PFCRFFEnergyDensity(const InputParameters &parameters)
Definition: PFCRFFEnergyDensity.C:33
PFCRFFEnergyDensity::_num_exp_terms
unsigned int _num_exp_terms
Definition: PFCRFFEnergyDensity.h:34
PFCRFFEnergyDensity.h
PFCRFFEnergyDensity::_a
Real _a
Definition: PFCRFFEnergyDensity.h:31