Line data Source code
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 : 16 : InputParameters 17 14862 : SolutionAux::validParams() 18 : { 19 14862 : InputParameters params = AuxKernel::validParams(); 20 14862 : params.addClassDescription("Creates fields by using information from a SolutionUserObject."); 21 14862 : params.addRequiredParam<UserObjectName>("solution", "The name of the SolutionUserObject"); 22 14862 : params.addParam<std::string>("from_variable", 23 : "The name of the variable to extract from the file"); 24 : 25 44586 : params.addParam<bool>( 26 : "direct", 27 29724 : false, 28 : "If true the meshes must be the same and then the values are simply copied over."); 29 44586 : params.addParam<Real>( 30 : "scale_factor", 31 29724 : 1.0, 32 : "Scale factor (a) to be applied to the solution (x): ax+b, where b is the 'add_factor'"); 33 44586 : params.addParam<Real>( 34 : "add_factor", 35 29724 : 0.0, 36 : "Add this value (b) to the solution (x): ax+b, where a is the 'scale_factor'"); 37 14862 : return params; 38 0 : } 39 : 40 311 : SolutionAux::SolutionAux(const InputParameters & parameters) 41 : : AuxKernel(parameters), 42 311 : _solution_object(getUserObject<SolutionUserObjectBase>("solution")), 43 311 : _direct(getParam<bool>("direct")), 44 311 : _scale_factor(getParam<Real>("scale_factor")), 45 933 : _add_factor(getParam<Real>("add_factor")) 46 : { 47 311 : } 48 : 49 : void 50 305 : SolutionAux::initialSetup() 51 : { 52 : // If 'from_variable' is supplied, use the value 53 305 : if (isParamValid("from_variable")) 54 104 : _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 201 : const std::vector<std::string> & vars = _solution_object.variableNames(); 61 : 62 : // If there are more than one, throw an error 63 201 : if (vars.size() > 1) 64 4 : 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 197 : _var_name = vars[0]; 69 : } 70 301 : } 71 : 72 : Real 73 612446 : SolutionAux::computeValue() 74 : { 75 : // The value to output 76 : Real output; 77 : 78 : // _direct=true, extract the values using the dof 79 612446 : if (_direct) 80 : { 81 40072 : if (isNodal()) 82 40072 : output = _solution_object.directValue(_current_node, _var_name); 83 : 84 : else 85 0 : output = _solution_object.directValue(_current_elem, _var_name); 86 : } 87 : 88 : // _direct=false, extract the values using time and point 89 : else 90 : { 91 572374 : if (isNodal()) 92 155414 : output = _solution_object.pointValue(_t, *_current_node, _var_name); 93 : 94 : else 95 416960 : output = _solution_object.pointValue(_t, _current_elem->vertex_average(), _var_name); 96 : } 97 : 98 : // Apply factors and return the value 99 612442 : return _scale_factor * output + _add_factor; 100 : }