forked from idaholab/moose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParsedAux.C
109 lines (90 loc) · 3.22 KB
/
ParsedAux.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//* 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)
_func_F->Optimize();
// just-in-time compile
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 + (_use_xyzt ? 4 : 0));
}
Real
ParsedAux::computeValue()
{
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);
}