LCOV - code coverage report
Current view: top level - src/auxscalarkernels - SolutionScalarAux.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 22 27 81.5 %
Date: 2025-07-17 01:28:37 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          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 "SolutionScalarAux.h"
      12             : #include "SolutionUserObjectBase.h"
      13             : 
      14             : registerMooseObject("MooseApp", SolutionScalarAux);
      15             : 
      16             : InputParameters
      17       14290 : SolutionScalarAux::validParams()
      18             : {
      19       14290 :   InputParameters params = AuxScalarKernel::validParams();
      20       14290 :   params.addClassDescription(
      21             :       "Sets scalar variable by using information from a SolutionUserObject.");
      22       14290 :   params.addRequiredParam<UserObjectName>("solution", "The name of the SolutionUserObject");
      23       14290 :   params.addParam<std::string>("from_variable",
      24             :                                "The name of the variable to extract from the file");
      25       42870 :   params.addParam<Real>(
      26             :       "scale_factor",
      27       28580 :       1.0,
      28             :       "Scale factor (a)  to be applied to the solution (x): ax+b, where b is the 'add_factor'");
      29       42870 :   params.addParam<Real>(
      30             :       "add_factor",
      31       28580 :       0.0,
      32             :       "Add this value (b) to the solution (x): ax+b, where a is the 'scale_factor'");
      33       14290 :   return params;
      34           0 : }
      35             : 
      36          13 : SolutionScalarAux::SolutionScalarAux(const InputParameters & parameters)
      37             :   : AuxScalarKernel(parameters),
      38          13 :     _solution_object(getUserObject<SolutionUserObjectBase>("solution")),
      39          13 :     _scale_factor(getParam<Real>("scale_factor")),
      40          39 :     _add_factor(getParam<Real>("add_factor"))
      41             : {
      42          13 : }
      43             : 
      44             : void
      45          13 : SolutionScalarAux::initialSetup()
      46             : {
      47          13 :   if (isParamValid("from_variable"))
      48          13 :     _var_name = getParam<std::string>("from_variable");
      49             :   else
      50             :   {
      51           0 :     const std::vector<std::string> & vars = _solution_object.variableNames();
      52           0 :     if (vars.size() > 1)
      53           0 :       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           0 :     _var_name = vars[0];
      58             :   }
      59          13 : }
      60             : 
      61             : Real
      62          44 : SolutionScalarAux::computeValue()
      63             : {
      64          44 :   Real value = _solution_object.scalarValue(_t, _var_name);
      65          44 :   return _scale_factor * value + _add_factor;
      66             : }

Generated by: LCOV version 1.14