![]() |
GemaCoreLib
The GeMA Core library
|
Class responsible for evaluating a UserFunction over a node / cell. More...
#include <gmUserFunction.h>
Classes | |
class | ParamContext |
Auxiliar class storing the information needed to collect a parameter value. More... | |
Public Member Functions | |
GmUserFunctionEvaluator (const GmUserFunction *ufInfo) | |
Constructor. Gets as parameter the user function definition. More... | |
~GmUserFunctionEvaluator () | |
Destructor. | |
bool | setEvaluationContext (const GmValueInfo *resultInfo, GmSimulationData *simData, const GmMesh *mesh, const GmLogCategory &logger, QString &err) |
Prepares the object to enable function evaluations. More... | |
const double * | eval (int index, const GmVector *coord, int ip, QString &err) const |
Evaluates the function to retrieve data from the node/cell identified by its index. More... | |
const GmUserFunction * | userFunction () const |
Returns the user function associated with this evaluator. | |
Private Types | |
enum | ParamContextType { VALUE_AC_PARAM, CELL_AC_PARAM, GAUSS_AC_PARAM, IPOINT_PARAM, NIPOINT_PARAM, ID_PARAM, MESH_ID_PARAM, CURRENT_TIME_PARAM, DELTA_TIME_PARAM } |
Auxiliar enum to store the type of paramaeter stored in ParamContext. More... | |
Private Member Functions | |
const double * | callFunction (int index, const GmVector *coord, int npars, LuaEnv *env, QString &err) const |
Calls the user function (in Lua or C). Expects parameters to be in place (Lua stack or _input vector) | |
bool | loadCFunction (GmSimulationData *simData, const GmMesh *mesh, QString &err) |
Load internal parameters needed to call a C function. | |
bool | parseParameterType (QString parName, ParamContextType *parType, GmValueInfo **info, QString &err) |
Fills parType and info from the parameter name. On errors, fills err and returns false. | |
bool | acceptsInterpolatorType (const GmCell *c, GmInterpolatorType type) const |
Checks if the given interpolator type is acceptable for the real cell object type. | |
Private Attributes | |
const GmSimulationData * | _simData |
The simulation data object used for retrieving time information. | |
const GmUserFunction * | _functionInfo |
Information about the function that will be evaluated. | |
const GmValueInfo * | _resultInfo |
Information about the expected function result. | |
const GmMesh * | _mesh |
The mesh that will supply function parameters. | |
const GmValueAccessor * | _coordAccessor |
An accessor to read coordinate values needed when interpolating values over cells. | |
bool | _evalNeedsCoord |
Set to true if the function evaluation needs user coordinates. | |
bool | _warnOnInvalidIndex |
Should we emit the invalid index warning? | |
ParamContext * | _parInfo |
A vector with a parameter info for each function parameter. | |
int | _ipRuleSet |
The integration rule set used by gauss attribute parameters or -1 if there is no such parameter type. | |
GmPhysicsUserFunctions * | _cObj |
The object that contains the C method or NULL for Lua functions. | |
GmCUserMethod | _cMethod |
The C method or NULL for Lua functions. | |
GmTLS< GmUserFunctionContext * > * | _cContext |
Per thread context objects passed to C methods or NULL for Lua functions. | |
GmTLS< double ** > * | _input |
Per thread local buffer used to hold input parameters for C functions. | |
GmTLBuffer< double, true > | _result |
Per thread local buffer used to store function results. | |
Friends | |
class | GmUserFunctionContext |
Class responsible for evaluating a UserFunction over a node / cell.
This is an internal implementation class and there should be no real reason for library users to use it directly. All value accesses should be done by the appropriate accessors.
|
private |
Auxiliar enum to store the type of paramaeter stored in ParamContext.
GmUserFunctionEvaluator::GmUserFunctionEvaluator | ( | const GmUserFunction * | ufInfo | ) |
Constructor. Gets as parameter the user function definition.
The object construction must be followed by a call to setEvaluationContext() before the object is able to evaluate values. This is not done in the constructor since setEvaluationContext() must be able to return errors.
const double * GmUserFunctionEvaluator::eval | ( | int | index, |
const GmVector * | coord, | ||
int | ip, | ||
QString & | err | ||
) | const |
Evaluates the function to retrieve data from the node/cell identified by its index.
For node based attributes supporting ghost nodes, expects index to be a linear index.
For cell based functions, coord informs the integration point used for aggregation. This parameter is required only for cell based functions where an aggregation is needed. Otherwise it can be a NULL pointer.
The coordinate values depends on the type of cell. For 'plain' cells, it should be cartesian coordinates. For element cells, it should be natural coordinates.
If the ip parameter is different from -1, it represents the index of the given coordinate in the cell integration rule. It is needed when a Gauss attribute is used as a parameter to a cell function. In that case, if the value is -1 the evaluation processe will try to figure out the corresponding index to the coordinate but that takes some effort.
The calculated value is returned in a vector with size equal to the size reported by the resultInfo object passed as parameter to setEvaluationContext(). This is an internal buffer valid only until the next call to eval().
On errors, returns NULL and reports error through the supplied err parameter. On some warning situations, there can be a warning message on err and a valid result buffer.
bool GmUserFunctionEvaluator::setEvaluationContext | ( | const GmValueInfo * | resultInfo, |
GmSimulationData * | simData, | ||
const GmMesh * | mesh, | ||
const GmLogCategory & | logger, | ||
QString & | err | ||
) |
Prepares the object to enable function evaluations.
The logger parameter is used for creating the needed accessor objects used to evaluate function parameters.
Returns false if the function parameters are incompatible with existing mesh attributes / state vars / properties and reports errors through the err parameter.
Its important to notice that errors are NOT reported through the logger. This is done to achieve a better error message integration with the caller routines.
resultInfo | A valueInfo object detailing the type of result that the evaluated function should return. |
simData | The simulation data |
mesh | The mesh that provides the environment for retrieving function parameters |
logger | The logger used for creating accessor objects |
err | Filled with an error message in case of problems |