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 
15 template <>
18 {
21  params.addParam<std::string>("value", "0", "User defined function.");
22  params.addParam<std::string>("grad_x", "0", "Partial with respect to x.");
23  params.addParam<std::string>("grad_y", "0", "Partial with respect to y.");
24  params.addParam<std::string>("grad_z", "0", "Partial with respect to z.");
25  return params;
26 }
27 
29  : Function(parameters),
30  MooseParsedFunctionBase(parameters),
31  _value(verifyFunction(getParam<std::string>("value"))),
32  _grad_value(verifyFunction(std::string("{") + getParam<std::string>("grad_x") + "}{" +
33  getParam<std::string>("grad_y") + "}{" +
34  getParam<std::string>("grad_z") + "}"))
35 {
36 }
37 
39 
40 Real
41 MooseParsedGradFunction::value(Real t, const Point & p)
42 {
43  // Return a scalar value
44  return _function_ptr->evaluate<Real>(t, p);
45 }
46 
47 RealGradient
48 MooseParsedGradFunction::gradient(Real t, const Point & p)
49 {
50  // Return gradient (RealGradient = RealVectorValue)
51  return _grad_function_ptr->evaluate<RealVectorValue>(t, p);
52 }
53 
55 MooseParsedGradFunction::vectorValue(Real /*t*/, const Point & /*p*/)
56 {
57  mooseError("The vectorValue method is not defined in ParsedGradFunction");
58 }
59 
60 void
62 {
63  THREAD_ID tid = 0;
64  if (isParamValid("_tid"))
65  tid = getParam<THREAD_ID>("_tid");
66 
67  if (!_function_ptr)
69  libmesh_make_unique<MooseParsedFunctionWrapper>(_pfb_feproblem, _value, _vars, _vals, tid);
70 
71  if (!_grad_function_ptr)
72  _grad_function_ptr = libmesh_make_unique<MooseParsedFunctionWrapper>(
74 }
std::unique_ptr< MooseParsedFunctionWrapper > _function_ptr
Pointer to the Parsed function wrapper object for the scalar.
Base class for function objects.
Definition: Function.h:40
Adds user facing parameters for parsed function.
VectorValue< Real > RealVectorValue
Definition: Assembly.h:31
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.
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
MooseParsedGradFunction(const InputParameters &parameters)
Class constructor.
virtual void initialSetup() override
Creates two libMesh::ParsedFunction objects for returning a vector via the &#39;gradient&#39; method and a sc...
virtual RealGradient gradient(Real t, const Point &p) override
Compute the gradient of the function.
std::string _grad_value
String for the gradient, vector function string.
virtual Real value(Real t, const Point &p) override
Return a scalar value from the function.
InputParameters validParams< MooseParsedGradFunction >()
registerMooseObjectAliased("MooseApp", MooseParsedGradFunction, "ParsedGradFunction")
InputParameters validParams< MooseParsedFunctionBase >()
Creates the &#39;vars&#39; and &#39;vals&#39; parameters used by all ParsedFunctions, the parameters provided from th...
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.
virtual RealVectorValue vectorValue(Real t, const Point &p) override
Method invalid for ParsedGradFunction.
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.
InputParameters validParams< Function >()
Definition: Function.C:14
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseObject.h:89
unsigned int THREAD_ID
Definition: MooseTypes.h:161