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

Generated by: LCOV version 1.14