API reference

OMRuntimeExternalC — Module

Julia bindings to the external C functions of the Modelica Standard Library (tables, strings, I/O, files, random numbers, FFT) and the tool side of ModelicaUtilities.h. They call libModelicaExternalC, built from the C sources of the Standard Library (see libraryPath).

source

Loading the library

OMRuntimeExternalC.libModelicaExternalC — Constant
libModelicaExternalC::String

The name ccall uses for the library, as the JLL packages do: the library is loaded by its full path in __init__, and the system finds the loaded one under this name (its install name on macOS, its SONAME on Linux, its module name on Windows).

source
OMRuntimeExternalC.artifactDirectory — Method
artifactDirectory()::Union{Nothing, String}

The directory of the library in the installed artifact "ModelicaExternalC", if Artifacts.toml has an entry for this platform and the artifact is installed.

source
OMRuntimeExternalC.libraryDirectory — Function
libraryDirectory(environment = ENV)::Union{Nothing, String}

The directory with libModelicaExternalC, in the order of the list at the top of this file: the directory of the environment variable OMRUNTIMEEXTERNALC_LIBRARY_DIR, the build directory deps/usr/lib (bin on Windows), the artifact. nothing when none of them has the library file.

source
OMRuntimeExternalC.libraryPath — Method
libraryPath()::Union{Nothing, String}

The full path of the loaded libModelicaExternalC, nothing if the library was not found or did not load. Its functions are the Modelica external C functions of the Standard Library (dlsym finds them in it) and the safe_* functions of the shim.

source
OMRuntimeExternalC.loadLibrary — Method
loadLibrary()::Union{Nothing, String}

Load libModelicaExternalC with RTLD_GLOBAL, so that compiled external C code of a model, which calls ModelicaError and the other functions of ModelicaUtilities.h, finds them in the process. Returns the path, nothing (with a warning) if there is no library or it does not load.

source

Functions

Not every function of the library has a Julia interface: src/api.jl has the ones that have.

OMRuntimeExternalC.ModelicaError — Method
ModelicaError(msg)

Throw the Modelica error msg as a Julia error ("Modelica runtime error: ..."). The method for a Cstring is the error handler of libModelicaExternalC (installErrorHandler): C code that calls ModelicaError or ModelicaFormatError ends up here.

source
OMRuntimeExternalC.ModelicaFFT_kiss_fftr — Method
ModelicaFFT_kiss_fftr(u, nu, work, nwork, amplitudes, phases) -> info

Modelica.Math.FastFourierTransform's real FFT (MSL's ModelicaFFT.c): the amplitudes |Xk| / nf and phases arg(Xk) of the frequencies k = 0..nu/2 of the real signal u, X_k = sum(u[n+1] * exp(-2impik*n/nu) for n in 0:nu-1), nf = nu/2 + 1. A direct sum over a table of the nu roots of unity (no FFT library; nu is at most a few thousand in the MSL examples); work is only checked for its size. info: 0 o.k., 1 nu not even, 2 work too small.

source
OMRuntimeExternalC.ModelicaInternal_removeFile — Method
ModelicaInternal_removeFile(file)

Remove a file from the filesystem. ccall goes directly to libModelicaExternalC because the shim has no safeModelicaInternalremoveFile wrapper. The C function calls ModelicaFormatError on failure (e.g. file does not exist), which ends the process when no safe_* call is running.

source
OMRuntimeExternalC.ModelicaStandardTables_CombiTable1D_init2 — Method

MODELICAEXPORT void* ModelicaStandardTablesCombiTable1Dinit2( _Inz_ const char* fileName, Inz_ const char* tableName, In double* table, sizet nRow, sizet nColumn, In int* columns, sizet nCols, int smoothness, int extrapolation, int verbose) MODELICANONNULLATTR;

source
OMRuntimeExternalC.ModelicaStandardTables_CombiTimeTable_init2 — Method

MODELICAEXPORT void* ModelicaStandardTablesCombiTimeTableinit2( _Inz_ const char* fileName, Inz_ const char* tableName, In double* table, sizet nRow, sizet nColumn, double startTime, In int* columns, sizet nCols, int smoothness, int extrapolation, double shiftTime, int timeEvents, int verbose) MODELICANONNULLATTR;

source
OMRuntimeExternalC.ModelicaStrings_scanInteger — Method

ModelicaStrings_scanInteger(string::String, startIndex::Int64, unsignedNumber::Int64) Scans for an integer starting at startIndex. If unsignedNumber != 0, only unsigned integers are recognized. Returns (nextIndex, integerNumber).

source
OMRuntimeExternalC.ModelicaStrings_scanReal — Method

ModelicaStrings_scanReal(string::String, startIndex::Int64, unsignedNumber::Int64) Scans for a real number starting at startIndex. If unsignedNumber != 0, only unsigned numbers are recognized. Returns (nextIndex, number).

source
OMRuntimeExternalC.installErrorHandler — Method
installErrorHandler()::Nothing

Set ModelicaError(::Cstring) as the error handler of the loaded libModelicaExternalC (modelica_set_error_handler of the shim): an error that C code reports with ModelicaError or ModelicaFormatError while no safe_* function is running is thrown as a Julia error from the ccall that was running, instead of ending the process. The C frames between are left without cleanup, as the C code expects of ModelicaError (it does not return).

Called when the package loads. An error raised on a thread that Julia did not start has no Julia caller to catch it.

source