LCOV - code coverage report
Current view: top level - src/auxkernels - ParsedVectorAux.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 63 66 95.5 %
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 "ParsedVectorAux.h"
      11             : #include "MooseApp.h"
      12             : 
      13             : registerMooseObject("MooseApp", ParsedVectorAux);
      14             : 
      15             : InputParameters
      16       14340 : ParsedVectorAux::validParams()
      17             : {
      18       14340 :   InputParameters params = VectorAuxKernel::validParams();
      19       14340 :   params += FunctionParserUtils<false>::validParams();
      20       14340 :   params.addClassDescription(
      21             :       "Sets a field vector variable value to the evaluation of a parsed expression.");
      22             : 
      23       14340 :   params.addRequiredCustomTypeParam<std::string>(
      24             :       "expression_x",
      25             :       "FunctionExpression",
      26             :       "Parsed function expression to compute the x component");
      27       14340 :   params.addCustomTypeParam<std::string>("expression_y",
      28             :                                          "0",
      29             :                                          "FunctionExpression",
      30             :                                          "Parsed function expression to compute the y component");
      31             :   if constexpr (LIBMESH_DIM >= 3)
      32       14340 :     params.addCustomTypeParam<std::string>("expression_z",
      33             :                                            "0",
      34             :                                            "FunctionExpression",
      35             :                                            "Parsed function expression to compute the z component");
      36       14340 :   params.addCoupledVar("coupled_variables", "Vector of coupled variable names");
      37       14340 :   params.addCoupledVar("coupled_vector_variables", "Vector of coupled variable names");
      38             : 
      39       43020 :   params.addParam<bool>(
      40             :       "use_xyzt",
      41       28680 :       false,
      42             :       "Make coordinate (x,y,z) and time (t) variables available in the function expression.");
      43       14340 :   params.addParam<std::vector<std::vector<std::string>>>(
      44             :       "constant_names", "Vector of constants used in the parsed function (use this for kB etc.)");
      45       14340 :   params.addParam<std::vector<std::vector<std::string>>>(
      46             :       "constant_expressions",
      47             :       "Vector of values for the constants in constant_names (can be an FParser expression)");
      48             : 
      49       14340 :   return params;
      50           0 : }
      51             : 
      52          39 : ParsedVectorAux::ParsedVectorAux(const InputParameters & parameters)
      53             :   : VectorAuxKernel(parameters),
      54             :     FunctionParserUtils(parameters),
      55         156 :     _function({getParam<std::string>("expression_x"),
      56             :                getParam<std::string>("expression_y"),
      57             :                getParam<std::string>("expression_z")}),
      58          39 :     _nargs(coupledComponents("coupled_variables")),
      59          39 :     _n_vector_args(coupledComponents("coupled_vector_variables")),
      60          39 :     _args(coupledValues("coupled_variables")),
      61          39 :     _vector_args(coupledVectorValues("coupled_vector_variables")),
      62          78 :     _use_xyzt(getParam<bool>("use_xyzt"))
      63             : {
      64          39 :   _func_F.resize(LIBMESH_DIM);
      65          39 :   _function.resize(LIBMESH_DIM);
      66             : 
      67         156 :   for (const auto i : make_range(Moose::dim))
      68             :   {
      69             :     // build variables argument
      70         117 :     std::string variables;
      71             : 
      72             :     // coupled regular field variables
      73         234 :     for (const auto i : make_range(_nargs))
      74         117 :       variables += (i == 0 ? "" : ",") + getFieldVar("coupled_variables", i)->name();
      75             : 
      76             :     // coupled vector field variables
      77         273 :     for (const auto i : make_range(_n_vector_args))
      78             :       variables +=
      79         156 :           (variables.empty() ? "" : ",") + getFieldVar("coupled_vector_variables", i)->name();
      80             : 
      81             :     // "system" variables
      82         585 :     const std::vector<std::string> xyzt = {"x", "y", "z", "t"};
      83         117 :     if (_use_xyzt)
      84         390 :       for (auto & v : xyzt)
      85         312 :         variables += (variables.empty() ? "" : ",") + v;
      86             : 
      87             :     // base function object
      88         117 :     _func_F[i] = std::make_shared<SymFunction>();
      89             : 
      90             :     // add the constant expressions
      91         234 :     auto constant_names = isParamValid("constant_names")
      92         117 :                               ? getParam<std::vector<std::vector<std::string>>>("constant_names")
      93         117 :                               : std::vector<std::vector<std::string>>{};
      94             :     auto constant_expressions =
      95         234 :         isParamValid("constant_expressions")
      96         117 :             ? getParam<std::vector<std::vector<std::string>>>("constant_expressions")
      97         117 :             : std::vector<std::vector<std::string>>{};
      98         117 :     if (constant_names.size() && i > constant_names.size())
      99           0 :       paramError("constant_names",
     100             :                  "Constant names must be specified for each component. Use ';' for outer-indexing "
     101             :                  "of double-indexed vector of constants.");
     102         117 :     if (constant_expressions.size() && i > constant_expressions.size())
     103           0 :       paramError("constant_expressions",
     104             :                  "Constant expressions must be specified for each component. Use ';' for "
     105             :                  "outer-indexing of double-indexed vector of constants.");
     106         117 :     const std::vector<std::string> empty_vec{};
     107         117 :     const auto names = constant_names.size() ? constant_names[i] : empty_vec;
     108         117 :     const auto expressions = constant_expressions.size() ? constant_expressions[i] : empty_vec;
     109             : 
     110             :     // Create parsed function for the component
     111         117 :     parsedFunctionSetup(_func_F[i], _function[i], variables, names, expressions, comm());
     112         117 :   }
     113             :   // reserve storage for parameter passing buffer
     114          39 :   _func_params.resize(_nargs + _n_vector_args + (_use_xyzt ? 4 : 0));
     115         351 : }
     116             : 
     117             : RealVectorValue
     118        3672 : ParsedVectorAux::computeValue()
     119             : {
     120        3672 :   RealVectorValue value;
     121       14688 :   for (const auto i : make_range(Moose::dim))
     122             :   {
     123       22032 :     for (const auto j : make_range(_nargs))
     124       11016 :       _func_params[j] = (*_args[j])[_qp];
     125             : 
     126       30648 :     for (const auto j : make_range(_n_vector_args))
     127       19632 :       _func_params[_nargs + j] = (*_vector_args[j])[_qp](i);
     128             : 
     129       11016 :     if (_use_xyzt)
     130             :     {
     131       39264 :       for (const auto j : make_range(Moose::dim))
     132       29448 :         _func_params[_nargs + _n_vector_args + j] =
     133       29448 :             isNodal() ? (*_current_node)(j) : _q_point[_qp](j);
     134        9816 :       _func_params[_nargs + _n_vector_args + 3] = _t;
     135             :     }
     136       11016 :     value(i) = evaluate(_func_F[i]);
     137             :   }
     138        3672 :   return value;
     139             : }

Generated by: LCOV version 1.14