LCOV - code coverage report
Current view: top level - src/postprocessors - ParsedPostprocessor.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31706 (f8ed4a) with base bb0a08 Lines: 48 49 98.0 %
Date: 2025-11-03 17:23:24 Functions: 6 6 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 "ParsedPostprocessor.h"
      11             : 
      12             : registerMooseObject("MooseApp", ParsedPostprocessor);
      13             : 
      14             : InputParameters
      15       16449 : ParsedPostprocessor::validParams()
      16             : {
      17       16449 :   InputParameters params = GeneralPostprocessor::validParams();
      18       16449 :   params += FunctionParserUtils<false>::validParams();
      19             : 
      20       98694 :   params.addRequiredCustomTypeParam<std::string>(
      21             :       "expression", "FunctionExpression", "function expression");
      22             : 
      23       65796 :   params.addParam<std::vector<PostprocessorName>>("pp_names", {}, "Post-processors arguments");
      24       65796 :   params.addParam<std::vector<std::string>>(
      25             :       "pp_symbols", {}, "Symbol associated with each post-processor argument");
      26       65796 :   params.addParam<std::vector<std::string>>(
      27             :       "constant_names",
      28             :       {},
      29             :       "Vector of constants used in the parsed function (use this for kB etc.)");
      30       65796 :   params.addParam<std::vector<std::string>>(
      31             :       "constant_expressions",
      32             :       {},
      33             :       "Vector of values for the constants in constant_names (can be an FParser expression)");
      34       49347 :   params.addParam<bool>(
      35       32898 :       "use_t", false, "Make time (t) variable available in the function expression.");
      36             : 
      37       16449 :   params.addClassDescription("Computes a parsed expression with post-processors");
      38       16449 :   return params;
      39           0 : }
      40             : 
      41         773 : ParsedPostprocessor::ParsedPostprocessor(const InputParameters & parameters)
      42             :   : GeneralPostprocessor(parameters),
      43             :     FunctionParserUtils(parameters),
      44         773 :     _n_pp(coupledPostprocessors("pp_names")),
      45        1546 :     _use_t(getParam<bool>("use_t")),
      46        2319 :     _value(0.0)
      47             : {
      48             :   // build postprocessors argument
      49         773 :   std::string postprocessors;
      50             : 
      51        1546 :   const std::vector<std::string> pp_symbols = getParam<std::vector<std::string>>("pp_symbols");
      52             :   // sanity checks
      53         773 :   if (!pp_symbols.empty() && (pp_symbols.size() != _n_pp))
      54           8 :     paramError("pp_symbols", "pp_symbols must be the same length as pp_names.");
      55             : 
      56             :   // coupled  postprocessors with capacity for symbol inputs
      57        1538 :   std::vector<PostprocessorName> pp_names = getParam<std::vector<PostprocessorName>>("pp_names");
      58         769 :   if (pp_symbols.empty())
      59             :   {
      60        2242 :     for (std::size_t i = 0; i < _n_pp; ++i)
      61        1486 :       postprocessors += (i == 0 ? "" : ",") + pp_names[i];
      62             :   }
      63             :   else
      64          26 :     postprocessors = MooseUtils::stringJoin(pp_symbols, ",");
      65             : 
      66             :   // add time if required
      67         769 :   if (_use_t)
      68          52 :     postprocessors += (postprocessors.empty() ? "" : ",") + std::string("t");
      69             : 
      70             :   // Create parsed function
      71         769 :   _func_F = std::make_shared<SymFunction>();
      72        3076 :   parsedFunctionSetup(_func_F,
      73        2307 :                       getParam<std::string>("expression"),
      74             :                       postprocessors,
      75             :                       getParam<std::vector<std::string>>("constant_names"),
      76             :                       getParam<std::vector<std::string>>("constant_expressions"),
      77             :                       comm());
      78             : 
      79             :   // reserve storage for parameter passing buffer
      80         769 :   _func_params.resize(_n_pp + _use_t);
      81         769 :   _pp_values.resize(_n_pp);
      82        2281 :   for (unsigned int i = 0; i < _n_pp; i++)
      83        4536 :     _pp_values[i] = &getPostprocessorValue("pp_names", i);
      84         769 : }
      85             : 
      86             : void
      87        5751 : ParsedPostprocessor::initialize()
      88             : {
      89        5751 : }
      90             : 
      91             : void
      92        5751 : ParsedPostprocessor::execute()
      93             : {
      94        5751 : }
      95             : 
      96             : void
      97        5751 : ParsedPostprocessor::finalize()
      98             : {
      99       16672 :   for (unsigned int i = 0; i < _n_pp; i++)
     100       10921 :     _func_params[i] = *_pp_values[i];
     101             : 
     102        5751 :   if (_use_t)
     103          98 :     _func_params[_n_pp] = _t;
     104             : 
     105       11502 :   _value = evaluate(_func_F);
     106        5751 : }
     107             : 
     108             : PostprocessorValue
     109        5751 : ParsedPostprocessor::getValue() const
     110             : {
     111        5751 :   return _value;
     112             : }

Generated by: LCOV version 1.14