https://mooseframework.inl.gov
CoupledValueFunctionFreeEnergy.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 
11 #include "Function.h"
12 
14 
17 {
19  params.addClassDescription("Compute a free energy from a lookup function");
20  params.addRequiredParam<FunctionName>("free_energy_function",
21  "Coupled function to evaluate with values from v");
22  params.addRequiredParam<std::vector<FunctionName>>(
23  "chemical_potential_functions", "Coupled function to evaluate with values from v");
24  params.addCoupledVar("v",
25  "List of up to four coupled variables that are substituted for x,y,z, and t "
26  "in the coupled function");
27  params.set<unsigned int>("derivative_order") = 2;
28  return params;
29 }
30 
32  : DerivativeFunctionMaterialBase(parameters),
33  _free_energy_function(
34  isParamValid("free_energy_function") ? &getFunction("free_energy_function") : nullptr),
35  _chemical_potential_names(getParam<std::vector<FunctionName>>("chemical_potential_functions")),
36  _chemical_potential_functions(_nargs)
37 {
39  paramError(
40  "chemical_potential_functions",
41  "Exactly one chemical potential function must be supplied for each coupled variable");
42 
43  // get chemical potential functions
44  for (unsigned int i = 0; i < _nargs; ++i)
46 }
47 
48 void
50 {
52  paramError("free_energy_function",
53  "The undifferentiated free energy property is requested in the simulation, but no "
54  "function is provided");
55 }
56 
57 void
59 {
60  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
61  {
62  // set function arguments to coupled variables
63  Point p;
64  Real t = 0;
65  for (unsigned int i = 0; i < 3 && i < _nargs; ++i)
66  p(i) = (*_args[i])[_qp];
67  if (_nargs == 4)
68  t = (*_args[3])[_qp];
69 
70  // set function value
72  (*_prop_F)[_qp] = _free_energy_function->value(t, p);
73 
74  for (unsigned int i = 0; i < _nargs; ++i)
75  {
76  // set first derivatives
77  if (_prop_dF[i])
79 
80  // second derivatives via grad
81  auto grad = _chemical_potential_functions[i]->gradient(t, p);
82  for (unsigned int j = i; j < 3 && j < _nargs; ++j)
83  if (_prop_d2F[i][j])
84  (*_prop_d2F[i][j])[_qp] = grad(j);
85 
86  // second derivative via time derivative
87  if (_nargs == 4 && _prop_d2F[i][3])
88  (*_prop_d2F[i][3])[_qp] = _chemical_potential_functions[i]->timeDerivative(t, p);
89  }
90  }
91 }
T & set(const std::string &name, bool quiet_mode=false)
const std::vector< FunctionName > _chemical_potential_names
void addRequiredParam(const std::string &name, const std::string &doc_string)
std::vector< std::vector< GenericMaterialProperty< Real, is_ad > *> > _prop_d2F
std::vector< const Function * > _chemical_potential_functions
CoupledValueFunctionFreeEnergy(const InputParameters &parameters)
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
Compute free energy and chemical potentials from user supplied MooseFunctions.
void paramError(const std::string &param, Args... args) const
std::string grad(const std::string &var)
Definition: NS.h:91
void addCoupledVar(const std::string &name, const std::string &doc_string)
registerMooseObject("PhaseFieldApp", CoupledValueFunctionFreeEnergy)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Function & getFunctionByName(const FunctionName &name) const
GenericMaterialProperty< Real, is_ad > * _prop_F
void addClassDescription(const std::string &doc_string)
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
virtual Real value(Real t, const Point &p) const
std::vector< const GenericVariableValue< is_ad > *> _args
std::vector< GenericMaterialProperty< Real, is_ad > *> _prop_dF
static InputParameters validParams()