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 3775 : SolutionAux::validParams() 18 : { 19 3775 : InputParameters params = AuxKernel::validParams(); 20 7550 : params.addClassDescription("Creates fields by using information from a SolutionUserObject."); 21 15100 : params.addRequiredParam<UserObjectName>("solution", "The name of the SolutionUserObject"); 22 15100 : params.addParam<std::string>("from_variable", 23 : "The name of the variable to extract from the file"); 24 : 25 11325 : params.addParam<bool>( 26 : "direct", 27 7550 : false, 28 : "If true the meshes must be the same and then the values are simply copied over."); 29 11325 : params.addParam<Real>( 30 : "scale_factor", 31 7550 : 1.0, 32 : "Scale factor (a) to be applied to the solution (x): ax+b, where b is the 'add_factor'"); 33 7550 : params.addParam<Real>( 34 : "add_factor", 35 7550 : 0.0, 36 : "Add this value (b) to the solution (x): ax+b, where a is the 'scale_factor'"); 37 3775 : return params; 38 0 : } 39 : 40 372 : SolutionAux::SolutionAux(const InputParameters & parameters) 41 : : AuxKernel(parameters), 42 372 : _solution_object(getUserObject<SolutionUserObjectBase>("solution")), 43 744 : _direct(getParam<bool>("direct")), 44 744 : _scale_factor(getParam<Real>("scale_factor")), 45 1488 : _add_factor(getParam<Real>("add_factor")) 46 : { 47 372 : } 48 : 49 : void 50 367 : SolutionAux::initialSetup() 51 : { 52 367 : AuxKernel::initialSetup(); 53 : 54 : // If 'from_variable' is supplied, use the value 55 1101 : if (isParamValid("from_variable")) 56 507 : _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 198 : const std::vector<std::string> & vars = _solution_object.variableNames(); 63 : 64 : // If there are more than one, throw an error 65 198 : if (vars.size() > 1) 66 3 : mooseError("The SolutionUserObject contains multiple variables, please specify the desired " 67 : "variables in the input file with 'from_variable' parameter."); 68 : 69 : // Define the variable 70 195 : _var_name = vars[0]; 71 : } 72 364 : } 73 : 74 : Real 75 621344 : SolutionAux::computeValue() 76 : { 77 : // The value to output 78 : Real output; 79 : 80 : // _direct=true, extract the values using the dof 81 621344 : if (_direct) 82 : { 83 40572 : if (isNodal()) 84 40572 : output = _solution_object.directValue(_current_node, _var_name); 85 : 86 : else 87 0 : output = _solution_object.directValue(_current_elem, _var_name); 88 : } 89 : 90 : // _direct=false, extract the values using time and point 91 : else 92 : { 93 580772 : if (isNodal()) 94 158372 : output = _solution_object.pointValue(_t, *_current_node, _var_name); 95 : 96 : else 97 422400 : output = _solution_object.pointValue(_t, _current_elem->vertex_average(), _var_name); 98 : } 99 : 100 : // Apply factors and return the value 101 621342 : return _scale_factor * output + _add_factor; 102 : }