LCOV - code coverage report
Current view: top level - src/auxkernels - ArrayParsedAux.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 53 55 96.4 %
Date: 2025-07-17 01:28:37 Functions: 3 3 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 "ArrayParsedAux.h"
      11             : #include "MooseApp.h"
      12             : 
      13             : registerMooseObject("MooseApp", ArrayParsedAux);
      14             : 
      15             : InputParameters
      16       14294 : ArrayParsedAux::validParams()
      17             : {
      18       14294 :   InputParameters params = ArrayAuxKernel::validParams();
      19       14294 :   params += FunctionParserUtils<false>::validParams();
      20       14294 :   params.addClassDescription(
      21             :       "Sets field array variable values to the evaluation of a parsed expression.");
      22             : 
      23       14294 :   params.addRequiredCustomTypeParam<std::string>(
      24             :       "expression", "FunctionExpression", "Parsed function expression to compute");
      25       14294 :   params.addCoupledVar("coupled_variables", "Vector of coupled variable names.");
      26       14294 :   params.addCoupledVar("coupled_array_variables", "Vector of coupled array variable names.");
      27             : 
      28       42882 :   params.addParam<bool>(
      29             :       "use_xyzt",
      30       28588 :       false,
      31             :       "Make coordinate (x,y,z) and time (t) variables available in the function expression.");
      32       14294 :   params.addParam<std::vector<std::string>>(
      33             :       "constant_names",
      34             :       {},
      35             :       "Vector of constants used in the parsed function (use this for kB etc.)");
      36       14294 :   params.addParam<std::vector<std::string>>(
      37             :       "constant_expressions",
      38             :       {},
      39             :       "Vector of values for the constants in constant_names (can be an FParser expression)");
      40             : 
      41       14294 :   return params;
      42           0 : }
      43             : 
      44          17 : ArrayParsedAux::ArrayParsedAux(const InputParameters & parameters)
      45             :   : ArrayAuxKernel(parameters),
      46             :     FunctionParserUtils(parameters),
      47          17 :     _function(getParam<std::string>("expression")),
      48          17 :     _n_vars(coupledComponents("coupled_variables")),
      49          17 :     _n_array_vars(coupledComponents("coupled_array_variables")),
      50          17 :     _vars(coupledValues("coupled_variables")),
      51          17 :     _array_vars(coupledArrayValues("coupled_array_variables")),
      52          34 :     _use_xyzt(getParam<bool>("use_xyzt"))
      53             : {
      54             :   // build variables argument
      55          17 :   std::string variables;
      56             : 
      57             :   // coupled field variables
      58          34 :   for (const auto & i : make_range(_n_vars))
      59          17 :     variables += (i == 0 ? "" : ",") + getFieldVar("coupled_variables", i)->name();
      60          43 :   for (const auto & i : make_range(_n_array_vars))
      61             :   {
      62          30 :     const auto & var = *getArrayVar("coupled_array_variables", i);
      63          30 :     if (var.count() != _var.count())
      64           8 :       paramError("coupled_array_variables",
      65             :                  "The number of components in '",
      66           4 :                  _var.name(),
      67             :                  "' (",
      68           4 :                  _var.count(),
      69             :                  ") does not match the number of components in '",
      70           4 :                  var.name(),
      71             :                  "' (",
      72             :                  var.count(),
      73             :                  ").");
      74          26 :     variables += (i == 0 && _n_vars == 0 ? "" : ",") + var.name();
      75             :   }
      76             : 
      77             :   // "system" variables
      78          65 :   const std::vector<std::string> xyzt = {"x", "y", "z", "t"};
      79          13 :   if (_use_xyzt)
      80          65 :     for (auto & v : xyzt)
      81          52 :       variables += (variables.empty() ? "" : ",") + v;
      82             : 
      83             :   // Create parsed function
      84          13 :   _func_F = std::make_shared<SymFunction>();
      85          26 :   parsedFunctionSetup(_func_F,
      86          13 :                       _function,
      87             :                       variables,
      88             :                       getParam<std::vector<std::string>>("constant_names"),
      89             :                       getParam<std::vector<std::string>>("constant_expressions"),
      90             :                       comm());
      91             : 
      92             :   // reserve storage for parameter passing buffer
      93          13 :   _func_params.resize(_n_vars + _n_array_vars + (_use_xyzt ? 4 : 0));
      94          39 : }
      95             : 
      96             : RealEigenVector
      97          88 : ArrayParsedAux::computeValue()
      98             : {
      99             :   // Returned value
     100          88 :   RealEigenVector val(_var.count());
     101             : 
     102             :   // Gather regular variable values
     103         176 :   for (const auto & i : make_range(_n_vars))
     104          88 :     _func_params[i] = (*_vars[i])[_qp];
     105             : 
     106             :   // Gather xyzt values
     107          88 :   if (_use_xyzt)
     108             :   {
     109         352 :     for (const auto j : make_range(Moose::dim))
     110         264 :       _func_params[_n_vars + _n_array_vars + j] =
     111         264 :           isNodal() ? (*_current_node)(j) : _q_point[_qp](j);
     112          88 :     _func_params[_n_vars + _n_array_vars + 3] = _t;
     113             :   }
     114             : 
     115             :   // Loop through each component
     116         264 :   for (const auto & c : make_range(_var.count()))
     117             :   {
     118             :     // Gather array variables
     119         528 :     for (const auto & i : make_range(_n_array_vars))
     120         352 :       _func_params[_n_vars + i] = (*_array_vars[i])[_qp](c);
     121             : 
     122             :     // Evaluate the parsed expression
     123         176 :     val(c) = evaluate(_func_F);
     124             :   }
     125             : 
     126          88 :   return val;
     127           0 : }

Generated by: LCOV version 1.14