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