https://mooseframework.inl.gov
SolutionScalarAux.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 "SolutionScalarAux.h"
12 #include "SolutionUserObjectBase.h"
13 
15 
18 {
20  params.addClassDescription(
21  "Sets scalar variable 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  params.addParam<Real>(
26  "scale_factor",
27  1.0,
28  "Scale factor (a) to be applied to the solution (x): ax+b, where b is the 'add_factor'");
29  params.addParam<Real>(
30  "add_factor",
31  0.0,
32  "Add this value (b) to the solution (x): ax+b, where a is the 'scale_factor'");
33  return params;
34 }
35 
37  : AuxScalarKernel(parameters),
38  _solution_object(getUserObject<SolutionUserObjectBase>("solution")),
39  _scale_factor(getParam<Real>("scale_factor")),
40  _add_factor(getParam<Real>("add_factor"))
41 {
42 }
43 
44 void
46 {
47  if (isParamValid("from_variable"))
48  _var_name = getParam<std::string>("from_variable");
49  else
50  {
51  const std::vector<std::string> & vars = _solution_object.variableNames();
52  if (vars.size() > 1)
53  mooseError(name(),
54  ": The SolutionUserObject contains multiple variables, please specifiy the "
55  "desired variable in the input file using the 'from_variable' parameter.");
56 
57  _var_name = vars[0];
58  }
59 }
60 
61 Real
63 {
65  return _scale_factor * value + _add_factor;
66 }
SolutionScalarAux(const InputParameters &parameters)
User object that reads an existing solution from an input file and uses it in the current simulation...
const Real _scale_factor
Multiplier for the solution, the a of ax+b.
virtual Real computeValue() override
Compute the value of this kernel.
char ** vars
const SolutionUserObjectBase & _solution_object
Reference to the SolutionUserObject storing the solution.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::string _var_name
The variable name of interest.
const Real _add_factor
Additional factor added to the solution, the b of ax+b.
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...
registerMooseObject("MooseApp", SolutionScalarAux)
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:99
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
AuxScalarKernel for reading a solution from file.
Base class for making kernels that work on auxiliary scalar variables.
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job...
Real scalarValue(Real t, const std::string &var_name) const
Returns a value of a global variable.
const std::vector< std::string > & variableNames() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static InputParameters validParams()
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
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...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseBase.h:195
static InputParameters validParams()