www.mooseframework.org
SolutionAux.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 "SolutionAux.h"
17 #include "SolutionUserObject.h"
18 
19 template <>
22 {
24  params.addClassDescription("Creates fields by using information from a SolutionUserObject.");
25  params.addRequiredParam<UserObjectName>("solution", "The name of the SolutionUserObject");
26  params.addParam<std::string>("from_variable",
27  "The name of the variable to extract from the file");
28 
29  params.addParam<bool>(
30  "direct",
31  false,
32  "If true the meshes must be the same and then the values are simply copied over.");
33  params.addParam<Real>(
34  "scale_factor",
35  1.0,
36  "Scale factor (a) to be applied to the solution (x): ax+b, where b is the 'add_factor'");
37  params.addParam<Real>(
38  "add_factor",
39  0.0,
40  "Add this value (b) to the solution (x): ax+b, where a is the 'scale_factor'");
41  return params;
42 }
43 
45  : AuxKernel(parameters),
46  _solution_object(getUserObject<SolutionUserObject>("solution")),
47  _direct(getParam<bool>("direct")),
48  _scale_factor(getParam<Real>("scale_factor")),
49  _add_factor(getParam<Real>("add_factor"))
50 {
51 }
52 
53 void
55 {
56  // If 'from_variable' is supplied, use the value
57  if (isParamValid("from_variable"))
58  _var_name = getParam<std::string>("from_variable");
59 
60  // If not, get the value from the SolutionUserObject
61  else
62  {
63  // Get all the variables from the SolutionUserObject
64  const std::vector<std::string> & vars = _solution_object.variableNames();
65 
66  // If there are more than one, throw an error
67  if (vars.size() > 1)
68  mooseError("The SolutionUserObject contains multiple variables, in this case the "
69  "SolutionFunction must specifiy the desired variable in the input file with "
70  "'from_variable'");
71 
72  // Define the variable
73  _var_name = vars[0];
74  }
75 
76  // Determine if 'from_variable' is elemental, if so then use direct extraction
78  _direct = true;
79 }
80 
81 Real
83 {
84  // The value to output
85  Real output;
86 
87  // _direct=true, extract the values using the dof
88  if (_direct)
89  {
90  if (isNodal())
92 
93  else
95  }
96 
97  // _direct=false, extract the values using time and point
98  else
99  {
100  if (isNodal())
102 
103  else
104  output = _solution_object.pointValue(_t, _current_elem->centroid(), _var_name);
105  }
106 
107  // Apply factors and return the value
108  return _scale_factor * output + _add_factor;
109 }
InputParameters validParams< SolutionAux >()
Definition: SolutionAux.C:21
virtual Real computeValue() override
Computes a value for a node or element depending on the type of kernel, it also uses the &#39;direct&#39; fla...
Definition: SolutionAux.C:82
const SolutionUserObject & _solution_object
Reference to the SolutionUserObject storing the solution.
Definition: SolutionAux.h:53
const Elem *& _current_elem
Current element (valid only for elemental kernels)
Definition: AuxKernel.h:176
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
bool isVariableNodal(const std::string &var_name) const
SolutionAux(const InputParameters &parameters)
Definition: SolutionAux.C:44
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...
virtual void initialSetup() override
Sets up the variable name for extraction from the SolutionUserObject.
Definition: SolutionAux.C:54
const Real _add_factor
Additional factor added to the solution, the b of ax+b.
Definition: SolutionAux.h:65
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)
std::string _var_name
The variable name of interest.
Definition: SolutionAux.h:56
Real directValue(const Node *node, const std::string &var_name) const
Return a value directly from a Node.
const Real _scale_factor
Multiplier for the solution, the a of ax+b.
Definition: SolutionAux.h:62
InputParameters validParams< AuxKernel >()
Definition: AuxKernel.C:30
const Node *& _current_node
Current node (valid only for nodal kernels)
Definition: AuxKernel.h:186
bool isNodal()
Nodal or elemental kernel?
Definition: AuxKernel.h:89
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseObject.h:67
bool _direct
Flag for directly grabbing the data based on the dof.
Definition: SolutionAux.h:59
Base class for creating new auxiliary kernels and auxiliary boundary conditions.
Definition: AuxKernel.h:51
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...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
const std::vector< std::string > & variableNames() const
User object that reads an existing solution from an input file and uses it in the current simulation...