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