![]() |
GeMA
The GeMA main application
|
Several functions are published on the Lua global environment by GeMA itself, and are available for being used during the orchestration and/or model loading. Functions used to create objects are documented together with the object type documentation and are not included here. This is also the case with functions for data interpolation and parallel calls, which are documented in their specific pages (and are available only during the orchestration step).
Index:
()
()
()
()
()
()
()
()
()
()
equal(a, b, relTol, absTol) nequal(a, b, relTol, absTol) lt(a, b, relTol, absTol) lte(a, b, relTol, absTol) gt(a, b, relTol, absTol) gte(a, b, relTol, absTol) | ||
---|---|---|
Description: | Double comparisson functions (nequal stands for not equal, lt for less than, lte for less than or equal, gt for greater than and gte for greater than or equal). Available during both model loading and orchestration. Comparissons are done using both a relative tolerance and an absolute tolerance to treat numbers close to zero. Tip: When comparing for equality, and one of the factors is a zero value, consider adding 1.0 to both sides of the comparisson, i.e. use equal(a + 1.0, 1.0) instead of equal(a, 0.0) in order for the relative tolerance to be meaningfull. | |
Parameters: | a, b | The values to be compared. |
relTol | The relative tolerance used for comparisson. Two numbers are considered equal if their absolute difference is smaller or equal to relTol * max(a, b) . Default = 1e-8 (0.000001%). | |
absTol | Absolute tolerance used for comparisson between values close to zero. Default = 1e-12. | |
Returns: | Returns true or false, according to the given values and on the chosen comparisson function. |
Example:
convert(value, srcUnit, dstUnit) | ||
---|---|---|
Description: | Converts the given value from the source unit to the destination unit. Available during both model loading and orchestration. See tips on the Working with units page. | |
Parameters: | value | The value to be converted, expressed in the source unit. |
srcUnit | The source unit string. | |
dstUnit | The destination unit string. | |
Returns: | Returns the converted value or nil if the conversion is not possible (unknown or incompatible units). |
Example:
checkUnit(unit) | |
---|---|
Description: | Check if an unit is a known unit or not. Available during both model loading and orchestration. See tips on the Working with units page. |
Parameters: | unit - The unit string. |
Returns: | Returns true if the unit is a known unit, false otherwise. |
Example:
currentTime(unit) | |
---|---|
Description: | Returns the current simulation time, optionally converted to a requested unit. Also returns the time unit. Available during the orchestration. |
Parameters: | unit - An optional unit to which the current time should be converted. |
Returns: | Returns the current time, or nil if the requested unit is invalid, + the unit of the returned time. |
Example:
previousTime(unit) | |
---|---|
Description: | Returns the previous simulation time (the time of the previous time-step), optionally converted to a requested unit. Also returns the time unit. Available during the orchestration. |
Parameters: | unit - An optional unit to which the previous time should be converted. |
Returns: | Returns the previous time, or nil if the requested unit is invalid, + the unit of the returned time. |
Example:
setCurrentTime(time, updatePrev) | ||
---|---|---|
Description: | Updates the current simulation time. Expects the time value to be expressed in the unit set with setCurrentTimeUnit() (or in seconds if this function was never called). Available during the orchestration. | |
Parameters: | time | The new current simulation time, expressed in the current simulation time unit. |
updatePrev | An optional parameter. If absent or set to true , the previous time will be updated to the current time (before the current time update), unless time is equal to 0.0 when the previous time will also be set to 0.0. When set to false , the previous time is not changed. | |
Returns: | Nothing. |
Example:
setPreviousTime(time) | |
---|---|
Description: | Updates the previous simulation time. Expects the time value to be expressed in the unit set with setCurrentTimeUnit() (or in seconds if this function was never called). Available during the orchestration. |
Parameters: | time - The new previous simulation time, expressed in the current simulation time unit. |
Returns: | Nothing. |
Example:
setCurrentTimeUnit(unit) | |
---|---|
Description: | Sets the current simulation time unit. Values passed to setCurrentTime() should be expressed on this unit. If this function is never called, by default, the simulation time will be expressed in seconds. Available during the orchestration. |
Parameters: | unit - The desired time unit. |
Returns: | Nothing. |
Example:
startTimer() | |
---|---|
Description: | Starts a timer that can be used to measure the elapsed time between this moment and a subsequent call to elapsedTime() . Available during the orchestration. |
Parameters: | None. |
Returns: | Returns the timer object that should be passed as a parameter in calls to elapsedTime() . |
Example:
elapsedTime(timer) | |
---|---|
Description: | Returns the elapsed time in seconds between this call and the the last call to either startTimer() or resetTimer() . Available during the orchestration. |
Parameters: | timer - The timer object returned by the call to startTimer() . |
Returns: | Returns the elapsed time in seconds. |
Example:
resetTimer(timer) | |
---|---|
Description: | Restarts a timer created by startTimer() . The next call to elapsedTime() will measure the time elapsed from this moment on. Available during the orchestration. |
Parameters: | timer - The timer object returned by the call to startTimer() . |
Returns: | Nothing. |
Example:
isMeshGhostNode(index) | |
---|---|
Description: | Check if an index is a ghost node index (has its high bit set). Ghost node indices are values that vary from 1 to mesh: numGhostNodes() , with their high bit set in order to make a distinction between common indices, sometimes also called geometry indices, and ghost node indices. That means that, for example, the first two ghost nodes have, respectively, an index equal to 0x80000001 and 0x80000002 if node indexes are stored as 32 bit integers. Available during the orchestration. |
Parameters: | index - The index to be checked. |
Returns: | Returns true if the index is a ghost index, false if not. |
Example:
setMeshGhostFlag(index) | |
---|---|
Description: | Returns a copy of the given index with its high bit set, turning it into a ghost index. Available during the orchestration. |
Parameters: | index - The index that will have its high bit set. |
Returns: | Returns the given index with its high bit set to 1. |
Example:
clearMeshGhostFlag(index) | |
---|---|
Description: | Returns a copy of the given index with its high bit cleared, turning it into a normal node index. Available during the orchestration. |
Parameters: | index - The index that will have its high bit cleared. |
Returns: | Returns the given index with its high bit set to 0. |
Example:
tr(str) | |
---|---|
Description: | Translates the given string according to the configured language translator and the translation database. If there is no configured target language or str is not present in the translation database for that language, returns str itself. When creating translatable strings, with dynamic contents, use the positional argument replacement functions given by string: arg() and friends so that parameter order can be changed on the translated string. Although this function can be used in simulation model files, it was created to be used in general scripts from the scripts library who really can benefit from string translations while presenting error messages. Available during both model loading and orchestration. At present, there are no configured language translators available for GeMA. |
Parameters: | str - The string to be translated. |
Returns: | Returns the translated string or str itself if there is no installed translator or if the given string does not have a configured translation. |
Example:
string:arg(formater, ...) | ||
---|---|---|
Description: | String method that replaces on the string the lowest numbered placeholder (%1, %2, %3, ...) by the given value, formated according to formater , through the use of string.format() . Placeholders don't need to be in order on the string. Available during both model loading and orchestration. | |
Parameters: | formater | The formater string using the syntax recognized by the standard Lua string.format() function. |
... | Formater values required by the given formater string. | |
Returns: | Returns the string with one format parameter replaced or the string itself if no placeholders where found. |
Example:
string:int(value, width) | ||
---|---|---|
Description: | String method for replacing the next placeholder by a formated integer value. Equivalent to calling string: arg("%wd", value) with w replaced by the width parameter or removed if width is nil . Available during both model loading and orchestration. | |
Parameters: | value | The integer value to be formated. |
width | An optional field width. | |
Returns: | Returns the string with one format parameter replaced or the string itself if no placeholders where found. |
Example:
string:num(value, width, prec, fmt) | ||
---|---|---|
Description: | String method for replacing the next placeholder by a formated number. Equivalent to calling string: arg("%w.pf", value) with w replaced by the width parameter, p by prec and f by fmt . All of them are optional. If width or prec are nil , they will be removed from the format string. If fmt is nil , an "f" value will be used. Available during both model loading and orchestration. | |
Parameters: | value | The numeric value to be formated. |
width | An optional field width. | |
prec | An optional field precision. | |
fmt | The format type ('f', 'g', 'd, 'x', ...). | |
Returns: | Returns the string with one format parameter replaced or the string itself if no placeholders where found. |
Example:
string:str(value, width) | ||
---|---|---|
Description: | String method for replacing the next placeholder by a string value. Equivalent to calling string: arg("%ws", value) with w replaced by the width parameter or removed if width is nil . Available during both model loading and orchestration. | |
Parameters: | value | The string to be formated. |
width | An optional field width. | |
Returns: | Returns the string with one format parameter replaced or the string itself if no placeholders where found. |
Example:
string:strs(...) | |
---|---|
Description: | String method for replacing several placeholders by the given string values. Equivalent to calling string: arg("%s", arg) several times, one for each function argument. Available during both model loading and orchestration. |
Parameters: | ... - The list of strings to be formated. |
Returns: | Returns the string with as many format placeholders replaced as strings on ... or the string itself if no placeholders where found. |
Example:
checkForCancelation() | |
---|---|
Description: | Checks for a pending cancelation request. If there is one, aborts the script processing by raising a Lua error. Cancelation requests can be received when the monitor server is active and cancelation requests are enabled. Available during both model loading and orchestration. Keep in mind that cancelation checks are done automatically in every process or API call during the orchestration and so calling this function is needed only if your code includes a Lua loop that takes a long time and only includes standard Lua calls. Also, when writing functions for using with node and cell parallel calls, the iterator object already does a cancelation check per loop iteration. |
Parameters: | None. |
Returns: | Returns nothing. If there is a pending cancelation request, this function does not return at all (calls error() ). |
Example:
translatePath(path) | |
---|---|
Description: | Translates path macros in path , expanding them to the correct path. Allows the usage of GeMA macros when opening or creating files directly with Lua file manipulation functions. Not needed when calling dofile() since the actual function is overriden by GeMA to already translate paths. This function also cleans the path, converting path separators to / , removing . and .. references. It also removes path separators from the end of the path. Available during both model loading and orchestration. |
Parameters: | path - The path to be translated. |
Returns: | Returns the translated path. |
Example:
cleanPath(path) | |
---|---|
Description: | Returns a cleaned version of the given path, converting path separators to / , removing . and .. references. It also removes path separators from the end of the path. Similar to calling translatePath() but without macro conversions. Available during both model loading and orchestration. |
Parameters: | path - The path to be cleaned. |
Returns: | Returns the cleaned path. |
Example:
logMsg(level, msg) | ||
---|---|---|
Description: | Writes a message using the logger infrastructure. The message will be printed on the console and / or in the log file, depending on the current configuration options. The standard Lua print() function also writes to the logger, but it always uses the info level, while logMsg allows the user to define the intended level. Available during both model loading and orchestration. | |
Parameters: | level | The logger level with which the message should be printed. Available options are: "trace" , "extinfo" , "info" , "warning" , "error" , "fatal" , "time" and "memory" . See the configuration options page for an explanation of each level intended purpose. |
msg | The message to be printed (a single string). | |
Returns: | Nothing. |
Example:
logMemory(msg) | |
---|---|
Description: | Writes a "memory" message using the logger infrastructure. The message will include the given user string, being formated like "Memory usage " + msg + " in Mb [phys, virtual]:" , followed by the actual memory usage numbers. The message will be printed on the console and / or in the log file, depending on the current configuration options. Available during both model loading and orchestration. |
Parameters: | msg - The user string that will be inserted in the logged message, together with the current memory usage. |
Returns: | Nothing. |
Example:
warn(...) | |
---|---|
Description: | Writes a warning message using the logger infrastructure. The message will be printed on the console and / or in the log file, depending on the current configuration options. Works like the standard Lua print() function, only using the warning level instead of the info level. Available during both model loading and orchestration. |
Parameters: | ... - The set of messages to print. Each one is converted to a string with the tostring() Lua function. |
Returns: | Nothing. |
Example:
cellTypeList() | |
---|---|
Description: | Returns a Lua table filled with known cell type names, in the internal GeMA type order. |
Parameters: | None. |
Returns: | Returns the cell type list. |
Example: