https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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"
13
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 params.addParam<MooseEnum>(
25 "weighting_type",
27 "The policy used to select a unique value when the imported solution is multivalued and "
28 "direct is false.");
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<SolutionUserObjectBase>("solution")),
47 _weighting_type(isParamSetByUser("weighting_type")
48 ? std::make_optional(getParam<MooseEnum>("weighting_type")
49 .getEnum<SolutionUserObjectBase::WeightingType>())
50 : std::nullopt),
51 _direct(getParam<bool>("direct")),
52 _scale_factor(getParam<Real>("scale_factor")),
53 _add_factor(getParam<Real>("add_factor"))
54{
55}
56
57void
59{
61
62 // If 'from_variable' is supplied, use the value
63 if (isParamValid("from_variable"))
64 _var_name = getParam<std::string>("from_variable");
65
66 // If not, get the value from the SolutionUserObject
67 else
68 {
69 // Get all the variables from the SolutionUserObject
70 const std::vector<std::string> & vars = _solution_object.variableNames();
71
72 // If there are more than one, throw an error
73 if (vars.size() > 1)
74 mooseError("The SolutionUserObject contains multiple variables, please specify the desired "
75 "variables in the input file with 'from_variable' parameter.");
76
77 // Define the variable
78 _var_name = vars[0];
79 }
80
83}
84
85void
93
94void
96{
97 mooseAssert(
99 "The SolutionUserObject must be initialized before validating its imported variable.");
100
103 "from_variable",
104 "The imported variable '",
105 _var_name,
106 "' is vector-valued, but SolutionAux supports only scalar-valued imported variables.");
107
108 // Warn when no explicit weighting policy is provided for a spatially discontinuous variable
112 "weighting_type",
113 "A weighting policy should be specified when the imported variable '",
114 _var_name,
115 "' is spatially discontinuous. Values evaluated on element interfaces may depend on "
116 "source element ordering.");
117
119}
120
121Real
123{
124 // The value to output
125 Real output;
126
127 // _direct=true, extract the values using the dof
128 if (_direct)
129 {
130 if (isNodal())
132
133 else
135 }
136
137 // _direct=false, extract the values using time and point
138 else
139 {
140 const Point p = isNodal() ? Point(*_current_node) : _current_elem->vertex_average();
141
142 if (_weighting_type)
144 else
146 }
147
148 // Apply factors and return the value
149 return _scale_factor * output + _add_factor;
150}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
char ** vars
registerMooseObject("MooseApp", SolutionAux)
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job.
bool isNodal() const
Nodal or elemental kernel?
Definition AuxKernel.h:43
virtual void compute() override
Computes the value and stores it in the solution vector.
Definition AuxKernel.C:143
const Elem *const & _current_elem
Current element (valid only for elemental kernels)
Definition AuxKernel.h:133
const Node *const & _current_node
Current node (valid only for nodal kernels)
Definition AuxKernel.h:143
static InputParameters validParams()
Definition AuxKernel.C:27
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
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...
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 paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
AuxKernel for reading a solution from file.
Definition SolutionAux.h:23
const std::optional< SolutionUserObjectBase::WeightingType > _weighting_type
Policy used when the imported solution is multivalued at the query point.
Definition SolutionAux.h:63
virtual void initialSetup() override
Sets up the variable name for extraction from the SolutionUserObject.
Definition SolutionAux.C:58
void validateVariable()
Validates that the selected imported variable is compatible with this AuxKernel.
Definition SolutionAux.C:95
static InputParameters validParams()
Definition SolutionAux.C:17
bool _variable_is_validated
Whether the imported variable has been validated.
Definition SolutionAux.h:60
const Real _scale_factor
Multiplier for the solution, the a of ax+b.
Definition SolutionAux.h:69
const SolutionUserObjectBase & _solution_object
Reference to the SolutionUserObject storing the solution.
Definition SolutionAux.h:54
virtual Real computeValue() override
Computes a value for a node or element depending on the type of kernel, it also uses the 'direct' fla...
virtual void compute() override
Validates the imported variable once before computing values.
Definition SolutionAux.C:86
bool _direct
Flag for directly grabbing the data based on the dof.
Definition SolutionAux.h:66
std::string _var_name
The variable name of interest.
Definition SolutionAux.h:57
const Real _add_factor
Additional factor added to the solution, the b of ax+b.
Definition SolutionAux.h:72
SolutionAux(const InputParameters &parameters)
Definition SolutionAux.C:44
void paramWarning(const std::string &param, Args... args) const
User object that reads an existing solution from an input file and uses it in the current simulation.
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 isVariableADiscontinuousScalarField(const std::string &var_name) const
Returns whether the imported variable is a discontinuous scalar finite element field.
bool initialized() const
Returns whether the imported solution has been initialized.
bool isVariableScalarValued(const std::string &var_name) const
Returns whether the imported variable has a scalar finite element field type.
const std::vector< std::string > & variableNames() const
Real directValue(const Node *node, const std::string &var_name) const
Return a value directly from a Node.