https://mooseframework.inl.gov
SolutionAux.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 "SolutionUserObjectBase.h"
13 
14 registerMooseObject("MooseApp", SolutionAux);
15 
18 {
20  params.addClassDescription("Creates fields by using information from a SolutionUserObject.");
21  params.addRequiredParam<UserObjectName>("solution", "The name of the SolutionUserObject");
22  params.addParam<std::string>("from_variable",
23  "The name of the variable to extract from the file");
24 
25  params.addParam<bool>(
26  "direct",
27  false,
28  "If true the meshes must be the same and then the values are simply copied over.");
29  params.addParam<Real>(
30  "scale_factor",
31  1.0,
32  "Scale factor (a) to be applied to the solution (x): ax+b, where b is the 'add_factor'");
33  params.addParam<Real>(
34  "add_factor",
35  0.0,
36  "Add this value (b) to the solution (x): ax+b, where a is the 'scale_factor'");
37  return params;
38 }
39 
41  : AuxKernel(parameters),
42  _solution_object(getUserObject<SolutionUserObjectBase>("solution")),
43  _direct(getParam<bool>("direct")),
44  _scale_factor(getParam<Real>("scale_factor")),
45  _add_factor(getParam<Real>("add_factor"))
46 {
47 }
48 
49 void
51 {
52  // If 'from_variable' is supplied, use the value
53  if (isParamValid("from_variable"))
54  _var_name = getParam<std::string>("from_variable");
55 
56  // If not, get the value from the SolutionUserObject
57  else
58  {
59  // Get all the variables from the SolutionUserObject
60  const std::vector<std::string> & vars = _solution_object.variableNames();
61 
62  // If there are more than one, throw an error
63  if (vars.size() > 1)
64  mooseError("The SolutionUserObject contains multiple variables, please specify the desired "
65  "variables in the input file with 'from_variable' parameter.");
66 
67  // Define the variable
68  _var_name = vars[0];
69  }
70 }
71 
72 Real
74 {
75  // The value to output
76  Real output;
77 
78  // _direct=true, extract the values using the dof
79  if (_direct)
80  {
81  if (isNodal())
83 
84  else
86  }
87 
88  // _direct=false, extract the values using time and point
89  else
90  {
91  if (isNodal())
93 
94  else
95  output = _solution_object.pointValue(_t, _current_elem->vertex_average(), _var_name);
96  }
97 
98  // Apply factors and return the value
99  return _scale_factor * output + _add_factor;
100 }
registerMooseObject("MooseApp", SolutionAux)
static InputParameters validParams()
Definition: SolutionAux.C:17
User object that reads an existing solution from an input file and uses it in the current simulation...
const Node *const & _current_node
Current node (valid only for nodal kernels)
Definition: AuxKernel.h:214
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:73
char ** vars
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
SolutionAux(const InputParameters &parameters)
Definition: SolutionAux.C:40
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:50
const Real _add_factor
Additional factor added to the solution, the b of ax+b.
Definition: SolutionAux.h:56
std::string _var_name
The variable name of interest.
Definition: SolutionAux.h:47
const SolutionUserObjectBase & _solution_object
Reference to the SolutionUserObject storing the solution.
Definition: SolutionAux.h:44
const Real _scale_factor
Multiplier for the solution, the a of ax+b.
Definition: SolutionAux.h:53
bool _direct
Flag for directly grabbing the data based on the dof.
Definition: SolutionAux.h:50
Real directValue(const Node *node, const std::string &var_name) const
Return a value directly from a Node.
const std::vector< std::string > & variableNames() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:267
AuxKernel for reading a solution from file.
Definition: SolutionAux.h:22
const Elem *const & _current_elem
Current element (valid only for elemental kernels)
Definition: AuxKernel.h:204
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 optional parameter and a documentation string to the InputParameters object...
static InputParameters validParams()
Definition: AuxKernel.C:27
Base class for creating new auxiliary kernels and auxiliary boundary conditions.
Definition: AuxKernel.h:36
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseBase.h:195
Real pointValue(Real t, const Point &p, const unsigned int local_var_index, const std::set< subdomain_id_type > *subdomain_ids=nullptr) const
Returns a value at a specific location and variable (see SolutionFunction)
bool isNodal() const
Nodal or elemental kernel?
Definition: AuxKernel.h:86