GemaCoreLib
The GeMA Core library
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
GmUserFunctionEvaluator Class Reference

Class responsible for evaluating a UserFunction over a node / cell. More...

#include <gmUserFunction.h>

Collaboration diagram for GmUserFunctionEvaluator:
Collaboration graph
[legend]

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 GmUserFunctionuserFunction () 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
 

Detailed Description

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.

Member Enumeration Documentation

◆ ParamContextType

Auxiliar enum to store the type of paramaeter stored in ParamContext.

Enumerator
VALUE_AC_PARAM 

The parameter is the result of a node attribute / state var / coordinate accessor.

CELL_AC_PARAM 

The parameter is the result of a cell attribute / property accessor.

GAUSS_AC_PARAM 

The parameter is the result of a gauss attribute accessor.

IPOINT_PARAM 

The parameter should return the integration point cartesian coordinates.

NIPOINT_PARAM 

The parameter should return the integration point natural coordinates.

ID_PARAM 

The parameter should return the node / cell Id.

MESH_ID_PARAM 

The parameter should return the mesh name (Lua functions only)

CURRENT_TIME_PARAM 

The parameter should return the current time.

DELTA_TIME_PARAM 

The parameter should return the difference from the current time to the last one.

Constructor & Destructor Documentation

◆ GmUserFunctionEvaluator()

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.

Member Function Documentation

◆ eval()

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.

◆ setEvaluationContext()

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.

Parameters
resultInfoA valueInfo object detailing the type of result that the evaluated function should return.
simDataThe simulation data
meshThe mesh that provides the environment for retrieving function parameters
loggerThe logger used for creating accessor objects
errFilled with an error message in case of problems
Returns
Returns false on errors

The documentation for this class was generated from the following files: