Skip to content

Commit

Permalink
Add x,y,z,t to ParsedAux (idaholab#15877)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Oct 5, 2020
1 parent 8af6521 commit 39923b4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
6 changes: 6 additions & 0 deletions framework/include/auxkernels/ParsedAux.h
Expand Up @@ -32,6 +32,12 @@ class ParsedAux : public AuxKernel, public FunctionParserUtils<false>
const unsigned int _nargs;
const std::vector<const VariableValue *> _args;

/// import coordinates and time
const bool _use_xyzt;

/// current simulation time
Real * _time;

/// function parser object for the resudual and on-diagonal Jacobian
SymFunctionPtr _func_F;

Expand Down
37 changes: 33 additions & 4 deletions framework/src/auxkernels/ParsedAux.C
Expand Up @@ -21,6 +21,10 @@ ParsedAux::validParams()
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>>(
Expand All @@ -35,13 +39,22 @@ ParsedAux::ParsedAux(const InputParameters & parameters)
FunctionParserUtils(parameters),
_function(getParam<std::string>("function")),
_nargs(coupledComponents("args")),
_args(coupledValues("args"))
_args(coupledValues("args")),
_use_xyzt(getParam<bool>("use_xyzt"))
{
// build variables argument
std::string variables;
for (unsigned int i = 0; i < _nargs; ++i)

// 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>();

Expand All @@ -66,15 +79,31 @@ ParsedAux::ParsedAux(const InputParameters & parameters)
if (_enable_jit)
_func_F->JITCompile();

// obtain current time
if (_use_xyzt)
{
auto fpb = dynamic_cast<FEProblemBase *>(&_subproblem);
if (!fpb)
mooseError("Cannot access simulation time t. Set '_use_xyzt' to false.");
_time = &fpb->time();
}

// reserve storage for parameter passing bufefr
_func_params.resize(_nargs);
_func_params.resize(_nargs + (_use_xyzt ? 4 : 0));
}

Real
ParsedAux::computeValue()
{
for (unsigned int j = 0; j < _nargs; ++j)
for (std::size_t j = 0; j < _nargs; ++j)
_func_params[j] = (*_args[j])[_qp];

if (_use_xyzt)
{
for (std::size_t j = 0; j < LIBMESH_DIM; ++j)
_func_params[_nargs + j] = isNodal() ? (*_current_node)(j) : _q_point[_qp](j);
_func_params[_nargs + 3] = *_time;
}

return evaluate(_func_F);
}

0 comments on commit 39923b4

Please sign in to comment.