https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
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{
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
48void
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
57void
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])
78 (*_prop_dF[i])[_qp] = _chemical_potential_functions[i]->value(t, p);
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}
registerMooseObject("PhaseFieldApp", CoupledValueFunctionFreeEnergy)
const Real p
Compute free energy and chemical potentials from user supplied MooseFunctions.
CoupledValueFunctionFreeEnergy(const InputParameters &parameters)
std::vector< const Function * > _chemical_potential_functions
const std::vector< FunctionName > _chemical_potential_names
static InputParameters validParams()
std::vector< std::vector< GenericMaterialProperty< Real, is_ad > * > > _prop_d2F
std::vector< GenericMaterialProperty< Real, is_ad > * > _prop_dF
const Function & getFunctionByName(const FunctionName &name) const
std::vector< const GenericVariableValue< is_ad > * > _args
GenericMaterialProperty< Real, is_ad > * _prop_F
virtual Real value(Real t, const Point &p) const
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
void addCoupledVar(const std::string &name, const std::string &doc_string)
void paramError(const std::string &param, Args... args) const