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