LCOV - code coverage report
Current view: top level - src/postprocessors - LinearCombinationPostprocessor.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 25 27 92.6 %
Date: 2025-07-17 01:28:37 Functions: 5 5 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 "LinearCombinationPostprocessor.h"
      11             : 
      12             : registerMooseObject("MooseApp", LinearCombinationPostprocessor);
      13             : 
      14             : InputParameters
      15       14361 : LinearCombinationPostprocessor::validParams()
      16             : {
      17       14361 :   InputParameters params = GeneralPostprocessor::validParams();
      18             : 
      19       14361 :   params.addRequiredParam<std::vector<PostprocessorName>>("pp_names", "List of post-processors");
      20       14361 :   params.addRequiredParam<std::vector<Real>>(
      21             :       "pp_coefs", "List of linear combination coefficients for each post-processor");
      22       14361 :   params.addParam<Real>("b", 0, "Additional value to add to sum");
      23       14361 :   params.addClassDescription(
      24             :       "Computes a linear combination between an arbitrary number of post-processors");
      25       14361 :   return params;
      26           0 : }
      27             : 
      28          48 : LinearCombinationPostprocessor::LinearCombinationPostprocessor(const InputParameters & parameters)
      29             :   : GeneralPostprocessor(parameters),
      30          48 :     _n_pp(coupledPostprocessors("pp_names")),
      31          48 :     _pp_coefs(getParam<std::vector<Real>>("pp_coefs")),
      32          96 :     _b_value(getParam<Real>("b"))
      33             : {
      34          48 :   if (_pp_coefs.size() != _n_pp)
      35           0 :     mooseError("The list parameters 'pp_names' and 'pp_coefs' must have the same length");
      36             : 
      37          48 :   _pp_values.resize(_n_pp);
      38          96 :   for (unsigned int i = 0; i < _n_pp; i++)
      39          48 :     _pp_values[i] = &getPostprocessorValue("pp_names", i);
      40          48 : }
      41             : 
      42             : void
      43          44 : LinearCombinationPostprocessor::initialize()
      44             : {
      45          44 : }
      46             : 
      47             : void
      48          44 : LinearCombinationPostprocessor::execute()
      49             : {
      50          44 : }
      51             : 
      52             : PostprocessorValue
      53          44 : LinearCombinationPostprocessor::getValue() const
      54             : {
      55          44 :   Real linear_combination = _b_value;
      56          88 :   for (unsigned int i = 0; i < _n_pp; i++)
      57          44 :     linear_combination += _pp_coefs[i] * *(_pp_values[i]);
      58             : 
      59          44 :   return linear_combination;
      60             : }

Generated by: LCOV version 1.14