www.mooseframework.org
MooseParsedGradFunction.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 
12 
13 registerMooseObjectAliased("MooseApp", MooseParsedGradFunction, "ParsedGradFunction");
14 
17 {
19  params.addClassDescription("Defines a function and its gradient using input file parameters.");
21  params.addDeprecatedParam<std::string>(
22  "value", "User defined function.", "Use 'expression' instead.");
23  // TODO Make required once deprecation is handled + add 0 default, see #19119
24  params.addParam<std::string>("expression", "User defined function.");
25  params.addParam<std::string>("grad_x", "0", "Partial derivative with respect to x.");
26  params.addParam<std::string>("grad_y", "0", "Partial derivative with respect to y.");
27  params.addParam<std::string>("grad_z", "0", "Partial derivative with respect to z.");
28  return params;
29 }
30 
32  : Function(parameters),
33  MooseParsedFunctionBase(parameters),
34  _value(verifyFunction(getRenamedParam<std::string>("value", "expression"))),
35  _grad_value(verifyFunction(std::string("{") + getParam<std::string>("grad_x") + "}{" +
36  getParam<std::string>("grad_y") + "}{" +
37  getParam<std::string>("grad_z") + "}"))
38 {
39 }
40 
42 
43 Real
44 MooseParsedGradFunction::value(Real t, const Point & p) const
45 {
46  // Return a scalar value
47  return _function_ptr->evaluate<Real>(t, p);
48 }
49 
51 MooseParsedGradFunction::gradient(Real t, const Point & p) const
52 {
53  // Return gradient (RealGradient = RealVectorValue)
54  return _grad_function_ptr->evaluate<RealVectorValue>(t, p);
55 }
56 
58 MooseParsedGradFunction::vectorValue(Real /*t*/, const Point & /*p*/) const
59 {
60  mooseError("The vectorValue method is not defined in ParsedGradFunction");
61 }
62 
63 void
65 {
66  THREAD_ID tid = 0;
67  if (isParamValid("_tid"))
68  tid = getParam<THREAD_ID>("_tid");
69 
70  if (!_function_ptr)
72  std::make_unique<MooseParsedFunctionWrapper>(_pfb_feproblem, _value, _vars, _vals, tid);
73 
74  if (!_grad_function_ptr)
75  _grad_function_ptr = std::make_unique<MooseParsedFunctionWrapper>(
77 }
std::unique_ptr< MooseParsedFunctionWrapper > _function_ptr
Pointer to the Parsed function wrapper object for the scalar.
Base class for function objects.
Definition: Function.h:37
Creates the &#39;vars&#39; and &#39;vals&#39; parameters used by all ParsedFunctions, the parameters provided from th...
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
virtual RealGradient gradient(Real t, const Point &p) const override
Compute the gradient of the function.
std::string _value
String for the scalar function string.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
FEProblemBase & _pfb_feproblem
Reference to the FEProblemBase class for this object.
const std::vector< std::string > _vals
Values passed by the user, they may be Reals for Postprocessors.
MooseParsedGradFunction(const InputParameters &parameters)
virtual void initialSetup() override
Creates two libMesh::ParsedFunction objects for returning a vector via the &#39;gradient&#39; method and a sc...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
std::string _grad_value
String for the gradient, vector function string.
registerMooseObjectAliased("MooseApp", MooseParsedGradFunction, "ParsedGradFunction")
virtual Real value(Real t, const Point &p) const override
Return a scalar value from the function.
virtual ~MooseParsedGradFunction()
Destructor necessary for std::unique_ptr usage.
This class is similar to ParsedFunction except it also supports returning the gradient of the functio...
std::unique_ptr< MooseParsedFunctionWrapper > _grad_function_ptr
Pointer to the Parsed function wrapper object for the gradient.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual RealVectorValue vectorValue(Real t, const Point &p) const override
Method invalid for ParsedGradFunction.
static InputParameters validParams()
Class constructor for the interface.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
const std::vector< std::string > _vars
Variables passed to libMesh::ParsedFunction.
static InputParameters validParams()
Class constructor.
Definition: Function.C:15
static InputParameters validParams()
Class constructor.
unsigned int THREAD_ID
Definition: MooseTypes.h:198