LCOV - code coverage report
Current view: top level - include/auxkernels - ParsedAux.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 11 11 100.0 %
Date: 2025-07-17 01:28:37 Functions: 2 2 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             : #pragma once
      11             : 
      12             : #include "AuxKernel.h"
      13             : #include "FunctionParserUtils.h"
      14             : 
      15             : /**
      16             :  * AuxKernel that evaluates a parsed function expression
      17             :  */
      18             : class ParsedAux : public AuxKernel, public FunctionParserUtils<false>
      19             : {
      20             : public:
      21             :   static InputParameters validParams();
      22             : 
      23             :   ParsedAux(const InputParameters & parameters);
      24             : 
      25             : protected:
      26             :   virtual Real computeValue() override;
      27             : 
      28             :   /// Function to validate the symbols in _functor_symbols
      29             :   void validateFunctorSymbols();
      30             : 
      31             :   /// Function to validate the names in _functor_names
      32             :   void validateFunctorNames();
      33             : 
      34             :   /**
      35             :    * Function to ensure vector entries (names) do not overlap with xyzt or coupled variable names.
      36             :    * @param names_vec Vector containing names to compare to xyzt and coupled variables names.
      37             :    * @param param_name Name of the parameter corresponding to names_vec. This will be the paremeter
      38             :    * errored on, if applicable.
      39             :    */
      40             :   template <typename T>
      41             :   void validateGenericVectorNames(const std::vector<T> & names_vec, const std::string & param_name);
      42             : 
      43             :   /// function expression
      44             :   std::string _function;
      45             : 
      46             :   /// coupled variables
      47             :   const unsigned int _nargs;
      48             :   const std::vector<const VariableValue *> _args;
      49             : 
      50             :   /// material properties
      51             :   const std::vector<MaterialPropertyName> & _matprop_names;
      52             :   const std::vector<MaterialPropertyName> & _ad_matprop_names;
      53             :   const unsigned int _n_matprops;
      54             :   const unsigned int _n_ad_matprops;
      55             :   std::vector<const MaterialProperty<Real> *> _matprops;
      56             :   std::vector<const ADMaterialProperty<Real> *> _ad_matprops;
      57             : 
      58             :   /// import coordinates and time
      59             :   const bool _use_xyzt;
      60             : 
      61             :   /// coordinate and time variable names
      62             :   const std::vector<std::string> _xyzt;
      63             : 
      64             :   /// function parser object to compute the local value of the aux-variable
      65             :   SymFunctionPtr _func_F;
      66             : 
      67             :   usingFunctionParserUtilsMembers(false);
      68             : 
      69             :   /// Functors to use in the parsed expression
      70             :   const std::vector<MooseFunctorName> & _functor_names;
      71             : 
      72             :   /// Number of functors
      73             :   const unsigned int _n_functors;
      74             : 
      75             :   /// Symbolic name to use for each functor
      76             :   const std::vector<std::string> _functor_symbols;
      77             : 
      78             :   /// Vector of pointers to functors
      79             :   std::vector<const Moose::Functor<Real> *> _functors;
      80             : 
      81             :   /// Vector of coupled variable names
      82             :   std::vector<std::string> _coupled_variable_names;
      83             : };
      84             : 
      85             : template <typename T>
      86             : void
      87        2526 : ParsedAux::validateGenericVectorNames(const std::vector<T> & names_vec,
      88             :                                       const std::string & param_name)
      89             : {
      90        2672 :   for (const auto & name : names_vec)
      91             :   {
      92             :     // Make sure symbol is not x, y, z, or t
      93         162 :     if (_use_xyzt && (std::find(_xyzt.begin(), _xyzt.end(), name) != _xyzt.end()))
      94           8 :       paramError(
      95             :           param_name,
      96             :           "x, y, z, and t cannot be used in '" + param_name + "' when use_xyzt=true." +
      97           8 :               (param_name == "functor_names" ? " Use 'functor_symbols' to disambiguate." : ""));
      98             :     // Make sure symbol is not a coupled variable name
      99         162 :     if (_coupled_variable_names.size() &&
     100           8 :         (std::find(_coupled_variable_names.begin(), _coupled_variable_names.end(), name) !=
     101         162 :          _coupled_variable_names.end()))
     102           8 :       paramError(
     103             :           param_name,
     104             :           "Values in '" + param_name + "' cannot overlap with coupled variable names." +
     105           8 :               (param_name == "functor_names" ? " Use 'functor_symbols' to disambiguate." : ""));
     106             :   }
     107        2510 : }

Generated by: LCOV version 1.14