ug4
|
maps several data values to an output data value using a lua callback More...
#include <lua_user_data.h>
Public Types | |
typedef StdDataLinker< LuaUserFunction< TData, dim, TDataIn >, TData, dim > | base_type |
![]() | |
typedef ICplUserData< dim > | base_type |
type of base class | |
![]() | |
typedef TData | data_type |
typedef TRet | return_type |
Public Member Functions | |
template<int refDim> | |
void | eval_and_deriv (TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< refDim > vLocIP[], const size_t nip, LocalVector *u, bool bDeriv, int s, std::vector< std::vector< TData > > vvvDeriv[], const MathMatrix< refDim, dim > *vJT=NULL) |
void | evaluate (TData &value, const MathVector< dim > &globIP, number time, int si) const |
template<int refDim> | |
void | evaluate (TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< refDim > vLocIP[], const size_t nip, LocalVector *u, const MathMatrix< refDim, dim > *vJT=NULL) const |
virtual void | operator() (TData &out, int numArgs,...) const |
evaluates the data | |
void | set_deriv (size_t arg, const char *luaCallback) |
sets the Lua function used to compute the derivative | |
void | set_deriv (size_t arg, LuaFunctionHandle handle) |
void | set_input_and_deriv (size_t i, SmartPtr< CplUserData< TDataIn, dim > > input, LuaFunctionHandle deriv) |
void | set_num_input (size_t num) |
set number of needed inputs | |
virtual | ~LuaUserFunction () |
destructor frees the reference | |
LuaUserFunction (const char *luaCallback, size_t numArgs) | |
constructor | |
LuaUserFunction (const char *luaCallback, size_t numArgs, bool bPosTimeNeed) | |
constructor | |
LuaUserFunction (LuaFunctionHandle handle, size_t numArgs) | |
constructor | |
LuaUserFunction (LuaFunctionHandle handle, size_t numArgs, bool bPosTimeNeed) | |
constructor | |
void | set_input (size_t i, SmartPtr< CplUserData< TDataIn, dim > > data) |
set input value for paramter i | |
void | set_input (size_t i, number val) |
set input value for paramter i | |
![]() | |
virtual void | check_setup () const |
returns if data is ok | |
virtual void | compute (LocalVector *u, GridObject *elem, const MathVector< dim > vCornerCoords[], bool bDeriv=false) |
compute values (and derivatives iff compDeriv == true) | |
virtual void | compute (LocalVectorTimeSeries *u, GridObject *elem, const MathVector< dim > vCornerCoords[], bool bDeriv=false) |
compute values (and derivatives iff compDeriv == true, but only for the 'current' time point) | |
virtual bool | continuous () const |
returns if provided data is continuous over geometric object boundaries | |
void | evaluate (TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< refDim > vLocIP[], const size_t nip, LocalVector *u, const MathMatrix< refDim, dim > *vJT=NULL) const |
virtual SmartPtr< ICplUserData< dim > > | needed_data (size_t i) |
return needed data | |
virtual size_t | num_input () const |
number of inputs | |
virtual size_t | num_needed_data () const |
number of other Data this data depends on | |
virtual void | operator() (TData &value, const MathVector< dim > &globIP, number time, int si) const |
returns value for a global position | |
virtual void | operator() (TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, const size_t nip) const |
returns value for global positions | |
virtual bool | requires_grid_fct () const |
returns that a grid function is needed for evaluation | |
virtual void | set_function_pattern (ConstSmartPtr< FunctionPattern > fctPatt) |
updates the function group | |
virtual void | set_input (size_t i, SmartPtr< ICplUserData< dim > > input, SmartPtr< UserDataInfo > info) |
sets an input | |
void | set_num_input (size_t num) |
sets the number of inputs | |
virtual bool | zero_derivative () const |
returns if derivative is zero | |
bool | zero_derivative (size_t i) const |
returns if the derivative of the i'th input is zero | |
![]() | |
virtual void | operator() (TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< 1 > vLocIP[], const size_t nip, LocalVector *u, const MathMatrix< 1, dim > *vJT=NULL) const |
virtual void | operator() (TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< 2 > vLocIP[], const size_t nip, LocalVector *u, const MathMatrix< 2, dim > *vJT=NULL) const |
virtual void | operator() (TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< 3 > vLocIP[], const size_t nip, LocalVector *u, const MathMatrix< 3, dim > *vJT=NULL) const |
![]() | |
bool | defined (size_t s, size_t ip) const |
returns flag, if data is evaluated (for conditional data) | |
size_t | num_ip (size_t s) const |
returns the number of integration points | |
size_t | num_series () const |
explicitly forward some functions | |
void | register_storage_callback (DataImport< TData, dim > *obj, void(DataImport< TData, dim >::*func)()) |
register external callback, invoked when data storage changed | |
void | unregister_storage_callback (DataImport< TData, dim > *obj) |
register all callbacks registered by class | |
TData & | value (size_t s, size_t ip) |
returns the value at ip | |
const TData & | value (size_t s, size_t ip) const |
returns the value at ip | |
TData * | values (size_t s) |
returns all values for a series | |
const TData * | values (size_t s) const |
returns all values for a series | |
~CplUserData () | |
destructor | |
![]() | |
bool | at_current_time (size_t s) const |
returns true iff the time point specification is equal to the current one, or not specified | |
void | clear () |
clear all data | |
virtual bool | constant () const |
returns if data is constant | |
int | dim_local_ips () const |
returns current local ip dimension | |
ICplUserData () | |
default constructor | |
const MathVector< dim > & | ip (size_t s, size_t ip) const |
returns global ip | |
const MathVector< dim > * | ips (size_t s) const |
returns global ips | |
template<int ldim> | |
const MathVector< ldim > & | local_ip (size_t s, size_t ip) const |
returns local ip | |
template<int ldim> | |
const MathVector< ldim > * | local_ips (size_t s) const |
returns local ips | |
size_t | num_ip (size_t s) const |
returns the number of integration points | |
size_t | num_series () const |
returns the number of ip series | |
template<int ldim> | |
size_t | register_local_ip_series (const MathVector< ldim > *vPos, const size_t numIP, bool bMayChange=true) |
set local positions without the specification of the time point, returns series id | |
template<int ldim> | |
size_t | register_local_ip_series (const MathVector< ldim > *vPos, const size_t numIP, const int timePointSpec, bool bMayChange=true) |
set local positions, returns series id | |
void | set_global_ips (size_t s, const MathVector< dim > *vPos, size_t numIP) |
set global positions | |
template<int ldim> | |
void | set_local_ips (const size_t seriesId, const MathVector< ldim > *vPos, const size_t numIP) |
sets new local ip positions for a local ip series | |
void | set_subset (int si) |
set the subset of evaluation | |
void | set_time_point (const size_t seriesId, const int timePointSpec) |
sets a new time point for a local ip series | |
void | set_time_point (size_t timePoint) |
sets the current time point | |
void | set_times (const std::vector< number > &vTime) |
set evaluation time | |
int | subset () const |
returns the subset of evaluation | |
number | time () const |
get the current evaluation time | |
number | time (size_t s) const |
get the specified evaluation time | |
size_t | time_point () |
returns the current time point | |
size_t | time_point (size_t s) const |
returns the time point specification (in particular, the current one, if the own one not specified) | |
int | time_point_specification (size_t s) const |
returns the time point specification (note: it may be -1, i.e. not specified) | |
virtual void | update_dof_sizes (const LocalIndices &ind) |
resize arrays | |
virtual | ~ICplUserData () |
virtual desctructor | |
![]() | |
const FunctionGroup & | function_group () const |
Function Group of functions. | |
const FunctionIndexMapping & | map () const |
get function mapping | |
size_t | num_fct () const |
number of functions this export depends on | |
const char * | obj_name () |
gets the name of the object (s. the field m_objName) | |
void | set_obj_name (const char *name) |
sets the name of the object (s. the field m_objName) | |
virtual | ~UserDataInfo () |
virtual destructor | |
![]() | |
int | get_dim () const |
returns dimension | |
virtual void | operator() (TData &value, const MathVector< dim > &globIP, number time, int si, Vertex *vrt) const |
returns a value at a vertex | |
std::string | type () const |
returns type of data as string (e.g. "Number", "Vector", "Matrix") | |
TRet | operator() (TData &value, const MathVector< dim > &globIP, number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< 1 > &locIP, LocalVector *u) const |
TRet | operator() (TData &value, const MathVector< dim > &globIP, number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< 2 > &locIP, LocalVector *u) const |
TRet | operator() (TData &value, const MathVector< dim > &globIP, number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< 3 > &locIP, LocalVector *u) const |
Protected Member Functions | |
void | eval_deriv (TData &out, const std::vector< TDataIn > &dataIn, const MathVector< dim > &x, number time, int si, size_t arg) const |
evaluates the data at a given point and time | |
void | eval_value (TData &out, const std::vector< TDataIn > &dataIn, const MathVector< dim > &x, number time, int si) const |
evaluates the data at a given point and time | |
void | free_callback_ref () |
frees the callback-reference, if a callback was set. | |
void | free_deriv_callback_ref (size_t arg) |
frees callback-references for derivate callbacks | |
void | set_lua_value_callback (const char *luaCallback, size_t numArgs) |
sets the Lua function used to compute the data | |
void | set_lua_value_callback (LuaFunctionHandle handle, size_t numArgs) |
![]() | |
void | eval_deriv (LocalVector *u, GridObject *elem, const MathVector< dim > vCornerCoords[], bool bDeriv=false) |
void | eval_deriv (LocalVectorTimeSeries *u, GridObject *elem, const MathVector< dim > vCornerCoords[], bool bDeriv=false) |
LuaUserFunction< TData, dim, TDataIn > & | getImpl () |
access to implementation | |
const LuaUserFunction< TData, dim, TDataIn > & | getImpl () const |
const access to implementation | |
virtual void | global_ips_changed (const size_t seriesID, const MathVector< dim > *vPos, const size_t numIP) |
forwards the global positions to the data inputs | |
size_t | input_common_fct (size_t i, size_t fct) const |
returns the number in the common FctGrp for a fct of an input | |
size_t | input_num_fct (size_t i) const |
returns number of functions the input depends on | |
virtual void | local_ip_series_added (const size_t seriesID) |
requests series id's from input data | |
virtual void | local_ip_series_to_be_cleared () |
requests cleaning of the ip series in the data inputs | |
virtual void | local_ips_changed (const size_t seriesID, const size_t newNumIP) |
forwards the local positions to the data inputs | |
size_t | series_id (size_t i, size_t s) const |
returns the series id set for the i'th input | |
![]() | |
TImpl & | getImpl () |
access to implementation | |
const TImpl & | getImpl () const |
const access to implementation | |
![]() | |
void | call_storage_callback () const |
calls are registered external storage callbacks | |
void | check_series (size_t s) const |
checks in debug mode the correct index | |
void | check_series_ip (size_t s, size_t ip) const |
checks in debug mode the correct index | |
virtual void | value_storage_changed (const size_t seriesID) |
callback, invoked when storage of data has changed for a series | |
![]() | |
void | check_s (size_t s) const |
checks in debug mode the correct usage of indices | |
void | check_s_ip (size_t s, size_t ip) const |
checks in debug mode the correct usage of indices | |
std::vector< const MathVector< 1 > * > & | get_local_ips (Int2Type< 1 >) |
help function to get local ips | |
const std::vector< const MathVector< 1 > * > & | get_local_ips (Int2Type< 1 >) const |
std::vector< const MathVector< 2 > * > & | get_local_ips (Int2Type< 2 >) |
const std::vector< const MathVector< 2 > * > & | get_local_ips (Int2Type< 2 >) const |
std::vector< const MathVector< 3 > * > & | get_local_ips (Int2Type< 3 >) |
const std::vector< const MathVector< 3 > * > & | get_local_ips (Int2Type< 3 >) const |
Protected Attributes | |
bool | m_bPosTimeNeed |
flag for position and time data | |
std::vector< std::string > | m_cbDerivName |
std::vector< int > | m_cbDerivRef |
std::string | m_cbValueName |
callback name as string | |
int | m_cbValueRef |
reference to lua function | |
lua_State * | m_L |
lua state | |
size_t | m_numArgs |
number of arguments to use | |
std::vector< SmartPtr< DependentUserData< TDataIn, dim > > > | m_vpDependData |
data input casted to dependend data | |
std::vector< SmartPtr< CplUserData< TDataIn, dim > > > | m_vpUserData |
LUACompiler types for compiled LUA code. | |
![]() | |
std::vector< FunctionIndexMapping > | m_vMap |
Function mapping for each input relative to common FunctionGroup. | |
std::vector< SmartPtr< ICplUserData< dim > > > | m_vspICplUserData |
data input | |
std::vector< SmartPtr< UserDataInfo > > | m_vspUserDataInfo |
data input casted to IDependend data | |
std::vector< std::vector< size_t > > | m_vvSeriesID |
series id the linker uses to get data from input | |
![]() | |
int | m_defaultTimePoint |
default time point (or -1 if not specified) | |
int | m_locPosDim |
dimension of local position (-1 indicates no dim set) | |
std::vector< const MathVector< 1 > * > | m_pvLocIP1d |
local ips of dimension 1d-3d | |
std::vector< const MathVector< 2 > * > | m_pvLocIP2d |
std::vector< const MathVector< 3 > * > | m_pvLocIP3d |
int | m_si |
subset for evaluation | |
size_t | m_timePoint |
current time point (used if no explicit specification for series) | |
std::vector< bool > | m_vMayChange |
flags if local ips may change | |
std::vector< size_t > | m_vNumIP |
number of evaluation points (-1 indicates no ips set) | |
std::vector< number > | m_vTime |
time for evaluation | |
std::vector< int > | m_vTimePoint |
time points for the series | |
std::vector< const MathVector< dim > * > | m_vvGlobPos |
global ips | |
![]() | |
FunctionGroup | m_fctGrp |
functions the data depends on | |
FunctionIndexMapping | m_map |
Mapping for import fct. | |
SmartPtr< char > | m_objName |
This field is used mainly for debugging: One can assign a name to the object to identify it when running. | |
maps several data values to an output data value using a lua callback
This class provides the evaluation of a user function, that is specified in the script. Several data (of the same c++-type) can be used as input, a data (of the same type) is returned.
typedef StdDataLinker<LuaUserFunction<TData, dim, TDataIn>, TData, dim> ug::LuaUserFunction< TData, dim, TDataIn >::base_type |
ug::LuaUserFunction< TData, dim, TDataIn >::LuaUserFunction | ( | const char * | luaCallback, |
size_t | numArgs | ||
) |
constructor
luaCallback | name of the Lua function to use as callback |
numArgs | number of arguments of the Lua callback |
References ug::script::GetDefaultLuaState(), ug::LuaUserFunction< TData, dim, TDataIn >::m_cbDerivName, ug::LuaUserFunction< TData, dim, TDataIn >::m_cbDerivRef, ug::LuaUserFunction< TData, dim, TDataIn >::m_cbValueRef, ug::LuaUserFunction< TData, dim, TDataIn >::m_L, ug::LuaUserFunction< TData, dim, TDataIn >::set_lua_value_callback(), and ug::useLuaCompiler.
ug::LuaUserFunction< TData, dim, TDataIn >::LuaUserFunction | ( | const char * | luaCallback, |
size_t | numArgs, | ||
bool | bPosTimeNeed | ||
) |
constructor
luaCallback | name of the Lua function to use as callback |
numArgs | number of arguments of the Lua callback |
References ug::script::GetDefaultLuaState(), ug::LuaUserFunction< TData, dim, TDataIn >::m_cbDerivName, ug::LuaUserFunction< TData, dim, TDataIn >::m_cbDerivRef, ug::LuaUserFunction< TData, dim, TDataIn >::m_cbValueRef, ug::LuaUserFunction< TData, dim, TDataIn >::m_L, and ug::LuaUserFunction< TData, dim, TDataIn >::set_lua_value_callback().
ug::LuaUserFunction< TData, dim, TDataIn >::LuaUserFunction | ( | LuaFunctionHandle | handle, |
size_t | numArgs | ||
) |
constructor
luaCallback | name of the Lua function to use as callback |
numArgs | number of arguments of the Lua callback |
References ug::script::GetDefaultLuaState(), ug::LuaUserFunction< TData, dim, TDataIn >::m_cbDerivName, ug::LuaUserFunction< TData, dim, TDataIn >::m_cbDerivRef, ug::LuaUserFunction< TData, dim, TDataIn >::m_cbValueRef, ug::LuaUserFunction< TData, dim, TDataIn >::m_L, ug::LuaUserFunction< TData, dim, TDataIn >::set_lua_value_callback(), UG_LOG, and ug::useLuaCompiler.
ug::LuaUserFunction< TData, dim, TDataIn >::LuaUserFunction | ( | LuaFunctionHandle | handle, |
size_t | numArgs, | ||
bool | bPosTimeNeed | ||
) |
constructor
luaCallback | name of the Lua function to use as callback |
numArgs | number of arguments of the Lua callback |
References ug::script::GetDefaultLuaState(), ug::LuaUserFunction< TData, dim, TDataIn >::m_cbDerivName, ug::LuaUserFunction< TData, dim, TDataIn >::m_cbDerivRef, ug::LuaUserFunction< TData, dim, TDataIn >::m_cbValueRef, ug::LuaUserFunction< TData, dim, TDataIn >::m_L, and ug::LuaUserFunction< TData, dim, TDataIn >::set_lua_value_callback().
|
virtual |
destructor frees the reference
void ug::LuaUserFunction< TData, dim, TDataIn >::eval_and_deriv | ( | TData | vValue[], |
const MathVector< dim > | vGlobIP[], | ||
number | time, | ||
int | si, | ||
GridObject * | elem, | ||
const MathVector< dim > | vCornerCoords[], | ||
const MathVector< refDim > | vLocIP[], | ||
const size_t | nip, | ||
LocalVector * | u, | ||
bool | bDeriv, | ||
int | s, | ||
std::vector< std::vector< TData > > | vvvDeriv[], | ||
const MathMatrix< refDim, dim > * | vJT = NULL |
||
) |
|
protected |
evaluates the data at a given point and time
References ug::bridge::LUACompiler::call(), ug::IsFiniteAndNotTooBig(), ug::bridge::LUACompiler::name(), ug::bridge::LUACompiler::num_out(), PROFILE_CALLBACK, UG_ASSERT, UG_CATCH_THROW, UG_COND_THROW, UG_THROW, and ug::useLuaCompiler.
|
protected |
evaluates the data at a given point and time
References ug::IsFiniteAndNotTooBig(), PROFILE_CALLBACK, UG_ASSERT, UG_CATCH_THROW, UG_COND_THROW, UG_THROW, and ug::useLuaCompiler.
|
inline |
References ug::IsFiniteAndNotTooBig(), PROFILE_CALLBACK, and UG_COND_THROW.
|
inline |
References ug::IsFiniteAndNotTooBig(), PROFILE_CALLBACK, and UG_COND_THROW.
|
protected |
frees the callback-reference, if a callback was set.
|
protected |
frees callback-references for derivate callbacks
|
virtual |
evaluates the data
References ug::IsFiniteAndNotTooBig(), PROFILE_CALLBACK, UG_ASSERT, UG_CATCH_THROW, UG_COND_THROW, UG_THROW, and ug::useLuaCompiler.
void ug::LuaUserFunction< TData, dim, TDataIn >::set_deriv | ( | size_t | arg, |
const char * | luaCallback | ||
) |
sets the Lua function used to compute the derivative
arg | this is the derivative with respect to the parameter index arg |
luaCallback | name of the Lua function to use as callback |
References UG_THROW, and ug::useLuaCompiler.
Referenced by ug::LuaUserFunction< TData, dim, TDataIn >::set_input_and_deriv().
void ug::LuaUserFunction< TData, dim, TDataIn >::set_deriv | ( | size_t | arg, |
LuaFunctionHandle | handle | ||
) |
References ug::LuaFunctionHandle::ref, and UG_THROW.
void ug::LuaUserFunction< TData, dim, TDataIn >::set_input | ( | size_t | i, |
number | val | ||
) |
set input value for paramter i
i | parameter index this input is bind to |
void ug::LuaUserFunction< TData, dim, TDataIn >::set_input | ( | size_t | i, |
SmartPtr< CplUserData< TDataIn, dim > > | data | ||
) |
set input value for paramter i
i | parameter index this input is bind to |
References UG_ASSERT, and UG_THROW.
Referenced by ug::LuaUserFunction< TData, dim, TDataIn >::set_input_and_deriv().
|
inline |
|
protected |
sets the Lua function used to compute the data
References UG_THROW.
Referenced by ug::LuaUserFunction< TData, dim, TDataIn >::LuaUserFunction(), ug::LuaUserFunction< TData, dim, TDataIn >::LuaUserFunction(), ug::LuaUserFunction< TData, dim, TDataIn >::LuaUserFunction(), and ug::LuaUserFunction< TData, dim, TDataIn >::LuaUserFunction().
|
protected |
References ug::LuaFunctionHandle::ref.
void ug::LuaUserFunction< TData, dim, TDataIn >::set_num_input | ( | size_t | num | ) |
set number of needed inputs
TODO: Note this is a public (non-virtual) function whose argument should be consistent with the number of the arguments. Should not it also resize the array for the references to the derivatives?
|
protected |
flag for position and time data
|
protected |
|
protected |
|
protected |
callback name as string
|
protected |
|
protected |
|
protected |
number of arguments to use
|
protected |
data input casted to dependend data
|
protected |
LUACompiler types for compiled LUA code.
data input