www.mooseframework.org
SolutionFunction.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "MooseError.h"
16 #include "SolutionFunction.h"
17 #include "SolutionUserObject.h"
18 #include "MooseMesh.h"
19 
20 template <>
23 {
24  // Get the Function input parameters
26 
27  // Add required parameters
28  params.addRequiredParam<UserObjectName>("solution",
29  "The SolutionUserObject to extract data from.");
30  params.addParam<std::string>("from_variable",
31  "The name of the variable in the file that is to be extracted");
32 
33  // Add optional paramters
34  params.addParam<Real>(
35  "scale_factor",
36  1.0,
37  "Scale factor (a) to be applied to the solution (x): ax+b, where b is the 'add_factor'");
38  params.addParam<Real>(
39  "add_factor",
40  0.0,
41  "Add this value (b) to the solution (x): ax+b, where a is the 'scale_factor'");
42 
43  // Return the parameters object
44  return params;
45 }
46 
48  : Function(parameters),
49  _solution_object_ptr(NULL),
50  _scale_factor(getParam<Real>("scale_factor")),
51  _add_factor(getParam<Real>("add_factor"))
52 {
53  for (unsigned int d = 0; d < _ti_feproblem.mesh().dimension(); ++d)
55 }
56 
57 void
59 {
60  // Get a pointer to the SolutionUserObject. A pointer is used because the UserObject is not
61  // available during the
62  // construction of the function
63  _solution_object_ptr = &getUserObject<SolutionUserObject>("solution");
64 
65  std::string var_name;
66 
67  // If 'from_variable' is supplied, use the value
68  if (isParamValid("from_variable"))
69  var_name = getParam<std::string>("from_variable");
70 
71  // If not, get the value from the SolutionUserObject
72  else
73  {
74  // Get all the variables from the SolutionUserObject
75  const std::vector<std::string> & vars = _solution_object_ptr->variableNames();
76 
77  // If there are more than one, throw an error
78  if (vars.size() > 1)
79  mooseError("The SolutionUserObject contains multiple variables, the SolutionFunction must "
80  "specifiy the desired variable in the input file with 'from_variable'");
81 
82  // Define the variable
83  var_name = vars[0];
84  }
86 }
87 
88 Real
89 SolutionFunction::value(Real t, const Point & p)
90 {
93 }
94 
96 SolutionFunction::gradient(Real t, const Point & p)
97 {
98  return _scale_factor *
100  _add_grad;
101 }
RealVectorValue RealGradient
Definition: Assembly.h:43
RealGradient pointValueGradient(Real t, const Point &p, const std::string &var_name) const
Returns the gradient at a specific location and variable (see SolutionFunction)
Base class for function objects.
Definition: Function.h:46
FEProblemBase & _ti_feproblem
virtual unsigned int dimension() const
Returns MeshBase::mesh_dimsension(), (not MeshBase::spatial_dimension()!) of the underlying libMesh m...
Definition: MooseMesh.C:1984
virtual Real value(Real t, const Point &p) override
Extract a value from the solution.
RealGradient _add_grad
Factor to add to the solution if gradient is requested (default = {0})
virtual RealGradient gradient(Real t, const Point &p) override
Extract a gradient from the solution.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const SolutionUserObject * _solution_object_ptr
Pointer to SolutionUserObject containing the solution of interest.
InputParameters validParams< SolutionFunction >()
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
Real pointValue(Real t, const Point &p, const unsigned int local_var_index) const
Returns a value at a specific location and variable (see SolutionFunction)
const Real _scale_factor
Factor to scale the solution by (default = 1)
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseObject.h:67
const Real _add_factor
Factor to add to the solution (default = 0)
unsigned int _solution_object_var_index
The local SolutionUserObject index for the variable extracted from the file.
virtual MooseMesh & mesh() override
SolutionFunction(const InputParameters &parameters)
Constructor.
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...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
InputParameters validParams< Function >()
Definition: Function.C:19
unsigned int getLocalVarIndex(const std::string &var_name) const
Returns the local index for a given variable name.
const std::vector< std::string > & variableNames() const
virtual void initialSetup() override
Setup the function for use Gathers a pointer to the SolutionUserObject containing the solution that w...