<commit_before>//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "ParsedAux.h"

registerMooseObject("MooseApp", ParsedAux);

InputParameters
ParsedAux::validParams()
{
  InputParameters params = AuxKernel::validParams();
  params += FunctionParserUtils<false>::validParams();
  params.addClassDescription("Parsed function AuxKernel.");

  params.addRequiredCustomTypeParam<std::string>(
      "function", "FunctionExpression", "function expression");
  params.addCoupledVar("args", "coupled variables");
  params.addParam<bool>(
      "use_xyzt",
      false,
      "Make coordinate (x,y,z) and time (t) variables available in the function expression.");
  params.addParam<std::vector<std::string>>(
      "constant_names", "Vector of constants used in the parsed function (use this for kB etc.)");
  params.addParam<std::vector<std::string>>(
      "constant_expressions",
      "Vector of values for the constants in constant_names (can be an FParser expression)");

  return params;
}

ParsedAux::ParsedAux(const InputParameters & parameters)
  : AuxKernel(parameters),
    FunctionParserUtils(parameters),
    _function(getParam<std::string>("function")),
    _nargs(coupledComponents("args")),
    _args(coupledValues("args")),
    _use_xyzt(getParam<bool>("use_xyzt"))
{
  // build variables argument
  std::string variables;

  // coupled field variables
  for (std::size_t i = 0; i < _nargs; ++i)
    variables += (i == 0 ? "" : ",") + getVar("args", i)->name();

  // "system" variables
  const std::vector<std::string> xyzt = {"x", "y", "z", "t"};
  if (_use_xyzt)
    for (auto & v : xyzt)
      variables += (variables.empty() ? "" : ",") + v;

  // base function object
  _func_F = std::make_shared<SymFunction>();

  // set FParser interneal feature flags
  setParserFeatureFlags(_func_F);

  // add the constant expressions
  addFParserConstants(_func_F,
                      getParam<std::vector<std::string>>("constant_names"),
                      getParam<std::vector<std::string>>("constant_expressions"));

  // parse function
  if (_func_F->Parse(_function, variables) >= 0)
    mooseError(
        "Invalid function\n", _function, "\nin ParsedAux ", name(), ".\n", _func_F->ErrorMsg());

  // optimize
  if (!_disable_fpoptimizer)<commit_msg>Allow ParsedAux to work with finite volume variables<commit_after>//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "ParsedAux.h"

registerMooseObject("MooseApp", ParsedAux);

InputParameters
ParsedAux::validParams()
{
  InputParameters params = AuxKernel::validParams();
  params += FunctionParserUtils<false>::validParams();
  params.addClassDescription("Parsed function AuxKernel.");

  params.addRequiredCustomTypeParam<std::string>(
      "function", "FunctionExpression", "function expression");
  params.addCoupledVar("args", "coupled variables");
  params.addParam<bool>(
      "use_xyzt",
      false,
      "Make coordinate (x,y,z) and time (t) variables available in the function expression.");
  params.addParam<std::vector<std::string>>(
      "constant_names", "Vector of constants used in the parsed function (use this for kB etc.)");
  params.addParam<std::vector<std::string>>(
      "constant_expressions",
      "Vector of values for the constants in constant_names (can be an FParser expression)");

  return params;
}

ParsedAux::ParsedAux(const InputParameters & parameters)
  : AuxKernel(parameters),
    FunctionParserUtils(parameters),
    _function(getParam<std::string>("function")),
    _nargs(coupledComponents("args")),
    _args(coupledValues("args")),
    _use_xyzt(getParam<bool>("use_xyzt"))
{
  // build variables argument
  std::string variables;

  // coupled field variables
  for (std::size_t i = 0; i < _nargs; ++i)
    variables += (i == 0 ? "" : ",") + getFieldVar("args", i)->name();

  // "system" variables
  const std::vector<std::string> xyzt = {"x", "y", "z", "t"};
  if (_use_xyzt)
    for (auto & v : xyzt)
      variables += (variables.empty() ? "" : ",") + v;

  // base function object
  _func_F = std::make_shared<SymFunction>();

  // set FParser interneal feature flags
  setParserFeatureFlags(_func_F);

  // add the constant expressions
  addFParserConstants(_func_F,
                      getParam<std::vector<std::string>>("constant_names"),
                      getParam<std::vector<std::string>>("constant_expressions"));

  // parse function
  if (_func_F->Parse(_function, variables) >= 0)
    mooseError(
        "Invalid function\n", _function, "\nin ParsedAux ", name(), ".\n", _func_F->ErrorMsg());

  // optimize
  if (!_disable_fpoptimizer)
{'fraction_non_alphanumeric': 0.1543859649122807, 'fraction_numerical': 0.0027290448343079924, 'mean_word_length': 4.151606425702811, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 41, 'https://': 6, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4106602', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1572, 'n_words': 368}