OMJulia.API
Module OMJulia.API
aims to provide a Julia interface to the OpenModelica scripting API. In contrast to sending the scripting api calls directly via sendExpression
this API has a Julia-like interface and some level of error handling implemented. This means errors will throw Julia Exception OMJulia.API.ScriptingError
instead of only printing to stdout.
Not all OMJulia.API
functions are tested and some functions could have slightly different default values compared to the OpenModelica scripting API.
Instead of escaping strings yourself the API interface handles this for you:
sendExpression(omc, "loadFile(\"$(bouncingBallFile)\")")
becomes
API.loadFile(omc, bouncingBallFile)
Functions
OMJulia.API.buildModel
— MethodbuildModel(omc, className;
startTime = 0.0,
stopTime = 1.0,
numberOfIntervals = 500,
tolerance = 1e-6,
method = "",
fileNamePrefix = className,
options = "",
outputFormat = "mat",
variableFilter = ".*",
cflags = "",
simflags = "")
Build Modelica model by generating C code and compiling it into an executable simulation. It does not run the simulation!
OMJulia.API.buildModelFMU
— MethodbuildModelFMU(omc, className;
version = "2.0",
fmuType = "me",
fileNamePrefix=className,
platforms=["static"],
includeResources = false)
Translates a modelica model into a Functional Mockup Unit. The only required argument is the className, while all others have some default values.
OMJulia.API.cd
— Functioncd(omc, newWorkingDirectory="")
Change directory to the given path newWorkingDirectory
(which may be either relative or absolute). Returns the new working directory on success or a message on failure. If the given path is the empty string, the function simply returns the current working directory.
OMJulia.API.closeSimulationResultFile
— Method closeSimulationResultFile(omc)
Closes the current simulation result file. Only needed by Windows. Windows cannot handle reading and writing to the same file from different processes. To allow OMEdit to make successful simulation again on the same file we must close the file after reading the Simulation Result Variables. Even OMEdit only use this API for Windows.
OMJulia.API.diffSimulationResults
— MethoddiffSimulationResults(omc, actualFile, expectedFile, diffPrefix;
relTol = 1e-3,
relTolDiffMinMax = 1e-4,
rangeDelta = 0.002,
vars = String[],
keepEqualResults = false)
Compares simulation results.
OMJulia.API.getClassNames
— MethodgetClassNames(omc;
class_ = "",
recursive = false,
qualified = false,
sort = false,
builtin = false,
showProtected = false,
includeConstants = false)
Returns the list of class names defined in the class.
OMJulia.API.getErrorString
— MethodgetErrorString(omc, warningsAsErrors = false)
Returns the current error message.
OMJulia.API.getInstallationDirectoryPath
— MethodgetInstallationDirectoryPath(omc)
This returns OPENMODELICAHOME
if it is set; on some platforms the default path is returned if it is not set.
See OpenModelica scripting API getInstallationDirectoryPath
.
OMJulia.API.getVersion
— MethodgetVersion(omc)
Returns the version of the Modelica compiler.
OMJulia.API.instantiateModel
— MethodinstantiateModel(omc, className)
Instantiates the class and returns the flat Modelica code.
OMJulia.API.linearize
— MethodCreates a model with symbolic linearization matrices.
OMJulia.API.loadFile
— MethodloadFile(omc, fileName;
encoding = "",
uses = true,
notify = true,
requireExactVersion = false)
Load file fileName
(*.mo) and merge it with the loaded AST. See OpenModelica scripting API loadFile
.
OMJulia.API.loadModel
— MethodloadModel(omc, className;
priorityVersion = String[],
notify = false,
languageStandard = "",
requireExactVersion = false)
Loads a Modelica library.
OMJulia.API.makeVectorString
— MethodmakeVectorString(vec)
Add quotes around each string element.
OMJulia.API.readSimulationResult
— FunctionreadSimulationResult(omc, filename,
variables = String[],
size = 0)
Reads a result file, returning a matrix corresponding to the variables and size given.
OMJulia.API.readSimulationResultSize
— MethodreadSimulationResultSize(omc, fileName)
The number of intervals that are present in the output file.
OMJulia.API.readSimulationResultVars
— MethodreadSimulationResultVars(omc, fileName; readParameters = true, openmodelicaStyle = false)
Returns the variables in the simulation file; you can use val() and plot() commands using these names.
OMJulia.API.setCommandLineOptions
— MethodsetCommandLineOptions(omc, option)
The input is a regular command-line flag given to OMC, e.g. -d=failtrace or -g=MetaModelica.
OMJulia.API.simulate
— Methodsimulate(omc, className;
startTime = 0.0,
stopTime = nothing,
numberOfIntervals = 500,
tolerance = 1e-6,
method = "",
fileNamePrefix=className,
options = "",
outputFormat = "mat",
variableFilter = ".*",
cflags = "",
simflags = "")
Simulates a modelica model by generating C code, build it and run the simulation executable.
OMJulia.API.ScriptingError
— TypeScriptingError <: Exception
OpenModelica scripting error with message msg
and additional error string
from getErrroString
.