From 20e8ad7dfa973a8cf9e2add063d6ce35a8190293 Mon Sep 17 00:00:00 2001 From: "Documenter.jl" Date: Mon, 27 May 2024 16:39:17 +0000 Subject: [PATCH] build based on ed8ac12 --- dev/api/index.html | 18 +++++++------- dev/index.html | 2 +- dev/modelicaSystem/index.html | 22 +++++++++--------- dev/quickstart/index.html | 44 +++++++++++++++++------------------ dev/search/index.html | 2 +- dev/search_index.js | 2 +- dev/sendExpression/index.html | 2 +- 7 files changed, 47 insertions(+), 45 deletions(-) diff --git a/dev/api/index.html b/dev/api/index.html index c504738..e677121 100644 --- a/dev/api/index.html +++ b/dev/api/index.html @@ -10,34 +10,36 @@ 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!

See OpenModelica scripting API buildModel.

source
OMJulia.API.buildModelFMUMethod
buildModelFMU(omc, className;
+           simflags = "")

Build Modelica model by generating C code and compiling it into an executable simulation. It does not run the simulation!

See OpenModelica scripting API buildModel.

source
OMJulia.API.buildModelFMUMethod
buildModelFMU(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.

See OpenModelica scripting API buildModelFMU.

source
OMJulia.API.cdFunction
cd(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.

See OpenModelica scripting API cd.

source
OMJulia.API.closeSimulationResultFileMethod
    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.

See OpenModelica scripting API closeSimulationResultFile.

source
OMJulia.API.diffSimulationResultsMethod
diffSimulationResults(omc, actualFile, expectedFile, diffPrefix;
+              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.

See OpenModelica scripting API buildModelFMU.

source
OMJulia.API.cdFunction
cd(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.

See OpenModelica scripting API cd.

source
OMJulia.API.closeSimulationResultFileMethod
    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.

See OpenModelica scripting API closeSimulationResultFile.

source
OMJulia.API.diffSimulationResultsMethod
diffSimulationResults(omc, actualFile, expectedFile, diffPrefix;
                       relTol = 1e-3,
                       relTolDiffMinMax = 1e-4,
                       rangeDelta = 0.002,
                       vars = String[],
-                      keepEqualResults = false)

Compares simulation results.

See OpenModelica scripting API diffSimulationResults.

source
OMJulia.API.getClassNamesMethod
getClassNames(omc;
+                      keepEqualResults = false)

Compares simulation results.

See OpenModelica scripting API diffSimulationResults.

source
OMJulia.API.getAvailablePackageVersionsMethod
getAvailablePackageVersions(omc, pkg; version="")

Get available package versions of pkg. Lists all available versions of the Buildings library on the OSMC server, starting from the most recent one, in descending order of priority. Note that pre-release versions have lower priority than all other versions.

See OpenModelica scripting API getAvailablePackageVersions or Package Management.

source
OMJulia.API.getClassNamesMethod
getClassNames(omc;
               class_ = "",
               recursive = false,
               qualified = false,
               sort = false,
               builtin = false,
               showProtected = false,
-              includeConstants = false)

Returns the list of class names defined in the class.

See OpenModelica scripting API getClassNames.

source
OMJulia.API.getErrorStringMethod
getErrorString(omc, warningsAsErrors = false)

Returns the current error message.

See OpenModelica scripting API getErrorString.

source
OMJulia.API.getInstallationDirectoryPathMethod
getInstallationDirectoryPath(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.

source
OMJulia.API.getVersionMethod
getVersion(omc)

Returns the version of the Modelica compiler.

See OpenModelica scripting API getVersion.

source
OMJulia.API.instantiateModelMethod

instantiateModel(omc, className)

Instantiates the class and returns the flat Modelica code.

See OpenModelica scripting API instantiateModel.

source
OMJulia.API.linearizeMethod

Creates a model with symbolic linearization matrices.

See OpenModelica scripting API linearize.

source
OMJulia.API.loadFileMethod
loadFile(omc, fileName;
+              includeConstants = false)

Returns the list of class names defined in the class.

See OpenModelica scripting API getClassNames.

source
OMJulia.API.getErrorStringMethod
getErrorString(omc, warningsAsErrors = false)

Returns the current error message.

See OpenModelica scripting API getErrorString.

source
OMJulia.API.getInstallationDirectoryPathMethod
getInstallationDirectoryPath(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.

source
OMJulia.API.getVersionMethod
getVersion(omc)

Returns the version of the Modelica compiler.

See OpenModelica scripting API getVersion.

source
OMJulia.API.installPackageMethod
installPackage(omc, pkg;
+               version="",
+               exactMatch=false)

Install package pkg with given version. If version="" try to install most recent version of package. If exactMatch is true install exact version, even if there are more recent backwards.compatible versions available.

See OpenModelica scripting API installPackage or Package Management.

source
OMJulia.API.instantiateModelMethod
instantiateModel(omc, className)

Instantiates the class and returns the flat Modelica code.

See OpenModelica scripting API instantiateModel.

source
OMJulia.API.linearizeMethod

Creates a model with symbolic linearization matrices.

See OpenModelica scripting API linearize.

source
OMJulia.API.loadFileMethod
loadFile(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.

source
OMJulia.API.loadModelMethod
loadModel(omc, className;
+         requireExactVersion = false)

Load file fileName (*.mo) and merge it with the loaded AST. See OpenModelica scripting API loadFile.

source
OMJulia.API.loadModelMethod
loadModel(omc, className;
           priorityVersion = String[],
           notify = false,
           languageStandard = "",
-          requireExactVersion = false)

Loads a Modelica library.

See OpenModelica scripting API loadModel.

source
OMJulia.API.makeVectorStringMethod
makeVectorString(vec)

Add quotes around each string element.

source
OMJulia.API.readSimulationResultFunction
readSimulationResult(omc, filename,
+          requireExactVersion = false)

Loads a Modelica library.

See OpenModelica scripting API loadModel.

source
OMJulia.API.makeVectorStringMethod
makeVectorString(vec)

Add quotes around each string element.

source
OMJulia.API.readSimulationResultFunction
readSimulationResult(omc, filename,
                      variables = String[],
-                     size = 0)

Reads a result file, returning a matrix corresponding to the variables and size given.

See OpenModelica scripting API readSimulationResult.

source
OMJulia.API.readSimulationResultSizeMethod
readSimulationResultSize(omc, fileName)

The number of intervals that are present in the output file.

See OpenModelica scripting API readSimulationResultSize.

source
OMJulia.API.readSimulationResultVarsMethod

readSimulationResultVars(omc, fileName; readParameters = true, openmodelicaStyle = false)

Returns the variables in the simulation file; you can use val() and plot() commands using these names.

See OpenModelica scripting API readSimulationResultVars.

source
OMJulia.API.setCommandLineOptionsMethod
setCommandLineOptions(omc, option)

The input is a regular command-line flag given to OMC, e.g. -d=failtrace or -g=MetaModelica.

See OpenModelica scripting API setCommandLineOptions.

source
OMJulia.API.simulateMethod
simulate(omc, className;
+                     size = 0)

Reads a result file, returning a matrix corresponding to the variables and size given.

See OpenModelica scripting API readSimulationResult.

source
OMJulia.API.readSimulationResultSizeMethod
readSimulationResultSize(omc, fileName)

The number of intervals that are present in the output file.

See OpenModelica scripting API readSimulationResultSize.

source
OMJulia.API.readSimulationResultVarsMethod

readSimulationResultVars(omc, fileName; readParameters = true, openmodelicaStyle = false)

Returns the variables in the simulation file; you can use val() and plot() commands using these names.

See OpenModelica scripting API readSimulationResultVars.

source
OMJulia.API.setCommandLineOptionsMethod
setCommandLineOptions(omc, option)

The input is a regular command-line flag given to OMC, e.g. -d=failtrace or -g=MetaModelica.

See OpenModelica scripting API setCommandLineOptions.

source
OMJulia.API.simulateMethod
simulate(omc, className;
         startTime = 0.0,
         stopTime = nothing,
         numberOfIntervals = 500,
@@ -48,4 +50,4 @@
         outputFormat = "mat",
         variableFilter = ".*",
         cflags = "",
-        simflags = "")

Simulates a modelica model by generating C code, build it and run the simulation executable.

See OpenModelica scripting API simulate.

source
OMJulia.API.ScriptingErrorType
ScriptingError <: Exception

OpenModelica scripting error with message msg and additional error string from getErrroString.

source
+ simflags = "")

Simulates a modelica model by generating C code, build it and run the simulation executable.

See OpenModelica scripting API simulate.

source
OMJulia.API.updatePackageIndexMethod
updatePackageIndex(omc)

Update package index list.

The package manager contacts OSMC sersers and updated the internally sotred list of available packages.

See OpenModelica scripting API updatePackageIndex or Package Management.

source
OMJulia.API.upgradeInstalledPackagesMethod
upgradeInstalledPackages(omc; installNewestVersions=true)

Installs the latest available version of all installed packages.

See OpenModelica scripting API upgradeInstalledPackages or Package Management.

source
OMJulia.API.ScriptingErrorType
ScriptingError <: Exception

OpenModelica scripting error with message msg and additional error string from getErrroString.

source
diff --git a/dev/index.html b/dev/index.html index edf03e7..a6f52ed 100644 --- a/dev/index.html +++ b/dev/index.html @@ -1,2 +1,2 @@ -Home · OMJulia.jl

OMJulia.jl

Julia scripting OpenModelica interface.

Overview

OMJulia - the OpenModelica Julia API is a free, open source, highly portable Julia based interactive session handler for Julia scripting of OpenModelica API functionality. It provides the modeler with components for creating a complete Julia-Modelica modeling, compilation and simulation environment based on the latest OpenModelica implementation and Modelica library standard available.

OMJulia is structured to combine both the solving strategy and model building. Thus, domain experts (people writing the models) and computational engineers (people writing the solver code) can work on one unified tool that is industrially viable for optimization of Modelica models, while offering a flexible platform for algorithm development and research. OMJulia is not a standalone package, it depends upon the OpenModelica installation.

OMJulia is implemented in Julia and depends on ZeroMQ - high performance asynchronous messaging library and it supports the Modelica Standard Library version 4.0 that is included with OpenModelica.

Installation

Make sure OpenModelica is installed.

Install OMJulia.jl with:

julia> import Pkg; Pkg.add("OMJulia")

Features of OMJulia

The OMJulia package contains the following features:

  • Interactive session handling, parsing, interpretation of commands and Modelica expressions for evaluation, simulation, plotting, etc.
  • Connect with the OpenModelica compiler through zmq sockets
  • Able to interact with the OpenModelica compiler through the available API
  • Easy access to the Modelica Standard library.
  • All the API calls are communicated with the help of the sendExpression method implemented in a Julia module
  • The results are returned as strings
+Home · OMJulia.jl

OMJulia.jl

Julia scripting OpenModelica interface.

Overview

OMJulia - the OpenModelica Julia API is a free, open source, highly portable Julia based interactive session handler for Julia scripting of OpenModelica API functionality. It provides the modeler with components for creating a complete Julia-Modelica modeling, compilation and simulation environment based on the latest OpenModelica implementation and Modelica library standard available.

OMJulia is structured to combine both the solving strategy and model building. Thus, domain experts (people writing the models) and computational engineers (people writing the solver code) can work on one unified tool that is industrially viable for optimization of Modelica models, while offering a flexible platform for algorithm development and research. OMJulia is not a standalone package, it depends upon the OpenModelica installation.

OMJulia is implemented in Julia and depends on ZeroMQ - high performance asynchronous messaging library and it supports the Modelica Standard Library version 4.0 that is included with OpenModelica.

Installation

Make sure OpenModelica is installed.

Install OMJulia.jl with:

julia> import Pkg; Pkg.add("OMJulia")

Features of OMJulia

The OMJulia package contains the following features:

  • Interactive session handling, parsing, interpretation of commands and Modelica expressions for evaluation, simulation, plotting, etc.
  • Connect with the OpenModelica compiler through zmq sockets
  • Able to interact with the OpenModelica compiler through the available API
  • Easy access to the Modelica Standard library.
  • All the API calls are communicated with the help of the sendExpression method implemented in a Julia module
  • The results are returned as strings
diff --git a/dev/modelicaSystem/index.html b/dev/modelicaSystem/index.html index a3ffc36..059f9f8 100644 --- a/dev/modelicaSystem/index.html +++ b/dev/modelicaSystem/index.html @@ -4,10 +4,10 @@ mod = OMJulia.OMCSession() ModelicaSystem(mod, "BouncingBall.mo", "BouncingBall", ["Modelica", "SystemDynamics"], commandLineOptions="-d=newInst")

Providing dependent libaries:

using OMJulia
 mod = OMJulia.OMCSession()
-ModelicaSystem(mod, "BouncingBall.mo", "BouncingBall", ["Modelica", "SystemDynamics", "dcmotor.mo"])

See also OMCSession().

source
ModelicaSystem(omc; modelName, library=nothing,
+ModelicaSystem(mod, "BouncingBall.mo", "BouncingBall", ["Modelica", "SystemDynamics", "dcmotor.mo"])

See also OMCSession().

source
ModelicaSystem(omc; modelName, library=nothing,
                commandLineOptions=nothing, variableFilter=nothing, customBuildDirectory=nothing)

Set command line options for OMCSession and build model modelname to prepare for a simulation.

Arguments

  • omc: OpenModelica compiler session, see OMCSession().

Keyword Arguments

  • modelName: Name of Modelica model to build, including namespace if the model is wrappen within a Modelica package.

  • library: List of dependent libraries or Modelica files. This argument can be passed as string (e.g. "Modelica") or tuple (e.g. ("Modelica", "4.0") or array (e.g. ["Modelica", "SystemDynamics"] or [("Modelica", "4.0"), "SystemDynamics"]).

  • commandLineOptions: OpenModelica command line options, see OpenModelica Compiler Flags.

  • variableFilter: Regex to filter variables in result file.

Usage

using OMJulia
 mod = OMJulia.OMCSession()
-ModelicaSystem(mod, modelName="Modelica.Electrical.Analog.Examples.CauerLowPassAnalog", library="Modelica")

See also OMCSession().

source
OMJulia.OMCSessionType
OMCSession <: Any

OMC session struct.


OMCSession(omc=nothing)

Create new OpenModelica session.

Arguments

  • omc::Union{String, Nothing}: Path to OpenModelica compiler. Use omc from PATH if nothing is provided.

See also ModelicaSystem, OMJulia.quit.

source
OMJulia.quitFunction
quit(omc::OMCSession; timeout=4::Integer)

Quit OMCSession.

Arguments

- `omc::OMCSession`:      OMC session.

Keywords

- `timeout=4::Integer`:   Timeout in seconds.

See also OMJulia.OMCSession.

source

Example

Let us see the usage of ModelicaSystem with the help of Modelica model ModSeborgCSTRorg

model ModSeborgCSTRorg
+ModelicaSystem(mod, modelName="Modelica.Electrical.Analog.Examples.CauerLowPassAnalog", library="Modelica")

See also OMCSession().

source
OMJulia.OMCSessionType
OMCSession <: Any

OMC session struct.


OMCSession(omc=nothing)

Create new OpenModelica session.

Arguments

  • omc::Union{String, Nothing}: Path to OpenModelica compiler. Use omc from PATH if nothing is provided.

See also ModelicaSystem, OMJulia.quit.

source
OMJulia.quitFunction
quit(omc::OMCSession; timeout=4::Integer)

Quit OMCSession.

Arguments

- `omc::OMCSession`:      OMC session.

Keywords

- `timeout=4::Integer`:   Timeout in seconds.

See also OMJulia.OMCSession.

source

Example

Let us see the usage of ModelicaSystem with the help of Modelica model ModSeborgCSTRorg

model ModSeborgCSTRorg
   // Model of original Seborg CSTR in ode form
   // author: Bernt Lie, University of Southeast Norway,November 7, 2017
 
@@ -50,11 +50,11 @@
   Qd = UA*(Tc-T);
   // Outputs
   y_T = T;
-end ModSeborgCSTRorg
julia> using OMJulia
julia> mod = OMJulia.OMCSession()[ Info: Path to zmq file="/tmp/openmodelica.runner.port.julia.AJQ6zie15m" -OMJulia.OMCSession(false, false, Dict{Any, Any}(), Dict{Any, Any}(), Dict{Any, Any}(), "", "/home/runner/work/OMJulia.jl/OMJulia.jl", "", "", "", "", "", nothing, Any[], Dict{Any, Any}(), Dict{Any, Any}(), Dict{Any, Any}(), Dict{Any, Any}(), OMJulia.ZMQSession(ZMQ.Context(Ptr{Nothing} @0x000000000221d7d0, WeakRef[WeakRef(ZMQ.Socket(Ptr{Nothing} @0x00000000016defc0, ZMQ.Context(#= circular reference @-4 =#), FileWatching.FDWatcher(FileWatching._FDWatcher(Ptr{Nothing} @0x000000000225ee20, 30, (1, 0), Base.GenericCondition{Base.Threads.SpinLock}(Base.IntrusiveLinkedList{Task}(nothing, nothing), Base.Threads.SpinLock(0)), 0, (false, false)), FileWatching.FDEvent(1))))]), ZMQ.Socket(Ptr{Nothing} @0x00000000016defc0, ZMQ.Context(Ptr{Nothing} @0x000000000221d7d0, WeakRef[WeakRef(ZMQ.Socket(#= circular reference @-4 =#))]), FileWatching.FDWatcher(FileWatching._FDWatcher(Ptr{Nothing} @0x000000000225ee20, 30, (1, 0), Base.GenericCondition{Base.Threads.SpinLock}(Base.IntrusiveLinkedList{Task}(nothing, nothing), Base.Threads.SpinLock(0)), 0, (false, false)), FileWatching.FDEvent(1))), Process(`omc --interactive=zmq -z=julia.AJQ6zie15m`, ProcessRunning)), OMJulia.Linearization("", "", Dict{AbstractString, AbstractString}("startTime" => "0.0", "stopTime" => "1.0", "stepSize" => "0.002", "tolerance" => "1e-6"), false, missing, missing, missing))
julia> ModelicaSystem(mod, +end ModSeborgCSTRorg
julia> using OMJulia
julia> mod = OMJulia.OMCSession()[ Info: Path to zmq file="/tmp/openmodelica.runner.port.julia.gYbB2MlPk7" +OMJulia.OMCSession(false, false, Dict{Any, Any}(), Dict{Any, Any}(), Dict{Any, Any}(), "", "/home/runner/work/OMJulia.jl/OMJulia.jl", "", "", "", "", "", nothing, Any[], Dict{Any, Any}(), Dict{Any, Any}(), Dict{Any, Any}(), Dict{Any, Any}(), OMJulia.ZMQSession(ZMQ.Context(Ptr{Nothing} @0x0000000002992250, WeakRef[WeakRef(ZMQ.Socket(Ptr{Nothing} @0x00000000031712c0, ZMQ.Context(#= circular reference @-4 =#), FileWatching.FDWatcher(FileWatching._FDWatcher(Ptr{Nothing} @0x0000000002958010, 30, (1, 0), Base.GenericCondition{Base.Threads.SpinLock}(Base.IntrusiveLinkedList{Task}(nothing, nothing), Base.Threads.SpinLock(0)), 0, (false, false)), FileWatching.FDEvent(1))))]), ZMQ.Socket(Ptr{Nothing} @0x00000000031712c0, ZMQ.Context(Ptr{Nothing} @0x0000000002992250, WeakRef[WeakRef(ZMQ.Socket(#= circular reference @-4 =#))]), FileWatching.FDWatcher(FileWatching._FDWatcher(Ptr{Nothing} @0x0000000002958010, 30, (1, 0), Base.GenericCondition{Base.Threads.SpinLock}(Base.IntrusiveLinkedList{Task}(nothing, nothing), Base.Threads.SpinLock(0)), 0, (false, false)), FileWatching.FDEvent(1))), Process(`omc --interactive=zmq -z=julia.gYbB2MlPk7`, ProcessRunning)), OMJulia.Linearization("", "", Dict{AbstractString, AbstractString}("startTime" => "0.0", "stopTime" => "1.0", "stepSize" => "0.002", "tolerance" => "1e-6"), false, missing, missing, missing))
julia> ModelicaSystem(mod, joinpath("docs", "testmodels", "ModSeborgCSTRorg.mo"), - "ModSeborgCSTRorg")

WorkDirectory

For each OMJulia.OMCSession session a temporary work directory is created and the results are published in that working directory. In order to get the work directory use getWorkDirectory.

OMJulia.getWorkDirectoryFunction
getWorkDirectory(omc)

Return working directory of OMJulia.OMCsession omc.

source
julia> getWorkDirectory(mod)"/tmp/jl_TJUIxi"

Build Model

OMJulia.buildModelFunction
buildModel(omc; variableFilter=nothing)

Build modelica model.

Arguments

  • omc::OMCSession: OpenModelica compiler session.

Keyword Arguments

  • variableFilter: Regex to filter variables in result file.
source

In case the Modelica model needs to be updated or additional simulation flags needs to be set using sendExpression The buildModel API can be used after ModelicaSystem.

buildModel(omc)
-buildModel(omc, variableFilter="a|T")

Get Methods

OMJulia.getQuantitiesFunction
getQuantities(omc, name=nothing)

Return list of all variables parsed from xml file.

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of variables to read from xml file. If nothing is provided read all variables.

See also showQuantities.

source
OMJulia.showQuantitiesFunction
showQuantities(omc, name=nothing)

Return DataFrame of all variables parsed from xml file.

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of variables to read from xml file. If nothing is provided read all variables.

See also getQuantities.

source
OMJulia.getContinuousFunction
getContinuous(omc, name=nothing)

Return continuous variables parsed from xml file.

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of continuous variables to read from xml file. If nothing is provided read all continuous variables.
source
OMJulia.getInputsFunction
getInputs(omc, name=nothing)

Return input variables parsed from xml file. If input variables have no start value the returned value is "None".

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of input variables to read from xml file. If nothing is provided read all input variables.
source
OMJulia.getOutputsFunction
getInputs(omc, name=nothing)

Return output variables parsed from xml file. If output variables have no start value the returned value is "None".

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of output variables to read from xml file. If nothing is provided read all output variables.
source
OMJulia.getParametersFunction
getParameters(omc, name=nothing)

Return parameter variables parsed from xml file.

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of parameters to read from xml file. If nothing is provided read all parameters.
source
OMJulia.getSimulationOptionsFunction
getSimulationOptions(omc, name=nothing)

Return SimulationOption variables parsed from xml file.

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of parameters to read from xml file. If nothing is provided read all parameters.
source
OMJulia.getSolutionsFunction
getSolutions(omc::OMCSession, name=nothing; resultfile=nothing)

Read result file and return simulation results

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of variables to read from result file. If nothing is provided read all variables.

Keyword Arguments

  • resultfile::Union{AbstractString, Nothing}: Path to result file. If nothing is provided use saved result file.
source

Examples

julia> getQuantities(mod)23-element Vector{Any}:
+                      "ModSeborgCSTRorg")

WorkDirectory

For each OMJulia.OMCSession session a temporary work directory is created and the results are published in that working directory. In order to get the work directory use getWorkDirectory.

OMJulia.getWorkDirectoryFunction
getWorkDirectory(omc)

Return working directory of OMJulia.OMCsession omc.

source
julia> getWorkDirectory(mod)"/tmp/jl_xDzQsn"

Build Model

OMJulia.buildModelFunction
buildModel(omc; variableFilter=nothing)

Build modelica model.

Arguments

  • omc::OMCSession: OpenModelica compiler session.

Keyword Arguments

  • variableFilter: Regex to filter variables in result file.
source

In case the Modelica model needs to be updated or additional simulation flags needs to be set using sendExpression The buildModel API can be used after ModelicaSystem.

buildModel(omc)
+buildModel(omc, variableFilter="a|T")

Get Methods

OMJulia.getQuantitiesFunction
getQuantities(omc, name=nothing)

Return list of all variables parsed from xml file.

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of variables to read from xml file. If nothing is provided read all variables.

See also showQuantities.

source
OMJulia.showQuantitiesFunction
showQuantities(omc, name=nothing)

Return DataFrame of all variables parsed from xml file.

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of variables to read from xml file. If nothing is provided read all variables.

See also getQuantities.

source
OMJulia.getContinuousFunction
getContinuous(omc, name=nothing)

Return continuous variables parsed from xml file.

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of continuous variables to read from xml file. If nothing is provided read all continuous variables.
source
OMJulia.getInputsFunction
getInputs(omc, name=nothing)

Return input variables parsed from xml file. If input variables have no start value the returned value is "None".

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of input variables to read from xml file. If nothing is provided read all input variables.
source
OMJulia.getOutputsFunction
getInputs(omc, name=nothing)

Return output variables parsed from xml file. If output variables have no start value the returned value is "None".

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of output variables to read from xml file. If nothing is provided read all output variables.
source
OMJulia.getParametersFunction
getParameters(omc, name=nothing)

Return parameter variables parsed from xml file.

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of parameters to read from xml file. If nothing is provided read all parameters.
source
OMJulia.getSimulationOptionsFunction
getSimulationOptions(omc, name=nothing)

Return SimulationOption variables parsed from xml file.

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of parameters to read from xml file. If nothing is provided read all parameters.
source
OMJulia.getSolutionsFunction
getSolutions(omc::OMCSession, name=nothing; resultfile=nothing)

Read result file and return simulation results

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of variables to read from result file. If nothing is provided read all variables.

Keyword Arguments

  • resultfile::Union{AbstractString, Nothing}: Path to result file. If nothing is provided use saved result file.
source

Examples

julia> getQuantities(mod)23-element Vector{Any}:
  Dict{Any, Any}("name" => "T", "max" => "None", "start" => "None", "min" => "None", "aliasvariable" => nothing, "variability" => "continuous", "changeable" => "false", "causality" => "local", "description" => "Initializing temperature in reactor, K", "alias" => "noAlias"…)
  Dict{Any, Any}("name" => "cA", "max" => "None", "start" => "None", "min" => "None", "aliasvariable" => nothing, "variability" => "continuous", "changeable" => "false", "causality" => "local", "description" => "Initializing concentration of A in reactor, mol/L", "alias" => "noAlias"…)
  Dict{Any, Any}("name" => "der(T)", "max" => "None", "start" => "None", "min" => "None", "aliasvariable" => nothing, "variability" => "continuous", "changeable" => "false", "causality" => "local", "description" => "der(Initializing temperature in reactor, K)", "alias" => "noAlias"…)
@@ -159,7 +159,7 @@
  "y_T"
julia> getSolutions(mod, ["time","a"])2-element Vector{Vector{Float64}}: [0.0, 0.002, 0.004, 0.006, 0.008, 0.01, 0.012, 0.014, 0.016, 0.018 … 0.984, 0.986, 0.988, 0.99, 0.992, 0.994, 0.996, 0.998, 1.0, 1.0] [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 … 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]

Examples of using resultFile provided by user location

getSolutions(mod, resultfile="C:/BouncingBal/tmpbouncingBall.mat") //returns list of simulation variables for which results are available , the resulfile location is provided by user
-getSolutions(mod, ["time","h"], resultfile="C:/BouncingBal/tmpbouncingBall.mat") // return list of array

Set Methods

OMJulia.setInputsFunction
setInputs(omc, name)

Set new values for input variables.

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}}: String "Name=value" or vector of strings ["Name1=value1","Name2=value2","Name3=value3"])
source
OMJulia.setParametersFunction
setParameters(omc, name; verbose=true)

Set parameter values for parameter variables defined by users

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}}: String "Name=value" or vector of strings ["Name1=value1","Name2=value2","Name3=value3"])

Keyword Arguments

  • verbose::Bool: Display additional info if setParameters failed.
source
OMJulia.setSimulationOptionsFunction
setSimulationOptions(omc, name)

Set simulation option values like stopTime or stepSize.

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}}: String "Name=value" or vector of strings ["Name1=value1","Name2=value2","Name3=value3"])
source

Examples

julia> setInputs(mod, "cAi=100")true
julia> setInputs(mod, ["cAi=100","Ti=200","Vdi=300","Tc=250"])
julia> setParameters(mod, "a=3")"3"
julia> setParameters(mod, ["a=4","V=200"])
julia> setSimulationOptions(mod, ["stopTime=2.0", "tolerance=1e-08"])

Advanced Simulation

OMJulia.simulateFunction
simulate(omc; resultfile=nothing, simflags="", verbose=false)

Simulate modelica model.

Arguments

  • omc::OMCSession: OpenModelica compiler session, see OMCSession().

Keyword Arguments

  • resultFile::Union{String, Nothing}: Result file to write simulation results into.
  • simflags::String: Simulation flags, see Simulation Runtime Flags.
  • verbose::Bool: [debug] Log cmd call to log.txt and error.txt.

Examples

simulate(omc)

Specify result file:

simulate(omc, resultfile="tmpresult.mat")

Set simulation runtime flags:

simulate(omc, simflags="-noEmitEvent -override=e=0.3,g=9.3")
source

An example of how to do advanced simulation to set parameter values using set methods and finally simulate the "ModSeborgCSTRorg.mo" model is given below .

julia> getParameters(mod)Dict{Any, Any} with 10 entries:
+getSolutions(mod, ["time","h"], resultfile="C:/BouncingBal/tmpbouncingBall.mat") // return list of array

Set Methods

OMJulia.setInputsFunction
setInputs(omc, name)

Set new values for input variables.

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}}: String "Name=value" or vector of strings ["Name1=value1","Name2=value2","Name3=value3"])
source
OMJulia.setParametersFunction
setParameters(omc, name; verbose=true)

Set parameter values for parameter variables defined by users

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}}: String "Name=value" or vector of strings ["Name1=value1","Name2=value2","Name3=value3"])

Keyword Arguments

  • verbose::Bool: Display additional info if setParameters failed.
source
OMJulia.setSimulationOptionsFunction
setSimulationOptions(omc, name)

Set simulation option values like stopTime or stepSize.

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}}: String "Name=value" or vector of strings ["Name1=value1","Name2=value2","Name3=value3"])
source

Examples

julia> setInputs(mod, "cAi=100")true
julia> setInputs(mod, ["cAi=100","Ti=200","Vdi=300","Tc=250"])
julia> setParameters(mod, "a=3")"3"
julia> setParameters(mod, ["a=4","V=200"])
julia> setSimulationOptions(mod, ["stopTime=2.0", "tolerance=1e-08"])

Advanced Simulation

OMJulia.simulateFunction
simulate(omc; resultfile=nothing, simflags="", verbose=false)

Simulate modelica model.

Arguments

  • omc::OMCSession: OpenModelica compiler session, see OMCSession().

Keyword Arguments

  • resultFile::Union{String, Nothing}: Result file to write simulation results into.
  • simflags::String: Simulation flags, see Simulation Runtime Flags.
  • verbose::Bool: [debug] Log cmd call to log.txt and error.txt.

Examples

simulate(omc)

Specify result file:

simulate(omc, resultfile="tmpresult.mat")

Set simulation runtime flags:

simulate(omc, simflags="-noEmitEvent -override=e=0.3,g=9.3")
source

An example of how to do advanced simulation to set parameter values using set methods and finally simulate the "ModSeborgCSTRorg.mo" model is given below .

julia> getParameters(mod)Dict{Any, Any} with 10 entries:
   "DrHt" => "-5e4"
   "T0"   => "350.0"
   "cph"  => "0.239"
@@ -185,7 +185,7 @@
 
 a=3.0
 
-tolerance=1e-08

Linearization

OMJulia.linearizeFunction

function which returns the linearize model of modelica model, The function returns four matrices A, B, C, D

linearize(omc; lintime = nothing, simflags= nothing, verbose=true)

Arguments

  • omc::OMCSession: OpenModelica compiler session.

Keyword Arguments

  • lintime : Value specifies a time where the linearization of the model should be performed
  • simflags: Simulation flags, see Simulation Runtime Flags.

Examples of using linearize() API

linearize(omc)

Specify result file:

linearize(omc, lintime="0.5")

Set simulation runtime flags:

linearize(omc, simflags="-noEmitEvent")
source
OMJulia.getLinearizationOptionsFunction
getLinearizationOptions(omc, name=nothing)

Return linearization options.

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of linearization options. If nothing is provided return all linearization options.
source
OMJulia.setLinearizationOptionsFunction
setLinearizationOptions(omc, name)

Set linearization options.

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}}: String "Name=value" or vector of strings ["Name1=value1","Name2=value2","Name3=value3"])
source
OMJulia.getLinearInputsFunction
getLinearInputs(omc)

Return linear input variables after the model is linearized

Arguments

  • omc::OMCSession: OpenModelica compiler session.
source
OMJulia.getLinearOutputsFunction
getLinearOutputs(omc)

Return linear output variables after the model is linearized

Arguments

  • omc::OMCSession: OpenModelica compiler session.
source
OMJulia.getLinearStatesFunction
getLinearStates(omc)

Return linear state variables after the model is linearized

Arguments

  • omc::OMCSession: OpenModelica compiler session.
source

Examples

julia> getLinearizationOptions(mod)Dict{AbstractString, AbstractString} with 4 entries:
+tolerance=1e-08

Linearization

OMJulia.linearizeFunction

function which returns the linearize model of modelica model, The function returns four matrices A, B, C, D

linearize(omc; lintime = nothing, simflags= nothing, verbose=true)

Arguments

  • omc::OMCSession: OpenModelica compiler session.

Keyword Arguments

  • lintime : Value specifies a time where the linearization of the model should be performed
  • simflags: Simulation flags, see Simulation Runtime Flags.

Examples of using linearize() API

linearize(omc)

Specify result file:

linearize(omc, lintime="0.5")

Set simulation runtime flags:

linearize(omc, simflags="-noEmitEvent")
source
OMJulia.getLinearizationOptionsFunction
getLinearizationOptions(omc, name=nothing)

Return linearization options.

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of linearization options. If nothing is provided return all linearization options.
source
OMJulia.setLinearizationOptionsFunction
setLinearizationOptions(omc, name)

Set linearization options.

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • name::Union{<:AbstractString, Array{<:AbstractString,1}}: String "Name=value" or vector of strings ["Name1=value1","Name2=value2","Name3=value3"])
source
OMJulia.getLinearInputsFunction
getLinearInputs(omc)

Return linear input variables after the model is linearized

Arguments

  • omc::OMCSession: OpenModelica compiler session.
source
OMJulia.getLinearOutputsFunction
getLinearOutputs(omc)

Return linear output variables after the model is linearized

Arguments

  • omc::OMCSession: OpenModelica compiler session.
source
OMJulia.getLinearStatesFunction
getLinearStates(omc)

Return linear state variables after the model is linearized

Arguments

  • omc::OMCSession: OpenModelica compiler session.
source

Examples

julia> getLinearizationOptions(mod)Dict{AbstractString, AbstractString} with 4 entries:
   "startTime" => "0.0"
   "stopTime"  => "1.0"
   "stepSize"  => "0.002"
@@ -194,7 +194,7 @@
  "1.0"
julia> setLinearizationOptions(mod,["stopTime=2.0","tolerance=1e-06"])
julia> res = linearize(mod)LOG_STDOUT        | info    | Linearization will be performed at point of time: 2.000000
 LOG_SUCCESS       | info    | The initialization finished successfully without homotopy method.
 LOG_SUCCESS       | info    | The simulation finished successfully.
-LOG_STDOUT        | info    | Linear model is created at /tmp/jl_TJUIxi/linearized_model.jl
+LOG_STDOUT        | info    | Linear model is created at /tmp/jl_xDzQsn/linearized_model.jl
 LOG_STDOUT        | info    | The output format can be changed with the command line option --linearizationDumpLanguage.
 LOG_STDOUT        | info    | The options are: --linearizationDumpLanguage=modelica, matlab, julia, python.
 4-element Vector{Matrix{Float64}}:
@@ -208,7 +208,7 @@
  "cAi"
julia> getLinearOutputs(mod)1-element Vector{String}: "y_T"
julia> getLinearStates(mod)2-element Vector{String}: "T" - "cA"

Sensitivity Analysis

OMJulia.sensitivityFunction
sensitivity(omc::OMCSession, Vp, Vv, Ve=[1e-2])

Method for computing numeric sensitivity of OpenModelica object.

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • Vp::Array{<:AbstractString, 1}: Modelica Parameter names.
  • Vv::Array{<:AbstractString, 1}: Modelica Variable names.
  • Ve::Array{Float64, 1}: Excitations of parameters; defaults to scalar 1e-2

Return

  • VSname::Vector{Vector{String}}: Vector of sensitivity names
  • VSarray::Vector{Vector{Vector{Float64}}}: Vector of sensitivies: vector of elements per parameter

Each element containing time series per variable

source

Examples

julia> (Sn, Sa) = sensitivity(mod, ["UA","EdR"], ["T","cA"], [1e-2,1e-4])stopTime=2.0
+ "cA"

Sensitivity Analysis

OMJulia.sensitivityFunction
sensitivity(omc::OMCSession, Vp, Vv, Ve=[1e-2])

Method for computing numeric sensitivity of OpenModelica object.

Arguments

  • omc::OMCSession: OpenModelica compiler session.
  • Vp::Array{<:AbstractString, 1}: Modelica Parameter names.
  • Vv::Array{<:AbstractString, 1}: Modelica Variable names.
  • Ve::Array{Float64, 1}: Excitations of parameters; defaults to scalar 1e-2

Return

  • VSname::Vector{Vector{String}}: Vector of sensitivity names
  • VSarray::Vector{Vector{Vector{Float64}}}: Vector of sensitivies: vector of elements per parameter

Each element containing time series per variable

source

Examples

julia> (Sn, Sa) = sensitivity(mod, ["UA","EdR"], ["T","cA"], [1e-2,1e-4])stopTime=2.0
 
 V=200
 
@@ -238,4 +238,4 @@
 
 tolerance=1e-08
 
-([["Sensitivity.UA.T", "Sensitivity.UA.cA"], ["Sensitivity.EdR.T", "Sensitivity.EdR.cA"]], [[[0.0, -8.46484032376793e-6, -1.8798798871443978e-5, -4.054143004407251e-5, -0.00028025729756348027, -6.051659275703969e-5, -8.768568498362584e-5, -0.00011815583249176598, -0.0001516332132214302, -0.00018800934382238665  …  -0.03209010383710483, -0.03210104827926261, -0.03211190136089135, -0.03212267289974443, -0.03213335596196521, -0.03214394907919814, -0.032154454090326905, -0.03216487956045239, -0.032175218940616104, -0.032175218940616104], [0.0, 2.601676771352146e-9, 3.3445380127172794e-8, 2.2605955135546197e-7, 3.5318723430695085e-6, 8.329957789204867e-8, 7.168512584540543e-8, 6.345060944540349e-8, 5.638188856171844e-8, 5.040525208062363e-8  …  8.856962310426452e-9, 8.860592887278626e-9, 8.865492741881414e-9, 8.867668825999e-9, 8.86896148159181e-9, 8.86904980795973e-9, 8.868635808970993e-9, 8.870353771220884e-9, 8.872947805761873e-9, 8.872947805761873e-9]], [[0.0, -2.4135574026981236e-6, -1.316218634071577e-5, 0.00015636715482157473, 0.013177910234259928, 0.0042572811244099285, 0.0030510811233658125, 0.002350161991801412, 0.0018775321397177841, 0.0015375293686312424  …  0.00011258585228850799, 0.00011259551164195207, 0.00011268012895016, 0.00011274436006455549, 0.00011269701125066993, 0.0001126057852941033, 0.00011244580777461774, 0.00011218779504166118, 0.00011179777668855553, 0.00011179777668855553], [0.0, 3.464740799025938e-8, 1.8925106358226783e-7, -2.2433035995155544e-6, -0.00018911546028377302, -6.305955485789003e-5, -4.5964775551775106e-5, -3.606039447237982e-5, -2.9394320519000277e-5, -2.4605578297357384e-5  …  -1.5254439210011378e-6, -1.52539591180333e-6, -1.5253540044091085e-6, -1.5253116510930659e-6, -1.525262738660182e-6, -1.5252130899814126e-6, -1.5251617968122958e-6, -1.5251077768130085e-6, -1.5250497614154629e-6, -1.5250497614154629e-6]]])
+([["Sensitivity.UA.T", "Sensitivity.UA.cA"], ["Sensitivity.EdR.T", "Sensitivity.EdR.cA"]], [[[0.0, -8.46484032376793e-6, -1.8798798871443978e-5, -4.054143004407251e-5, -0.00028025729756348027, -6.051659275703969e-5, -8.768568498362584e-5, -0.00011815583249176598, -0.0001516332132214302, -0.00018800934382238665 … -0.03209010383710483, -0.03210104827926261, -0.03211190136089135, -0.03212267289974443, -0.03213335596196521, -0.03214394907919814, -0.032154454090326905, -0.03216487956045239, -0.032175218940616104, -0.032175218940616104], [0.0, 2.601676771352146e-9, 3.3445380127172794e-8, 2.2605955135546197e-7, 3.5318723430695085e-6, 8.329957789204867e-8, 7.168512584540543e-8, 6.345060944540349e-8, 5.638188856171844e-8, 5.040525208062363e-8 … 8.856962310426452e-9, 8.860592887278626e-9, 8.865492741881414e-9, 8.867668825999e-9, 8.86896148159181e-9, 8.86904980795973e-9, 8.868635808970993e-9, 8.870353771220884e-9, 8.872947805761873e-9, 8.872947805761873e-9]], [[0.0, -2.4135574026981236e-6, -1.316218634071577e-5, 0.00015636715482157473, 0.013177910234259928, 0.0042572811244099285, 0.0030510811233658125, 0.002350161991801412, 0.0018775321397177841, 0.0015375293686312424 … 0.00011258585228850799, 0.00011259551164195207, 0.00011268012895016, 0.00011274436006455549, 0.00011269701125066993, 0.0001126057852941033, 0.00011244580777461774, 0.00011218779504166118, 0.00011179777668855553, 0.00011179777668855553], [0.0, 3.464740799025938e-8, 1.8925106358226783e-7, -2.2433035995155544e-6, -0.00018911546028377302, -6.305955485789003e-5, -4.5964775551775106e-5, -3.606039447237982e-5, -2.9394320519000277e-5, -2.4605578297357384e-5 … -1.5254439210011378e-6, -1.52539591180333e-6, -1.5253540044091085e-6, -1.5253116510930659e-6, -1.525262738660182e-6, -1.5252130899814126e-6, -1.5251617968122958e-6, -1.5251077768130085e-6, -1.5250497614154629e-6, -1.5250497614154629e-6]]]) diff --git a/dev/quickstart/index.html b/dev/quickstart/index.html index dd066f6..47007f7 100644 --- a/dev/quickstart/index.html +++ b/dev/quickstart/index.html @@ -19,21 +19,21 @@ flying = v_new > 0; reinit(v, v_new); end when; -end BouncingBall;
Info

The BouncingBall.mo file can be found in your OpenModelica installation directory in <OpenModelcia>/share/doc/omc/testmodels/BouncingBall.mo.

ModelicaSystem

Start a new OMJulia.OMCSession and create a new ModelicaSystem to build and simulate the BouncingBall model. Afterwards the result can be plotted in Julia.

julia> using OMJulia
julia> using CSV, DataFrames, PlotlyJS
julia> mod = OMJulia.OMCSession();[ Info: Path to zmq file="/tmp/openmodelica.runner.port.julia.EGpLhpep2A"
julia> installDir = sendExpression(mod, "getInstallationDirectoryPath()")"/usr/bin/.."
julia> bouncingBallFile = joinpath(installDir, "share", "doc", "omc", "testmodels", "BouncingBall.mo")"/usr/bin/../share/doc/omc/testmodels/BouncingBall.mo"
julia> ModelicaSystem(mod, +end BouncingBall;
Info

The BouncingBall.mo file can be found in your OpenModelica installation directory in <OpenModelcia>/share/doc/omc/testmodels/BouncingBall.mo.

ModelicaSystem

Start a new OMJulia.OMCSession and create a new ModelicaSystem to build and simulate the BouncingBall model. Afterwards the result can be plotted in Julia.

julia> using OMJulia
julia> using CSV, DataFrames, PlotlyJS
julia> mod = OMJulia.OMCSession();[ Info: Path to zmq file="/tmp/openmodelica.runner.port.julia.x81u48IKPx"
julia> installDir = sendExpression(mod, "getInstallationDirectoryPath()")"/usr/bin/.."
julia> bouncingBallFile = joinpath(installDir, "share", "doc", "omc", "testmodels", "BouncingBall.mo")"/usr/bin/../share/doc/omc/testmodels/BouncingBall.mo"
julia> ModelicaSystem(mod, bouncingBallFile, "BouncingBall")
julia> simulate(mod, resultfile = "BouncingBall_ref.csv", - simflags = "-override=outputFormat=csv,stopTime=3")
julia> resultfile = joinpath(getWorkDirectory(mod), "BouncingBall_ref.csv")"/tmp/jl_DRIqQn/BouncingBall_ref.csv"
julia> df = DataFrame(CSV.File(resultfile));
julia> plt = plot(df, + simflags = "-override=outputFormat=csv,stopTime=3")
julia> resultfile = joinpath(getWorkDirectory(mod), "BouncingBall_ref.csv")"/tmp/jl_MGH7JO/BouncingBall_ref.csv"
julia> df = DataFrame(CSV.File(resultfile));
julia> plt = plot(df, x=:time, y=:h, mode="lines", Layout(title="Bouncing Ball", height = 700))data: [ "scatter with fields mode, type, x, xaxis, y, and yaxis" ] -layout: "layout with fields height, legend, margin, template, title, xaxis, and yaxis"
julia> OMJulia.quit(mod)
+layout: "layout with fields height, legend, margin, template, title, xaxis, and yaxis"
julia> OMJulia.quit(mod)
-

OMJulia.API

Example

Start a new OMJulia.OMCSession and call scripting API directly using the OMJulia.API module.

julia> using OMJulia
julia> using OMJulia.API: API
julia> using CSV, DataFrames, PlotlyJS
julia> omc = OMJulia.OMCSession();[ Info: Path to zmq file="/tmp/openmodelica.runner.port.julia.w9HT2FoM2k"
julia> installDir = API.getInstallationDirectoryPath(omc)"/usr/bin/.."
julia> bouncingBallFile = joinpath(installDir, "share", "doc", "omc", "testmodels", "BouncingBall.mo")"/usr/bin/../share/doc/omc/testmodels/BouncingBall.mo"
julia> API.loadFile(omc, bouncingBallFile)true
julia> res = API.simulate(omc, "BouncingBall"; stopTime=3.0, outputFormat = "csv")Dict{String, Any} with 10 entries: - "timeCompile" => 0.933683 +

OMJulia.API

Example

Start a new OMJulia.OMCSession and call scripting API directly using the OMJulia.API module.

julia> using OMJulia
julia> using OMJulia.API: API
julia> using CSV, DataFrames, PlotlyJS
julia> omc = OMJulia.OMCSession();[ Info: Path to zmq file="/tmp/openmodelica.runner.port.julia.KlYEIninyE"
julia> installDir = API.getInstallationDirectoryPath(omc)"/usr/bin/.."
julia> bouncingBallFile = joinpath(installDir, "share", "doc", "omc", "testmodels", "BouncingBall.mo")"/usr/bin/../share/doc/omc/testmodels/BouncingBall.mo"
julia> API.loadFile(omc, bouncingBallFile)true
julia> res = API.simulate(omc, "BouncingBall"; stopTime=3.0, outputFormat = "csv")Dict{String, Any} with 10 entries: + "timeCompile" => 0.974328 "simulationOptions" => "startTime = 0.0, stopTime = 3.0, numberOfIntervals = … "messages" => "LOG_SUCCESS | info | The initialization fini… - "timeFrontend" => 0.00229328 - "timeTotal" => 0.963008 - "timeTemplates" => 0.00217135 - "timeSimulation" => 0.0163057 + "timeFrontend" => 0.00205366 + "timeTotal" => 1.00539 + "timeTemplates" => 0.00222063 + "timeSimulation" => 0.0172949 "resultFile" => "/home/runner/work/OMJulia.jl/OMJulia.jl/BouncingBall_… - "timeSimCode" => 0.00458408 - "timeBackend" => 0.00386704
julia> resultfile = res["resultFile"]"/home/runner/work/OMJulia.jl/OMJulia.jl/BouncingBall_res.csv"
julia> df = DataFrame(CSV.File(resultfile));
julia> plt = plot(df, + "timeSimCode" => 0.0048417 + "timeBackend" => 0.00453622
julia> resultfile = res["resultFile"]"/home/runner/work/OMJulia.jl/OMJulia.jl/BouncingBall_res.csv"
julia> df = DataFrame(CSV.File(resultfile));
julia> plt = plot(df, x=:time, y=:h, mode="lines", Layout(title="Bouncing Ball", height = 700))data: [ "scatter with fields mode, type, x, xaxis, y, and yaxis" ] -layout: "layout with fields height, legend, margin, template, title, xaxis, and yaxis"
julia> OMJulia.quit(omc)
+layout: "layout with fields height, legend, margin, template, title, xaxis, and yaxis"

julia> OMJulia.quit(omc)
-

Scripting API with sendExpression

Start a new OMJulia.OMCSession and send scripting API expressions to the omc session with sendExpression().

Warn

All special characters inside a string argument for an API function need to be escaped when passing to sendExpression.

E.g. MOS command

loadFile("/some/path/to/BouncingBall.mo");

becomes Julia code

sendExpression(omc, "loadFile(\"/some/path/to/BouncingBall.mo\")")
Info

On Windows path separation symbol \ needs to be escaped \\ or replaced to Unix style path / to prevent warnings.

julia> using OMJulia
julia> omc = OMJulia.OMCSession();[ Info: Path to zmq file="/tmp/openmodelica.runner.port.julia.nOp3rWbpoZ"
julia> installDir = sendExpression(omc, "getInstallationDirectoryPath()")"/usr/bin/.."
julia> bouncingBallFile = joinpath(installDir, "share", "doc", "omc", "testmodels", "BouncingBall.mo")"/usr/bin/../share/doc/omc/testmodels/BouncingBall.mo"
julia> if Sys.iswindows() +

Scripting API with sendExpression

Start a new OMJulia.OMCSession and send scripting API expressions to the omc session with sendExpression().

Warn

All special characters inside a string argument for an API function need to be escaped when passing to sendExpression.

E.g. MOS command

loadFile("/some/path/to/BouncingBall.mo");

becomes Julia code

sendExpression(omc, "loadFile(\"/some/path/to/BouncingBall.mo\")")
Info

On Windows path separation symbol \ needs to be escaped \\ or replaced to Unix style path / to prevent warnings.

julia> using OMJulia
julia> omc = OMJulia.OMCSession();[ Info: Path to zmq file="/tmp/openmodelica.runner.port.julia.SLTSKyRvVY"
julia> installDir = sendExpression(omc, "getInstallationDirectoryPath()")"/usr/bin/.."
julia> bouncingBallFile = joinpath(installDir, "share", "doc", "omc", "testmodels", "BouncingBall.mo")"/usr/bin/../share/doc/omc/testmodels/BouncingBall.mo"
julia> if Sys.iswindows() bouncingBallFile = replace(bouncingBallFile, "\\" => "/") end
julia> sendExpression(omc, "loadFile(\"$(bouncingBallFile)\")")true
julia> sendExpression(omc, "simulate(BouncingBall)")Dict{String, Any} with 10 entries: - "timeCompile" => 0.935007 + "timeCompile" => 0.97281 "simulationOptions" => "startTime = 0.0, stopTime = 1.0, numberOfIntervals = … "messages" => "LOG_SUCCESS | info | The initialization fini… - "timeFrontend" => 0.00218336 - "timeTotal" => 0.961981 - "timeTemplates" => 0.00230437 - "timeSimulation" => 0.0133282 + "timeFrontend" => 0.00236354 + "timeTotal" => 1.00119 + "timeTemplates" => 0.00267323 + "timeSimulation" => 0.0138314 "resultFile" => "/home/runner/work/OMJulia.jl/OMJulia.jl/docs/omc-temp… - "timeSimCode" => 0.0010991 - "timeBackend" => 0.00795902
julia> OMJulia.quit(omc)
+ "timeSimCode" => 0.00123324 + "timeBackend" => 0.00816155

julia> OMJulia.quit(omc)
diff --git a/dev/search/index.html b/dev/search/index.html index 643c506..e9245e5 100644 --- a/dev/search/index.html +++ b/dev/search/index.html @@ -1,2 +1,2 @@ -Search · OMJulia.jl

Loading search...

    +Search · OMJulia.jl

    Loading search...

      diff --git a/dev/search_index.js b/dev/search_index.js index feca282..0b6798c 100644 --- a/dev/search_index.js +++ b/dev/search_index.js @@ -1,3 +1,3 @@ var documenterSearchIndex = {"docs": -[{"location":"sendExpression/#sendExpression","page":"sendExpression","title":"sendExpression","text":"","category":"section"},{"location":"sendExpression/","page":"sendExpression","title":"sendExpression","text":"Start a new OMCSession and send scripting API expressions to the omc session with sendExpression().","category":"page"},{"location":"sendExpression/","page":"sendExpression","title":"sendExpression","text":"sendExpression","category":"page"},{"location":"sendExpression/#OMJulia.sendExpression","page":"sendExpression","title":"OMJulia.sendExpression","text":"sendExpression(omc, expr; parsed=true)\n\nSend API call to OpenModelica ZMQ server. See OpenModelica User's Guide Scripting API for a complete list of all functions.\n\nnote: Note\nSome characters in argument expr need to be escaped. E.g. \" becomes \\\". For example scripting API callloadFile(\"/path/to/M.mo\")will translate tosendExpression(omc, \"loadFile(\\\"/path/to/M.mo\\\")\")\n\nwarn: Warn\nOn Windows path separation symbol \\ needs to be escaped \\\\ or replaced to Unix style path / to prevent warnings.loadFile(\"C:\\\\path\\\\to\\\\M.mo\")translate tosendExpression(omc, \"loadFile(\\\"C:\\\\\\\\path\\\\\\\\to\\\\\\\\M.mo\\\")\") # Windows\nsendExpression(omc, \"loadFile(\\\"/c/path/to/M.mo\\\")\") # Windows\n\nExample\n\nusing OMJulia\nomc = OMJulia.OMCSession()\nOMJulia.sendExpression(omc, \"getVersion()\")\n\n\n\n\n\n","category":"function"},{"location":"sendExpression/#Examples","page":"sendExpression","title":"Examples","text":"","category":"section"},{"location":"sendExpression/","page":"sendExpression","title":"sendExpression","text":"using OMJulia # hide\nomc = OMJulia.OMCSession() # hide\nversion = OMJulia.sendExpression(omc, \"getVersion()\")\nOMJulia.quit(omc)","category":"page"},{"location":"api/#OMJulia.API","page":"OMJulia.API","title":"OMJulia.API","text":"","category":"section"},{"location":"api/","page":"OMJulia.API","title":"OMJulia.API","text":"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.","category":"page"},{"location":"api/","page":"OMJulia.API","title":"OMJulia.API","text":"warn: Warn\nNot all OMJulia.API functions are tested and some functions could have slightly different default values compared to the OpenModelica scripting API.","category":"page"},{"location":"api/","page":"OMJulia.API","title":"OMJulia.API","text":"Instead of escaping strings yourself the API interface handles this for you:","category":"page"},{"location":"api/","page":"OMJulia.API","title":"OMJulia.API","text":"sendExpression(omc, \"loadFile(\\\"$(bouncingBallFile)\\\")\")","category":"page"},{"location":"api/","page":"OMJulia.API","title":"OMJulia.API","text":"becomes","category":"page"},{"location":"api/","page":"OMJulia.API","title":"OMJulia.API","text":"API.loadFile(omc, bouncingBallFile)","category":"page"},{"location":"api/#Functions","page":"OMJulia.API","title":"Functions","text":"","category":"section"},{"location":"api/","page":"OMJulia.API","title":"OMJulia.API","text":"Modules = [OMJulia.API]\nOrder = [:function, :type]\nFilter = t -> t != OMJulia.API.modelicaString","category":"page"},{"location":"api/#OMJulia.API.buildModel-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.buildModel","text":"buildModel(omc, className;\n startTime = 0.0,\n stopTime = 1.0,\n numberOfIntervals = 500,\n tolerance = 1e-6,\n method = \"\",\n fileNamePrefix = className,\n options = \"\",\n outputFormat = \"mat\",\n variableFilter = \".*\",\n cflags = \"\",\n simflags = \"\")\n\nBuild Modelica model by generating C code and compiling it into an executable simulation. It does not run the simulation!\n\nSee OpenModelica scripting API buildModel.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.buildModelFMU-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.buildModelFMU","text":"buildModelFMU(omc, className;\n version = \"2.0\",\n fmuType = \"me\",\n fileNamePrefix=className,\n platforms=[\"static\"],\n includeResources = false)\n\nTranslates a modelica model into a Functional Mockup Unit. The only required argument is the className, while all others have some default values.\n\nSee OpenModelica scripting API buildModelFMU.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.cd","page":"OMJulia.API","title":"OMJulia.API.cd","text":"cd(omc, newWorkingDirectory=\"\")\n\nChange 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.\n\nSee OpenModelica scripting API cd.\n\n\n\n\n\n","category":"function"},{"location":"api/#OMJulia.API.closeSimulationResultFile-Tuple{OMJulia.OMCSession}","page":"OMJulia.API","title":"OMJulia.API.closeSimulationResultFile","text":" closeSimulationResultFile(omc)\n\nCloses 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.\n\nSee OpenModelica scripting API closeSimulationResultFile.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.diffSimulationResults-Tuple{OMJulia.OMCSession, String, String, String}","page":"OMJulia.API","title":"OMJulia.API.diffSimulationResults","text":"diffSimulationResults(omc, actualFile, expectedFile, diffPrefix;\n relTol = 1e-3,\n relTolDiffMinMax = 1e-4,\n rangeDelta = 0.002,\n vars = String[],\n keepEqualResults = false)\n\nCompares simulation results.\n\nSee OpenModelica scripting API diffSimulationResults.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.getClassNames-Tuple{OMJulia.OMCSession}","page":"OMJulia.API","title":"OMJulia.API.getClassNames","text":"getClassNames(omc;\n class_ = \"\",\n recursive = false,\n qualified = false,\n sort = false,\n builtin = false,\n showProtected = false,\n includeConstants = false)\n\nReturns the list of class names defined in the class.\n\nSee OpenModelica scripting API getClassNames.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.getErrorString-Tuple{OMJulia.OMCSession}","page":"OMJulia.API","title":"OMJulia.API.getErrorString","text":"getErrorString(omc, warningsAsErrors = false)\n\nReturns the current error message.\n\nSee OpenModelica scripting API getErrorString.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.getInstallationDirectoryPath-Tuple{OMJulia.OMCSession}","page":"OMJulia.API","title":"OMJulia.API.getInstallationDirectoryPath","text":"getInstallationDirectoryPath(omc)\n\nThis returns OPENMODELICAHOME if it is set; on some platforms the default path is returned if it is not set.\n\nSee OpenModelica scripting API getInstallationDirectoryPath.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.getVersion-Tuple{OMJulia.OMCSession}","page":"OMJulia.API","title":"OMJulia.API.getVersion","text":"getVersion(omc)\n\nReturns the version of the Modelica compiler.\n\nSee OpenModelica scripting API getVersion.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.instantiateModel-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.instantiateModel","text":"instantiateModel(omc, className)\n\nInstantiates the class and returns the flat Modelica code.\n\nSee OpenModelica scripting API instantiateModel.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.linearize-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.linearize","text":"Creates a model with symbolic linearization matrices.\n\nSee OpenModelica scripting API linearize.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.loadFile-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.loadFile","text":"loadFile(omc, fileName;\n encoding = \"\",\n uses = true,\n notify = true,\n requireExactVersion = false)\n\nLoad file fileName (*.mo) and merge it with the loaded AST. See OpenModelica scripting API loadFile.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.loadModel-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.loadModel","text":"loadModel(omc, className;\n priorityVersion = String[],\n notify = false,\n languageStandard = \"\",\n requireExactVersion = false)\n\nLoads a Modelica library.\n\nSee OpenModelica scripting API loadModel.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.makeVectorString-Tuple{Vector{String}}","page":"OMJulia.API","title":"OMJulia.API.makeVectorString","text":"makeVectorString(vec)\n\nAdd quotes around each string element.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.readSimulationResult","page":"OMJulia.API","title":"OMJulia.API.readSimulationResult","text":"readSimulationResult(omc, filename,\n variables = String[],\n size = 0)\n\nReads a result file, returning a matrix corresponding to the variables and size given.\n\nSee OpenModelica scripting API readSimulationResult.\n\n\n\n\n\n","category":"function"},{"location":"api/#OMJulia.API.readSimulationResultSize-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.readSimulationResultSize","text":"readSimulationResultSize(omc, fileName)\n\nThe number of intervals that are present in the output file.\n\nSee OpenModelica scripting API readSimulationResultSize.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.readSimulationResultVars-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.readSimulationResultVars","text":"readSimulationResultVars(omc, fileName; readParameters = true, openmodelicaStyle = false)\n\nReturns the variables in the simulation file; you can use val() and plot() commands using these names.\n\nSee OpenModelica scripting API readSimulationResultVars.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.setCommandLineOptions-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.setCommandLineOptions","text":"setCommandLineOptions(omc, option)\n\nThe input is a regular command-line flag given to OMC, e.g. -d=failtrace or -g=MetaModelica.\n\nSee OpenModelica scripting API setCommandLineOptions.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.simulate-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.simulate","text":"simulate(omc, className;\n startTime = 0.0,\n stopTime = nothing,\n numberOfIntervals = 500,\n tolerance = 1e-6,\n method = \"\",\n fileNamePrefix=className,\n options = \"\",\n outputFormat = \"mat\",\n variableFilter = \".*\",\n cflags = \"\",\n simflags = \"\")\n\nSimulates a modelica model by generating C code, build it and run the simulation executable.\n\nSee OpenModelica scripting API simulate.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.ScriptingError","page":"OMJulia.API","title":"OMJulia.API.ScriptingError","text":"ScriptingError <: Exception\n\nOpenModelica scripting error with message msg and additional error string from getErrroString.\n\n\n\n\n\n","category":"type"},{"location":"quickstart/#Quickstart","page":"Quickstart","title":"Quickstart","text":"","category":"section"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"There are three ways to interact with OpenModelica:","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"ModelicaSystem: A Julia style scripting API that handles low level API calls.\nOMJulia.API: A Julia style scripting API that handles low level sendExpression calls and has some degree of error handling.\nScripting API with sendExpression: Send expressions to the low level OpenModelica scripting API.","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"The following examples demonstrate how to simulate Modelica model BouncingBall in both ways.","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"model BouncingBall\n parameter Real e=0.7 \"coefficient of restitution\";\n parameter Real g=9.81 \"gravity acceleration\";\n Real h(fixed=true, start=1) \"height of ball\";\n Real v(fixed=true) \"velocity of ball\";\n Boolean flying(fixed=true, start=true) \"true, if ball is flying\";\n Boolean impact;\n Real v_new(fixed=true);\n Integer foo;\nequation\n impact = h <= 0.0;\n foo = if impact then 1 else 2;\n der(v) = if flying then -g else 0;\n der(h) = v;\n\n when {h <= 0.0 and v <= 0.0,impact} then\n v_new = if edge(impact) then -e*pre(v) else 0;\n flying = v_new > 0;\n reinit(v, v_new);\n end when;\nend BouncingBall;","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"info: Info\nThe BouncingBall.mo file can be found in your OpenModelica installation directory in /share/doc/omc/testmodels/BouncingBall.mo.","category":"page"},{"location":"quickstart/#modelicasystem","page":"Quickstart","title":"ModelicaSystem","text":"","category":"section"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"Start a new OMJulia.OMCSession and create a new ModelicaSystem to build and simulate the BouncingBall model. Afterwards the result can be plotted in Julia.","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"using OMJulia\nusing CSV, DataFrames, PlotlyJS\nusing PlotlyDocumenter # hide\n\nmod = OMJulia.OMCSession();\n\ninstallDir = sendExpression(mod, \"getInstallationDirectoryPath()\")\nbouncingBallFile = joinpath(installDir, \"share\", \"doc\", \"omc\", \"testmodels\", \"BouncingBall.mo\")\n\nModelicaSystem(mod,\n bouncingBallFile,\n \"BouncingBall\")\nsimulate(mod,\n resultfile = \"BouncingBall_ref.csv\",\n simflags = \"-override=outputFormat=csv,stopTime=3\")\n\nresultfile = joinpath(getWorkDirectory(mod), \"BouncingBall_ref.csv\")\ndf = DataFrame(CSV.File(resultfile));\n\nplt = plot(df,\n x=:time, y=:h,\n mode=\"lines\",\n Layout(title=\"Bouncing Ball\", height = 700))\n\nOMJulia.quit(mod)","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"PlotlyDocumenter.to_documenter(plt) # hide","category":"page"},{"location":"quickstart/#omjulia-api","page":"Quickstart","title":"OMJulia.API","text":"","category":"section"},{"location":"quickstart/#Example","page":"Quickstart","title":"Example","text":"","category":"section"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"Start a new OMJulia.OMCSession and call scripting API directly using the OMJulia.API module.","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"using OMJulia\nusing OMJulia.API: API\n\nusing CSV, DataFrames, PlotlyJS\nusing PlotlyDocumenter # hide\n\nomc = OMJulia.OMCSession();\nomcWorkDir = mkpath(joinpath(\"docs\", \"omc-temp\")) # hide\nmkpath(omcWorkDir) # hide\nAPI.cd(omcWorkDir) # hide\ninstallDir = API.getInstallationDirectoryPath(omc)\nbouncingBallFile = joinpath(installDir, \"share\", \"doc\", \"omc\", \"testmodels\", \"BouncingBall.mo\")\nbouncingBallFile = abspath(bouncingBallFile) # hide\nAPI.loadFile(omc, bouncingBallFile)\nres = API.simulate(omc, \"BouncingBall\"; stopTime=3.0, outputFormat = \"csv\")\nresultfile = res[\"resultFile\"]\ndf = DataFrame(CSV.File(resultfile));\n\nplt = plot(df,\n x=:time, y=:h,\n mode=\"lines\",\n Layout(title=\"Bouncing Ball\", height = 700))\n\nOMJulia.quit(omc)","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"PlotlyDocumenter.to_documenter(plt) # hide","category":"page"},{"location":"quickstart/#scripting-api-with-sendExpression","page":"Quickstart","title":"Scripting API with sendExpression","text":"","category":"section"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"Start a new OMJulia.OMCSession and send scripting API expressions to the omc session with sendExpression().","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"warn: Warn\nAll special characters inside a string argument for an API function need to be escaped when passing to sendExpression.E.g. MOS commandloadFile(\"/some/path/to/BouncingBall.mo\");becomes Julia codesendExpression(omc, \"loadFile(\\\"/some/path/to/BouncingBall.mo\\\")\")","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"info: Info\nOn Windows path separation symbol \\ needs to be escaped \\\\ or replaced to Unix style path / to prevent warnings.","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"using OMJulia\n\nomc = OMJulia.OMCSession();\nomcWorkDir = mkpath(joinpath(\"docs\", \"omc-temp\")) # hide\nmkpath(omcWorkDir) # hide\nsendExpression(omc, \"cd(\\\"$(omcWorkDir)\\\")\") # hide\ninstallDir = sendExpression(omc, \"getInstallationDirectoryPath()\")\nbouncingBallFile = joinpath(installDir, \"share\", \"doc\", \"omc\", \"testmodels\", \"BouncingBall.mo\")\nbouncingBallFile = abspath(bouncingBallFile) # hide\nif Sys.iswindows()\n bouncingBallFile = replace(bouncingBallFile, \"\\\\\" => \"/\")\nend\nsendExpression(omc, \"loadFile(\\\"$(bouncingBallFile)\\\")\")\nsendExpression(omc, \"simulate(BouncingBall)\")\nOMJulia.quit(omc)","category":"page"},{"location":"#OMJulia.jl","page":"Home","title":"OMJulia.jl","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Julia scripting OpenModelica interface.","category":"page"},{"location":"#Overview","page":"Home","title":"Overview","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"OMJulia - the OpenModelica Julia API is a free, open source, highly portable Julia based interactive session handler for Julia scripting of OpenModelica API functionality. It provides the modeler with components for creating a complete Julia-Modelica modeling, compilation and simulation environment based on the latest OpenModelica implementation and Modelica library standard available.","category":"page"},{"location":"","page":"Home","title":"Home","text":"OMJulia is structured to combine both the solving strategy and model building. Thus, domain experts (people writing the models) and computational engineers (people writing the solver code) can work on one unified tool that is industrially viable for optimization of Modelica models, while offering a flexible platform for algorithm development and research. OMJulia is not a standalone package, it depends upon the OpenModelica installation.","category":"page"},{"location":"","page":"Home","title":"Home","text":"OMJulia is implemented in Julia and depends on ZeroMQ - high performance asynchronous messaging library and it supports the Modelica Standard Library version 4.0 that is included with OpenModelica.","category":"page"},{"location":"#Installation","page":"Home","title":"Installation","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Make sure OpenModelica is installed.","category":"page"},{"location":"","page":"Home","title":"Home","text":"Install OMJulia.jl with:","category":"page"},{"location":"","page":"Home","title":"Home","text":"julia> import Pkg; Pkg.add(\"OMJulia\")","category":"page"},{"location":"#Features-of-OMJulia","page":"Home","title":"Features of OMJulia","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"The OMJulia package contains the following features:","category":"page"},{"location":"","page":"Home","title":"Home","text":"Interactive session handling, parsing, interpretation of commands and Modelica expressions for evaluation, simulation, plotting, etc.\nConnect with the OpenModelica compiler through zmq sockets\nAble to interact with the OpenModelica compiler through the available API\nEasy access to the Modelica Standard library.\nAll the API calls are communicated with the help of the sendExpression method implemented in a Julia module\nThe results are returned as strings","category":"page"},{"location":"modelicaSystem/#Advanced-API","page":"ModelicaSystem","title":"Advanced API","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"A Julia style scripting API that handles low level API calls.","category":"page"},{"location":"modelicaSystem/#ModelicaSystem","page":"ModelicaSystem","title":"ModelicaSystem","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"ModelicaSystem","category":"page"},{"location":"modelicaSystem/#OMJulia.ModelicaSystem","page":"ModelicaSystem","title":"OMJulia.ModelicaSystem","text":"ModelicaSystem(omc, fileName, modelName, library=nothing;\n commandLineOptions=nothing, variableFilter=nothing, customBuildDirectory=nothing)\n\nSet command line options for OMCSession and build model modelName to prepare for a simulation.\n\nArguments\n\nomc: OpenModelica compiler session, see OMCSession().\nfileName: Path to Modelica file.\nmodelName: Name of Modelica model to build, including namespace if the model is wrappen within a Modelica package.\nlibrary: List of dependent libraries or Modelica files. This argument can be passed as string (e.g. \"Modelica\") or tuple (e.g. (\"Modelica\", \"4.0\") or array (e.g. [\"Modelica\", \"SystemDynamics\"] or [(\"Modelica\", \"4.0\"), \"SystemDynamics\"]).\n\nKeyword Arguments\n\ncommandLineOptions: OpenModelica command line options, see OpenModelica Compiler Flags.\nvariableFilter: Regex to filter variables in result file.\n\nUsage\n\nusing OMJulia\nmod = OMJulia.OMCSession()\nModelicaSystem(mod, \"BouncingBall.mo\", \"BouncingBall\", [\"Modelica\", \"SystemDynamics\"], commandLineOptions=\"-d=newInst\")\n\nProviding dependent libaries:\n\nusing OMJulia\nmod = OMJulia.OMCSession()\nModelicaSystem(mod, \"BouncingBall.mo\", \"BouncingBall\", [\"Modelica\", \"SystemDynamics\", \"dcmotor.mo\"])\n\nSee also OMCSession().\n\n\n\n\n\nModelicaSystem(omc; modelName, library=nothing,\n commandLineOptions=nothing, variableFilter=nothing, customBuildDirectory=nothing)\n\nSet command line options for OMCSession and build model modelname to prepare for a simulation.\n\nArguments\n\nomc: OpenModelica compiler session, see OMCSession().\n\nKeyword Arguments\n\nmodelName: Name of Modelica model to build, including namespace if the model is wrappen within a Modelica package.\nlibrary: List of dependent libraries or Modelica files. This argument can be passed as string (e.g. \"Modelica\") or tuple (e.g. (\"Modelica\", \"4.0\") or array (e.g. [\"Modelica\", \"SystemDynamics\"] or [(\"Modelica\", \"4.0\"), \"SystemDynamics\"]).\ncommandLineOptions: OpenModelica command line options, see OpenModelica Compiler Flags.\nvariableFilter: Regex to filter variables in result file.\n\nUsage\n\nusing OMJulia\nmod = OMJulia.OMCSession()\nModelicaSystem(mod, modelName=\"Modelica.Electrical.Analog.Examples.CauerLowPassAnalog\", library=\"Modelica\")\n\nSee also OMCSession().\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"OMJulia.OMCSession\nOMJulia.quit","category":"page"},{"location":"modelicaSystem/#OMJulia.OMCSession","page":"ModelicaSystem","title":"OMJulia.OMCSession","text":"OMCSession <: Any\n\nOMC session struct.\n\n\n\nOMCSession(omc=nothing)\n\nCreate new OpenModelica session.\n\nArguments\n\nomc::Union{String, Nothing}: Path to OpenModelica compiler. Use omc from PATH if nothing is provided.\n\nSee also ModelicaSystem, OMJulia.quit.\n\n\n\n\n\n","category":"type"},{"location":"modelicaSystem/#OMJulia.quit","page":"ModelicaSystem","title":"OMJulia.quit","text":"quit(omc::OMCSession; timeout=4::Integer)\n\nQuit OMCSession.\n\nArguments\n\n- `omc::OMCSession`: OMC session.\n\nKeywords\n\n- `timeout=4::Integer`: Timeout in seconds.\n\nSee also OMJulia.OMCSession.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#Example","page":"ModelicaSystem","title":"Example","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"Let us see the usage of ModelicaSystem with the help of Modelica model ModSeborgCSTRorg","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"model ModSeborgCSTRorg\n // Model of original Seborg CSTR in ode form\n // author: Bernt Lie, University of Southeast Norway,November 7, 2017\n\n // Parameters\n parameter Real V = 100 \"Reactor volume, L\";\n parameter Real rho = 1e3 \"Liquid density, g/L\";\n parameter Real a = 1 \"Stoichiometric constant, -\";\n parameter Real EdR = 8750 \"Activation temperature, K\";\n parameter Real k0 = exp(EdR/350) \"Pre-exponential factor, 1/min\";\n parameter Real cph = 0.239 \"Specific heat capacity of mixture, J.g-1.K-1\";\n parameter Real DrHt = -5e4 \"Molar enthalpy of reaction, J/mol\";\n parameter Real UA = 5e4 \"Heat transfer parameter, J/(min.K)\";\n\n // Initial state parameters\n parameter Real cA0 = 0.5 \"Initial concentration of A, mol/L\";\n parameter Real T0 = 350 \"Initial temperature, K\";\n // Declaring variables\n // -- states\n Real cA(start = cA0, fixed = true) \"Initializing concentration of A in reactor, mol/L\";\n Real T(start = T0, fixed = true) \"Initializing temperature in reactor, K\";\n // -- auxiliary variables\n Real r \"Rate of reaction, mol/(L.s)\";\n Real k \"Reaction 'constant', ...\";\n Real Qd \"Heat flow rate, J/min\";\n // -- input variables\n input Real Vdi \"Volumetric flow rate through reactor, L/min\";\n input Real cAi \"Influent molar concentration of A, mol/L\";\n input Real Ti \"Influent temperature, K\";\n input Real Tc \"Cooling temperature', K\";\n // -- output variables\n output Real y_T \"Reactor temperature, K\";\n // Equations constituting the model\nequation\n // Differential equations\n der(cA) = Vdi*(cAi-cA)/V- a*r;\n der(T) = Vdi*(Ti-T)/V + (-DrHt)*r/(rho*cph) + Qd/(rho*V*cph);\n // Algebraic equations\n r = k*cA^a;\n k = k0*exp(-EdR/T);\n Qd = UA*(Tc-T);\n // Outputs\n y_T = T;\nend ModSeborgCSTRorg","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"using OMJulia\nmod = OMJulia.OMCSession()\nomcWorkDir = mkpath(joinpath(\"docs\", \"omc-temp\")) # hide\nmkpath(omcWorkDir) # hide\nsendExpression(mod, \"cd(\\\"$(omcWorkDir)\\\")\") # hide\nModelicaSystem(mod,\n joinpath(\"docs\", \"testmodels\", \"ModSeborgCSTRorg.mo\"),\n \"ModSeborgCSTRorg\")","category":"page"},{"location":"modelicaSystem/#WorkDirectory","page":"ModelicaSystem","title":"WorkDirectory","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"For each OMJulia.OMCSession session a temporary work directory is created and the results are published in that working directory. In order to get the work directory use getWorkDirectory.","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getWorkDirectory","category":"page"},{"location":"modelicaSystem/#OMJulia.getWorkDirectory","page":"ModelicaSystem","title":"OMJulia.getWorkDirectory","text":"getWorkDirectory(omc)\n\nReturn working directory of OMJulia.OMCsession omc.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getWorkDirectory(mod)","category":"page"},{"location":"modelicaSystem/#Build-Model","page":"ModelicaSystem","title":"Build Model","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"buildModel","category":"page"},{"location":"modelicaSystem/#OMJulia.buildModel","page":"ModelicaSystem","title":"OMJulia.buildModel","text":"buildModel(omc; variableFilter=nothing)\n\nBuild modelica model.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\n\nKeyword Arguments\n\nvariableFilter: Regex to filter variables in result file.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"In case the Modelica model needs to be updated or additional simulation flags needs to be set using sendExpression The buildModel API can be used after ModelicaSystem.","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"buildModel(omc)\nbuildModel(omc, variableFilter=\"a|T\")","category":"page"},{"location":"modelicaSystem/#Get-Methods","page":"ModelicaSystem","title":"Get Methods","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getQuantities\nshowQuantities\ngetContinuous\ngetInputs\ngetOutputs\ngetParameters\ngetSimulationOptions\ngetSolutions","category":"page"},{"location":"modelicaSystem/#OMJulia.getQuantities","page":"ModelicaSystem","title":"OMJulia.getQuantities","text":"getQuantities(omc, name=nothing)\n\nReturn list of all variables parsed from xml file.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of variables to read from xml file. If nothing is provided read all variables.\n\nSee also showQuantities.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.showQuantities","page":"ModelicaSystem","title":"OMJulia.showQuantities","text":"showQuantities(omc, name=nothing)\n\nReturn DataFrame of all variables parsed from xml file.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of variables to read from xml file. If nothing is provided read all variables.\n\nSee also getQuantities.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.getContinuous","page":"ModelicaSystem","title":"OMJulia.getContinuous","text":"getContinuous(omc, name=nothing)\n\nReturn continuous variables parsed from xml file.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of continuous variables to read from xml file. If nothing is provided read all continuous variables.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.getInputs","page":"ModelicaSystem","title":"OMJulia.getInputs","text":"getInputs(omc, name=nothing)\n\nReturn input variables parsed from xml file. If input variables have no start value the returned value is \"None\".\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of input variables to read from xml file. If nothing is provided read all input variables.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.getOutputs","page":"ModelicaSystem","title":"OMJulia.getOutputs","text":"getInputs(omc, name=nothing)\n\nReturn output variables parsed from xml file. If output variables have no start value the returned value is \"None\".\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of output variables to read from xml file. If nothing is provided read all output variables.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.getParameters","page":"ModelicaSystem","title":"OMJulia.getParameters","text":"getParameters(omc, name=nothing)\n\nReturn parameter variables parsed from xml file.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of parameters to read from xml file. If nothing is provided read all parameters.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.getSimulationOptions","page":"ModelicaSystem","title":"OMJulia.getSimulationOptions","text":"getSimulationOptions(omc, name=nothing)\n\nReturn SimulationOption variables parsed from xml file.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of parameters to read from xml file. If nothing is provided read all parameters.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.getSolutions","page":"ModelicaSystem","title":"OMJulia.getSolutions","text":"getSolutions(omc::OMCSession, name=nothing; resultfile=nothing)\n\nRead result file and return simulation results\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of variables to read from result file. If nothing is provided read all variables.\n\nKeyword Arguments\n\nresultfile::Union{AbstractString, Nothing}: Path to result file. If nothing is provided use saved result file.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#Examples","page":"ModelicaSystem","title":"Examples","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getQuantities(mod)\ngetQuantities(mod, \"T\")\ngetQuantities(mod, [\"T\",\"cA\"])\nshowQuantities(mod)","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getContinuous(mod)\ngetContinuous(mod, [\"Qd\",\"Tc\"])","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getInputs(mod)\ngetOutputs(mod)","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getParameters(mod)\ngetParameters(mod, [\"a\",\"V\"])","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getSimulationOptions(mod)\ngetSimulationOptions(mod, [\"stepSize\",\"tolerance\"])","category":"page"},{"location":"modelicaSystem/#Reading-Simulation-Results","page":"ModelicaSystem","title":"Reading Simulation Results","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"To read the simulation results, we need to simulate the model first and use the getSolution() API to read the results","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"simulate(mod)","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"The getSolution method can be used in two different ways.","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"using default result filename\nuse the result filenames provided by user","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"This provides a way to compare simulation results and perform regression testing","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getSolutions(mod)\ngetSolutions(mod, [\"time\",\"a\"])","category":"page"},{"location":"modelicaSystem/#Examples-of-using-resultFile-provided-by-user-location","page":"ModelicaSystem","title":"Examples of using resultFile provided by user location","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getSolutions(mod, resultfile=\"C:/BouncingBal/tmpbouncingBall.mat\") //returns list of simulation variables for which results are available , the resulfile location is provided by user\ngetSolutions(mod, [\"time\",\"h\"], resultfile=\"C:/BouncingBal/tmpbouncingBall.mat\") // return list of array","category":"page"},{"location":"modelicaSystem/#Set-Methods","page":"ModelicaSystem","title":"Set Methods","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"setInputs\nsetParameters\nsetSimulationOptions","category":"page"},{"location":"modelicaSystem/#OMJulia.setInputs","page":"ModelicaSystem","title":"OMJulia.setInputs","text":"setInputs(omc, name)\n\nSet new values for input variables.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}}: String \"Name=value\" or vector of strings [\"Name1=value1\",\"Name2=value2\",\"Name3=value3\"])\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.setParameters","page":"ModelicaSystem","title":"OMJulia.setParameters","text":"setParameters(omc, name; verbose=true)\n\nSet parameter values for parameter variables defined by users\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}}: String \"Name=value\" or vector of strings [\"Name1=value1\",\"Name2=value2\",\"Name3=value3\"])\n\nKeyword Arguments\n\nverbose::Bool: Display additional info if setParameters failed.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.setSimulationOptions","page":"ModelicaSystem","title":"OMJulia.setSimulationOptions","text":"setSimulationOptions(omc, name)\n\nSet simulation option values like stopTime or stepSize.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}}: String \"Name=value\" or vector of strings [\"Name1=value1\",\"Name2=value2\",\"Name3=value3\"])\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#Examples-2","page":"ModelicaSystem","title":"Examples","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"setInputs(mod, \"cAi=100\")\nsetInputs(mod, [\"cAi=100\",\"Ti=200\",\"Vdi=300\",\"Tc=250\"])","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"setParameters(mod, \"a=3\")\nsetParameters(mod, [\"a=4\",\"V=200\"])","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"setSimulationOptions(mod, [\"stopTime=2.0\", \"tolerance=1e-08\"])","category":"page"},{"location":"modelicaSystem/#Advanced-Simulation","page":"ModelicaSystem","title":"Advanced Simulation","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"simulate","category":"page"},{"location":"modelicaSystem/#OMJulia.simulate","page":"ModelicaSystem","title":"OMJulia.simulate","text":"simulate(omc; resultfile=nothing, simflags=\"\", verbose=false)\n\nSimulate modelica model.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session, see OMCSession().\n\nKeyword Arguments\n\nresultFile::Union{String, Nothing}: Result file to write simulation results into.\nsimflags::String: Simulation flags, see Simulation Runtime Flags.\nverbose::Bool: [debug] Log cmd call to log.txt and error.txt.\n\nExamples\n\nsimulate(omc)\n\nSpecify result file:\n\nsimulate(omc, resultfile=\"tmpresult.mat\")\n\nSet simulation runtime flags:\n\nsimulate(omc, simflags=\"-noEmitEvent -override=e=0.3,g=9.3\")\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"An example of how to do advanced simulation to set parameter values using set methods and finally simulate the \"ModSeborgCSTRorg.mo\" model is given below .","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getParameters(mod)\nsetParameters(mod, \"a=3.0\")","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"To check whether new values are updated to model , we can again query the getParameters().","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getParameters(mod)","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"Similary we can also use setInputs() to set a value for the inputs during various time interval can also be done using the following.","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"setInputs(mod, \"cAi=100\")","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"And finally we simulate the model","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"simulate(mod)","category":"page"},{"location":"modelicaSystem/#Linearization","page":"ModelicaSystem","title":"Linearization","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"linearize\ngetLinearizationOptions\nsetLinearizationOptions\ngetLinearInputs\ngetLinearOutputs\ngetLinearStates","category":"page"},{"location":"modelicaSystem/#OMJulia.linearize","page":"ModelicaSystem","title":"OMJulia.linearize","text":"function which returns the linearize model of modelica model, The function returns four matrices A, B, C, D\n\nlinearize(omc; lintime = nothing, simflags= nothing, verbose=true)\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\n\nKeyword Arguments\n\nlintime : Value specifies a time where the linearization of the model should be performed\nsimflags: Simulation flags, see Simulation Runtime Flags.\n\nExamples of using linearize() API\n\nlinearize(omc)\n\nSpecify result file:\n\nlinearize(omc, lintime=\"0.5\")\n\nSet simulation runtime flags:\n\nlinearize(omc, simflags=\"-noEmitEvent\")\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.getLinearizationOptions","page":"ModelicaSystem","title":"OMJulia.getLinearizationOptions","text":"getLinearizationOptions(omc, name=nothing)\n\nReturn linearization options.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of linearization options. If nothing is provided return all linearization options.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.setLinearizationOptions","page":"ModelicaSystem","title":"OMJulia.setLinearizationOptions","text":"setLinearizationOptions(omc, name)\n\nSet linearization options.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}}: String \"Name=value\" or vector of strings [\"Name1=value1\",\"Name2=value2\",\"Name3=value3\"])\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.getLinearInputs","page":"ModelicaSystem","title":"OMJulia.getLinearInputs","text":"getLinearInputs(omc)\n\nReturn linear input variables after the model is linearized\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.getLinearOutputs","page":"ModelicaSystem","title":"OMJulia.getLinearOutputs","text":"getLinearOutputs(omc)\n\nReturn linear output variables after the model is linearized\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.getLinearStates","page":"ModelicaSystem","title":"OMJulia.getLinearStates","text":"getLinearStates(omc)\n\nReturn linear state variables after the model is linearized\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#Examples-3","page":"ModelicaSystem","title":"Examples","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getLinearizationOptions(mod)\ngetLinearizationOptions(mod, [\"startTime\",\"stopTime\"])","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"setLinearizationOptions(mod,[\"stopTime=2.0\",\"tolerance=1e-06\"])","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"res = linearize(mod)","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getLinearInputs(mod)\ngetLinearOutputs(mod)\ngetLinearStates(mod)","category":"page"},{"location":"modelicaSystem/#Sensitivity-Analysis","page":"ModelicaSystem","title":"Sensitivity Analysis","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"sensitivity","category":"page"},{"location":"modelicaSystem/#OMJulia.sensitivity","page":"ModelicaSystem","title":"OMJulia.sensitivity","text":"sensitivity(omc::OMCSession, Vp, Vv, Ve=[1e-2])\n\nMethod for computing numeric sensitivity of OpenModelica object.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nVp::Array{<:AbstractString, 1}: Modelica Parameter names.\nVv::Array{<:AbstractString, 1}: Modelica Variable names.\nVe::Array{Float64, 1}: Excitations of parameters; defaults to scalar 1e-2\n\nReturn\n\nVSname::Vector{Vector{String}}: Vector of sensitivity names\nVSarray::Vector{Vector{Vector{Float64}}}: Vector of sensitivies: vector of elements per parameter\n\nEach element containing time series per variable\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#Examples-4","page":"ModelicaSystem","title":"Examples","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"(Sn, Sa) = sensitivity(mod, [\"UA\",\"EdR\"], [\"T\",\"cA\"], [1e-2,1e-4])\nOMJulia.quit(mod) # hide","category":"page"}] +[{"location":"sendExpression/#sendExpression","page":"sendExpression","title":"sendExpression","text":"","category":"section"},{"location":"sendExpression/","page":"sendExpression","title":"sendExpression","text":"Start a new OMCSession and send scripting API expressions to the omc session with sendExpression().","category":"page"},{"location":"sendExpression/","page":"sendExpression","title":"sendExpression","text":"sendExpression","category":"page"},{"location":"sendExpression/#OMJulia.sendExpression","page":"sendExpression","title":"OMJulia.sendExpression","text":"sendExpression(omc, expr; parsed=true)\n\nSend API call to OpenModelica ZMQ server. See OpenModelica User's Guide Scripting API for a complete list of all functions.\n\nnote: Note\nSome characters in argument expr need to be escaped. E.g. \" becomes \\\". For example scripting API callloadFile(\"/path/to/M.mo\")will translate tosendExpression(omc, \"loadFile(\\\"/path/to/M.mo\\\")\")\n\nwarn: Warn\nOn Windows path separation symbol \\ needs to be escaped \\\\ or replaced to Unix style path / to prevent warnings.loadFile(\"C:\\\\path\\\\to\\\\M.mo\")translate tosendExpression(omc, \"loadFile(\\\"C:\\\\\\\\path\\\\\\\\to\\\\\\\\M.mo\\\")\") # Windows\nsendExpression(omc, \"loadFile(\\\"/c/path/to/M.mo\\\")\") # Windows\n\nExample\n\nusing OMJulia\nomc = OMJulia.OMCSession()\nOMJulia.sendExpression(omc, \"getVersion()\")\n\n\n\n\n\n","category":"function"},{"location":"sendExpression/#Examples","page":"sendExpression","title":"Examples","text":"","category":"section"},{"location":"sendExpression/","page":"sendExpression","title":"sendExpression","text":"using OMJulia # hide\nomc = OMJulia.OMCSession() # hide\nversion = OMJulia.sendExpression(omc, \"getVersion()\")\nOMJulia.quit(omc)","category":"page"},{"location":"api/#OMJulia.API","page":"OMJulia.API","title":"OMJulia.API","text":"","category":"section"},{"location":"api/","page":"OMJulia.API","title":"OMJulia.API","text":"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.","category":"page"},{"location":"api/","page":"OMJulia.API","title":"OMJulia.API","text":"warn: Warn\nNot all OMJulia.API functions are tested and some functions could have slightly different default values compared to the OpenModelica scripting API.","category":"page"},{"location":"api/","page":"OMJulia.API","title":"OMJulia.API","text":"Instead of escaping strings yourself the API interface handles this for you:","category":"page"},{"location":"api/","page":"OMJulia.API","title":"OMJulia.API","text":"sendExpression(omc, \"loadFile(\\\"$(bouncingBallFile)\\\")\")","category":"page"},{"location":"api/","page":"OMJulia.API","title":"OMJulia.API","text":"becomes","category":"page"},{"location":"api/","page":"OMJulia.API","title":"OMJulia.API","text":"API.loadFile(omc, bouncingBallFile)","category":"page"},{"location":"api/#Functions","page":"OMJulia.API","title":"Functions","text":"","category":"section"},{"location":"api/","page":"OMJulia.API","title":"OMJulia.API","text":"Modules = [OMJulia.API]\nOrder = [:function, :type]\nFilter = t -> t != OMJulia.API.modelicaString","category":"page"},{"location":"api/#OMJulia.API.buildModel-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.buildModel","text":"buildModel(omc, className;\n startTime = 0.0,\n stopTime = 1.0,\n numberOfIntervals = 500,\n tolerance = 1e-6,\n method = \"\",\n fileNamePrefix = className,\n options = \"\",\n outputFormat = \"mat\",\n variableFilter = \".*\",\n cflags = \"\",\n simflags = \"\")\n\nBuild Modelica model by generating C code and compiling it into an executable simulation. It does not run the simulation!\n\nSee OpenModelica scripting API buildModel.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.buildModelFMU-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.buildModelFMU","text":"buildModelFMU(omc, className;\n version = \"2.0\",\n fmuType = \"me\",\n fileNamePrefix=className,\n platforms=[\"static\"],\n includeResources = false)\n\nTranslates a modelica model into a Functional Mockup Unit. The only required argument is the className, while all others have some default values.\n\nSee OpenModelica scripting API buildModelFMU.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.cd","page":"OMJulia.API","title":"OMJulia.API.cd","text":"cd(omc, newWorkingDirectory=\"\")\n\nChange 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.\n\nSee OpenModelica scripting API cd.\n\n\n\n\n\n","category":"function"},{"location":"api/#OMJulia.API.closeSimulationResultFile-Tuple{OMJulia.OMCSession}","page":"OMJulia.API","title":"OMJulia.API.closeSimulationResultFile","text":" closeSimulationResultFile(omc)\n\nCloses 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.\n\nSee OpenModelica scripting API closeSimulationResultFile.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.diffSimulationResults-Tuple{OMJulia.OMCSession, String, String, String}","page":"OMJulia.API","title":"OMJulia.API.diffSimulationResults","text":"diffSimulationResults(omc, actualFile, expectedFile, diffPrefix;\n relTol = 1e-3,\n relTolDiffMinMax = 1e-4,\n rangeDelta = 0.002,\n vars = String[],\n keepEqualResults = false)\n\nCompares simulation results.\n\nSee OpenModelica scripting API diffSimulationResults.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.getAvailablePackageVersions-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.getAvailablePackageVersions","text":"getAvailablePackageVersions(omc, pkg; version=\"\")\n\nGet available package versions of pkg. Lists all available versions of the Buildings library on the OSMC server, starting from the most recent one, in descending order of priority. Note that pre-release versions have lower priority than all other versions.\n\nSee OpenModelica scripting API getAvailablePackageVersions or Package Management.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.getClassNames-Tuple{OMJulia.OMCSession}","page":"OMJulia.API","title":"OMJulia.API.getClassNames","text":"getClassNames(omc;\n class_ = \"\",\n recursive = false,\n qualified = false,\n sort = false,\n builtin = false,\n showProtected = false,\n includeConstants = false)\n\nReturns the list of class names defined in the class.\n\nSee OpenModelica scripting API getClassNames.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.getErrorString-Tuple{OMJulia.OMCSession}","page":"OMJulia.API","title":"OMJulia.API.getErrorString","text":"getErrorString(omc, warningsAsErrors = false)\n\nReturns the current error message.\n\nSee OpenModelica scripting API getErrorString.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.getInstallationDirectoryPath-Tuple{OMJulia.OMCSession}","page":"OMJulia.API","title":"OMJulia.API.getInstallationDirectoryPath","text":"getInstallationDirectoryPath(omc)\n\nThis returns OPENMODELICAHOME if it is set; on some platforms the default path is returned if it is not set.\n\nSee OpenModelica scripting API getInstallationDirectoryPath.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.getVersion-Tuple{OMJulia.OMCSession}","page":"OMJulia.API","title":"OMJulia.API.getVersion","text":"getVersion(omc)\n\nReturns the version of the Modelica compiler.\n\nSee OpenModelica scripting API getVersion.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.installPackage-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.installPackage","text":"installPackage(omc, pkg;\n version=\"\",\n exactMatch=false)\n\nInstall package pkg with given version. If version=\"\" try to install most recent version of package. If exactMatch is true install exact version, even if there are more recent backwards.compatible versions available.\n\nSee OpenModelica scripting API installPackage or Package Management.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.instantiateModel-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.instantiateModel","text":"instantiateModel(omc, className)\n\nInstantiates the class and returns the flat Modelica code.\n\nSee OpenModelica scripting API instantiateModel.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.linearize-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.linearize","text":"Creates a model with symbolic linearization matrices.\n\nSee OpenModelica scripting API linearize.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.loadFile-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.loadFile","text":"loadFile(omc, fileName;\n encoding = \"\",\n uses = true,\n notify = true,\n requireExactVersion = false)\n\nLoad file fileName (*.mo) and merge it with the loaded AST. See OpenModelica scripting API loadFile.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.loadModel-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.loadModel","text":"loadModel(omc, className;\n priorityVersion = String[],\n notify = false,\n languageStandard = \"\",\n requireExactVersion = false)\n\nLoads a Modelica library.\n\nSee OpenModelica scripting API loadModel.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.makeVectorString-Tuple{Vector{String}}","page":"OMJulia.API","title":"OMJulia.API.makeVectorString","text":"makeVectorString(vec)\n\nAdd quotes around each string element.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.readSimulationResult","page":"OMJulia.API","title":"OMJulia.API.readSimulationResult","text":"readSimulationResult(omc, filename,\n variables = String[],\n size = 0)\n\nReads a result file, returning a matrix corresponding to the variables and size given.\n\nSee OpenModelica scripting API readSimulationResult.\n\n\n\n\n\n","category":"function"},{"location":"api/#OMJulia.API.readSimulationResultSize-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.readSimulationResultSize","text":"readSimulationResultSize(omc, fileName)\n\nThe number of intervals that are present in the output file.\n\nSee OpenModelica scripting API readSimulationResultSize.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.readSimulationResultVars-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.readSimulationResultVars","text":"readSimulationResultVars(omc, fileName; readParameters = true, openmodelicaStyle = false)\n\nReturns the variables in the simulation file; you can use val() and plot() commands using these names.\n\nSee OpenModelica scripting API readSimulationResultVars.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.setCommandLineOptions-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.setCommandLineOptions","text":"setCommandLineOptions(omc, option)\n\nThe input is a regular command-line flag given to OMC, e.g. -d=failtrace or -g=MetaModelica.\n\nSee OpenModelica scripting API setCommandLineOptions.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.simulate-Tuple{OMJulia.OMCSession, String}","page":"OMJulia.API","title":"OMJulia.API.simulate","text":"simulate(omc, className;\n startTime = 0.0,\n stopTime = nothing,\n numberOfIntervals = 500,\n tolerance = 1e-6,\n method = \"\",\n fileNamePrefix=className,\n options = \"\",\n outputFormat = \"mat\",\n variableFilter = \".*\",\n cflags = \"\",\n simflags = \"\")\n\nSimulates a modelica model by generating C code, build it and run the simulation executable.\n\nSee OpenModelica scripting API simulate.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.updatePackageIndex-Tuple{OMJulia.OMCSession}","page":"OMJulia.API","title":"OMJulia.API.updatePackageIndex","text":"updatePackageIndex(omc)\n\nUpdate package index list.\n\nThe package manager contacts OSMC sersers and updated the internally sotred list of available packages.\n\nSee OpenModelica scripting API updatePackageIndex or Package Management.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.upgradeInstalledPackages-Tuple{OMJulia.OMCSession}","page":"OMJulia.API","title":"OMJulia.API.upgradeInstalledPackages","text":"upgradeInstalledPackages(omc; installNewestVersions=true)\n\nInstalls the latest available version of all installed packages.\n\nSee OpenModelica scripting API upgradeInstalledPackages or Package Management.\n\n\n\n\n\n","category":"method"},{"location":"api/#OMJulia.API.ScriptingError","page":"OMJulia.API","title":"OMJulia.API.ScriptingError","text":"ScriptingError <: Exception\n\nOpenModelica scripting error with message msg and additional error string from getErrroString.\n\n\n\n\n\n","category":"type"},{"location":"quickstart/#Quickstart","page":"Quickstart","title":"Quickstart","text":"","category":"section"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"There are three ways to interact with OpenModelica:","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"ModelicaSystem: A Julia style scripting API that handles low level API calls.\nOMJulia.API: A Julia style scripting API that handles low level sendExpression calls and has some degree of error handling.\nScripting API with sendExpression: Send expressions to the low level OpenModelica scripting API.","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"The following examples demonstrate how to simulate Modelica model BouncingBall in both ways.","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"model BouncingBall\n parameter Real e=0.7 \"coefficient of restitution\";\n parameter Real g=9.81 \"gravity acceleration\";\n Real h(fixed=true, start=1) \"height of ball\";\n Real v(fixed=true) \"velocity of ball\";\n Boolean flying(fixed=true, start=true) \"true, if ball is flying\";\n Boolean impact;\n Real v_new(fixed=true);\n Integer foo;\nequation\n impact = h <= 0.0;\n foo = if impact then 1 else 2;\n der(v) = if flying then -g else 0;\n der(h) = v;\n\n when {h <= 0.0 and v <= 0.0,impact} then\n v_new = if edge(impact) then -e*pre(v) else 0;\n flying = v_new > 0;\n reinit(v, v_new);\n end when;\nend BouncingBall;","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"info: Info\nThe BouncingBall.mo file can be found in your OpenModelica installation directory in /share/doc/omc/testmodels/BouncingBall.mo.","category":"page"},{"location":"quickstart/#modelicasystem","page":"Quickstart","title":"ModelicaSystem","text":"","category":"section"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"Start a new OMJulia.OMCSession and create a new ModelicaSystem to build and simulate the BouncingBall model. Afterwards the result can be plotted in Julia.","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"using OMJulia\nusing CSV, DataFrames, PlotlyJS\nusing PlotlyDocumenter # hide\n\nmod = OMJulia.OMCSession();\n\ninstallDir = sendExpression(mod, \"getInstallationDirectoryPath()\")\nbouncingBallFile = joinpath(installDir, \"share\", \"doc\", \"omc\", \"testmodels\", \"BouncingBall.mo\")\n\nModelicaSystem(mod,\n bouncingBallFile,\n \"BouncingBall\")\nsimulate(mod,\n resultfile = \"BouncingBall_ref.csv\",\n simflags = \"-override=outputFormat=csv,stopTime=3\")\n\nresultfile = joinpath(getWorkDirectory(mod), \"BouncingBall_ref.csv\")\ndf = DataFrame(CSV.File(resultfile));\n\nplt = plot(df,\n x=:time, y=:h,\n mode=\"lines\",\n Layout(title=\"Bouncing Ball\", height = 700))\n\nOMJulia.quit(mod)","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"PlotlyDocumenter.to_documenter(plt) # hide","category":"page"},{"location":"quickstart/#omjulia-api","page":"Quickstart","title":"OMJulia.API","text":"","category":"section"},{"location":"quickstart/#Example","page":"Quickstart","title":"Example","text":"","category":"section"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"Start a new OMJulia.OMCSession and call scripting API directly using the OMJulia.API module.","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"using OMJulia\nusing OMJulia.API: API\n\nusing CSV, DataFrames, PlotlyJS\nusing PlotlyDocumenter # hide\n\nomc = OMJulia.OMCSession();\nomcWorkDir = mkpath(joinpath(\"docs\", \"omc-temp\")) # hide\nmkpath(omcWorkDir) # hide\nAPI.cd(omcWorkDir) # hide\ninstallDir = API.getInstallationDirectoryPath(omc)\nbouncingBallFile = joinpath(installDir, \"share\", \"doc\", \"omc\", \"testmodels\", \"BouncingBall.mo\")\nbouncingBallFile = abspath(bouncingBallFile) # hide\nAPI.loadFile(omc, bouncingBallFile)\nres = API.simulate(omc, \"BouncingBall\"; stopTime=3.0, outputFormat = \"csv\")\nresultfile = res[\"resultFile\"]\ndf = DataFrame(CSV.File(resultfile));\n\nplt = plot(df,\n x=:time, y=:h,\n mode=\"lines\",\n Layout(title=\"Bouncing Ball\", height = 700))\n\nOMJulia.quit(omc)","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"PlotlyDocumenter.to_documenter(plt) # hide","category":"page"},{"location":"quickstart/#scripting-api-with-sendExpression","page":"Quickstart","title":"Scripting API with sendExpression","text":"","category":"section"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"Start a new OMJulia.OMCSession and send scripting API expressions to the omc session with sendExpression().","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"warn: Warn\nAll special characters inside a string argument for an API function need to be escaped when passing to sendExpression.E.g. MOS commandloadFile(\"/some/path/to/BouncingBall.mo\");becomes Julia codesendExpression(omc, \"loadFile(\\\"/some/path/to/BouncingBall.mo\\\")\")","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"info: Info\nOn Windows path separation symbol \\ needs to be escaped \\\\ or replaced to Unix style path / to prevent warnings.","category":"page"},{"location":"quickstart/","page":"Quickstart","title":"Quickstart","text":"using OMJulia\n\nomc = OMJulia.OMCSession();\nomcWorkDir = mkpath(joinpath(\"docs\", \"omc-temp\")) # hide\nmkpath(omcWorkDir) # hide\nsendExpression(omc, \"cd(\\\"$(omcWorkDir)\\\")\") # hide\ninstallDir = sendExpression(omc, \"getInstallationDirectoryPath()\")\nbouncingBallFile = joinpath(installDir, \"share\", \"doc\", \"omc\", \"testmodels\", \"BouncingBall.mo\")\nbouncingBallFile = abspath(bouncingBallFile) # hide\nif Sys.iswindows()\n bouncingBallFile = replace(bouncingBallFile, \"\\\\\" => \"/\")\nend\nsendExpression(omc, \"loadFile(\\\"$(bouncingBallFile)\\\")\")\nsendExpression(omc, \"simulate(BouncingBall)\")\nOMJulia.quit(omc)","category":"page"},{"location":"#OMJulia.jl","page":"Home","title":"OMJulia.jl","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Julia scripting OpenModelica interface.","category":"page"},{"location":"#Overview","page":"Home","title":"Overview","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"OMJulia - the OpenModelica Julia API is a free, open source, highly portable Julia based interactive session handler for Julia scripting of OpenModelica API functionality. It provides the modeler with components for creating a complete Julia-Modelica modeling, compilation and simulation environment based on the latest OpenModelica implementation and Modelica library standard available.","category":"page"},{"location":"","page":"Home","title":"Home","text":"OMJulia is structured to combine both the solving strategy and model building. Thus, domain experts (people writing the models) and computational engineers (people writing the solver code) can work on one unified tool that is industrially viable for optimization of Modelica models, while offering a flexible platform for algorithm development and research. OMJulia is not a standalone package, it depends upon the OpenModelica installation.","category":"page"},{"location":"","page":"Home","title":"Home","text":"OMJulia is implemented in Julia and depends on ZeroMQ - high performance asynchronous messaging library and it supports the Modelica Standard Library version 4.0 that is included with OpenModelica.","category":"page"},{"location":"#Installation","page":"Home","title":"Installation","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Make sure OpenModelica is installed.","category":"page"},{"location":"","page":"Home","title":"Home","text":"Install OMJulia.jl with:","category":"page"},{"location":"","page":"Home","title":"Home","text":"julia> import Pkg; Pkg.add(\"OMJulia\")","category":"page"},{"location":"#Features-of-OMJulia","page":"Home","title":"Features of OMJulia","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"The OMJulia package contains the following features:","category":"page"},{"location":"","page":"Home","title":"Home","text":"Interactive session handling, parsing, interpretation of commands and Modelica expressions for evaluation, simulation, plotting, etc.\nConnect with the OpenModelica compiler through zmq sockets\nAble to interact with the OpenModelica compiler through the available API\nEasy access to the Modelica Standard library.\nAll the API calls are communicated with the help of the sendExpression method implemented in a Julia module\nThe results are returned as strings","category":"page"},{"location":"modelicaSystem/#Advanced-API","page":"ModelicaSystem","title":"Advanced API","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"A Julia style scripting API that handles low level API calls.","category":"page"},{"location":"modelicaSystem/#ModelicaSystem","page":"ModelicaSystem","title":"ModelicaSystem","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"ModelicaSystem","category":"page"},{"location":"modelicaSystem/#OMJulia.ModelicaSystem","page":"ModelicaSystem","title":"OMJulia.ModelicaSystem","text":"ModelicaSystem(omc, fileName, modelName, library=nothing;\n commandLineOptions=nothing, variableFilter=nothing, customBuildDirectory=nothing)\n\nSet command line options for OMCSession and build model modelName to prepare for a simulation.\n\nArguments\n\nomc: OpenModelica compiler session, see OMCSession().\nfileName: Path to Modelica file.\nmodelName: Name of Modelica model to build, including namespace if the model is wrappen within a Modelica package.\nlibrary: List of dependent libraries or Modelica files. This argument can be passed as string (e.g. \"Modelica\") or tuple (e.g. (\"Modelica\", \"4.0\") or array (e.g. [\"Modelica\", \"SystemDynamics\"] or [(\"Modelica\", \"4.0\"), \"SystemDynamics\"]).\n\nKeyword Arguments\n\ncommandLineOptions: OpenModelica command line options, see OpenModelica Compiler Flags.\nvariableFilter: Regex to filter variables in result file.\n\nUsage\n\nusing OMJulia\nmod = OMJulia.OMCSession()\nModelicaSystem(mod, \"BouncingBall.mo\", \"BouncingBall\", [\"Modelica\", \"SystemDynamics\"], commandLineOptions=\"-d=newInst\")\n\nProviding dependent libaries:\n\nusing OMJulia\nmod = OMJulia.OMCSession()\nModelicaSystem(mod, \"BouncingBall.mo\", \"BouncingBall\", [\"Modelica\", \"SystemDynamics\", \"dcmotor.mo\"])\n\nSee also OMCSession().\n\n\n\n\n\nModelicaSystem(omc; modelName, library=nothing,\n commandLineOptions=nothing, variableFilter=nothing, customBuildDirectory=nothing)\n\nSet command line options for OMCSession and build model modelname to prepare for a simulation.\n\nArguments\n\nomc: OpenModelica compiler session, see OMCSession().\n\nKeyword Arguments\n\nmodelName: Name of Modelica model to build, including namespace if the model is wrappen within a Modelica package.\nlibrary: List of dependent libraries or Modelica files. This argument can be passed as string (e.g. \"Modelica\") or tuple (e.g. (\"Modelica\", \"4.0\") or array (e.g. [\"Modelica\", \"SystemDynamics\"] or [(\"Modelica\", \"4.0\"), \"SystemDynamics\"]).\ncommandLineOptions: OpenModelica command line options, see OpenModelica Compiler Flags.\nvariableFilter: Regex to filter variables in result file.\n\nUsage\n\nusing OMJulia\nmod = OMJulia.OMCSession()\nModelicaSystem(mod, modelName=\"Modelica.Electrical.Analog.Examples.CauerLowPassAnalog\", library=\"Modelica\")\n\nSee also OMCSession().\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"OMJulia.OMCSession\nOMJulia.quit","category":"page"},{"location":"modelicaSystem/#OMJulia.OMCSession","page":"ModelicaSystem","title":"OMJulia.OMCSession","text":"OMCSession <: Any\n\nOMC session struct.\n\n\n\nOMCSession(omc=nothing)\n\nCreate new OpenModelica session.\n\nArguments\n\nomc::Union{String, Nothing}: Path to OpenModelica compiler. Use omc from PATH if nothing is provided.\n\nSee also ModelicaSystem, OMJulia.quit.\n\n\n\n\n\n","category":"type"},{"location":"modelicaSystem/#OMJulia.quit","page":"ModelicaSystem","title":"OMJulia.quit","text":"quit(omc::OMCSession; timeout=4::Integer)\n\nQuit OMCSession.\n\nArguments\n\n- `omc::OMCSession`: OMC session.\n\nKeywords\n\n- `timeout=4::Integer`: Timeout in seconds.\n\nSee also OMJulia.OMCSession.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#Example","page":"ModelicaSystem","title":"Example","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"Let us see the usage of ModelicaSystem with the help of Modelica model ModSeborgCSTRorg","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"model ModSeborgCSTRorg\n // Model of original Seborg CSTR in ode form\n // author: Bernt Lie, University of Southeast Norway,November 7, 2017\n\n // Parameters\n parameter Real V = 100 \"Reactor volume, L\";\n parameter Real rho = 1e3 \"Liquid density, g/L\";\n parameter Real a = 1 \"Stoichiometric constant, -\";\n parameter Real EdR = 8750 \"Activation temperature, K\";\n parameter Real k0 = exp(EdR/350) \"Pre-exponential factor, 1/min\";\n parameter Real cph = 0.239 \"Specific heat capacity of mixture, J.g-1.K-1\";\n parameter Real DrHt = -5e4 \"Molar enthalpy of reaction, J/mol\";\n parameter Real UA = 5e4 \"Heat transfer parameter, J/(min.K)\";\n\n // Initial state parameters\n parameter Real cA0 = 0.5 \"Initial concentration of A, mol/L\";\n parameter Real T0 = 350 \"Initial temperature, K\";\n // Declaring variables\n // -- states\n Real cA(start = cA0, fixed = true) \"Initializing concentration of A in reactor, mol/L\";\n Real T(start = T0, fixed = true) \"Initializing temperature in reactor, K\";\n // -- auxiliary variables\n Real r \"Rate of reaction, mol/(L.s)\";\n Real k \"Reaction 'constant', ...\";\n Real Qd \"Heat flow rate, J/min\";\n // -- input variables\n input Real Vdi \"Volumetric flow rate through reactor, L/min\";\n input Real cAi \"Influent molar concentration of A, mol/L\";\n input Real Ti \"Influent temperature, K\";\n input Real Tc \"Cooling temperature', K\";\n // -- output variables\n output Real y_T \"Reactor temperature, K\";\n // Equations constituting the model\nequation\n // Differential equations\n der(cA) = Vdi*(cAi-cA)/V- a*r;\n der(T) = Vdi*(Ti-T)/V + (-DrHt)*r/(rho*cph) + Qd/(rho*V*cph);\n // Algebraic equations\n r = k*cA^a;\n k = k0*exp(-EdR/T);\n Qd = UA*(Tc-T);\n // Outputs\n y_T = T;\nend ModSeborgCSTRorg","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"using OMJulia\nmod = OMJulia.OMCSession()\nomcWorkDir = mkpath(joinpath(\"docs\", \"omc-temp\")) # hide\nmkpath(omcWorkDir) # hide\nsendExpression(mod, \"cd(\\\"$(omcWorkDir)\\\")\") # hide\nModelicaSystem(mod,\n joinpath(\"docs\", \"testmodels\", \"ModSeborgCSTRorg.mo\"),\n \"ModSeborgCSTRorg\")","category":"page"},{"location":"modelicaSystem/#WorkDirectory","page":"ModelicaSystem","title":"WorkDirectory","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"For each OMJulia.OMCSession session a temporary work directory is created and the results are published in that working directory. In order to get the work directory use getWorkDirectory.","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getWorkDirectory","category":"page"},{"location":"modelicaSystem/#OMJulia.getWorkDirectory","page":"ModelicaSystem","title":"OMJulia.getWorkDirectory","text":"getWorkDirectory(omc)\n\nReturn working directory of OMJulia.OMCsession omc.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getWorkDirectory(mod)","category":"page"},{"location":"modelicaSystem/#Build-Model","page":"ModelicaSystem","title":"Build Model","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"buildModel","category":"page"},{"location":"modelicaSystem/#OMJulia.buildModel","page":"ModelicaSystem","title":"OMJulia.buildModel","text":"buildModel(omc; variableFilter=nothing)\n\nBuild modelica model.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\n\nKeyword Arguments\n\nvariableFilter: Regex to filter variables in result file.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"In case the Modelica model needs to be updated or additional simulation flags needs to be set using sendExpression The buildModel API can be used after ModelicaSystem.","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"buildModel(omc)\nbuildModel(omc, variableFilter=\"a|T\")","category":"page"},{"location":"modelicaSystem/#Get-Methods","page":"ModelicaSystem","title":"Get Methods","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getQuantities\nshowQuantities\ngetContinuous\ngetInputs\ngetOutputs\ngetParameters\ngetSimulationOptions\ngetSolutions","category":"page"},{"location":"modelicaSystem/#OMJulia.getQuantities","page":"ModelicaSystem","title":"OMJulia.getQuantities","text":"getQuantities(omc, name=nothing)\n\nReturn list of all variables parsed from xml file.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of variables to read from xml file. If nothing is provided read all variables.\n\nSee also showQuantities.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.showQuantities","page":"ModelicaSystem","title":"OMJulia.showQuantities","text":"showQuantities(omc, name=nothing)\n\nReturn DataFrame of all variables parsed from xml file.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of variables to read from xml file. If nothing is provided read all variables.\n\nSee also getQuantities.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.getContinuous","page":"ModelicaSystem","title":"OMJulia.getContinuous","text":"getContinuous(omc, name=nothing)\n\nReturn continuous variables parsed from xml file.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of continuous variables to read from xml file. If nothing is provided read all continuous variables.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.getInputs","page":"ModelicaSystem","title":"OMJulia.getInputs","text":"getInputs(omc, name=nothing)\n\nReturn input variables parsed from xml file. If input variables have no start value the returned value is \"None\".\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of input variables to read from xml file. If nothing is provided read all input variables.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.getOutputs","page":"ModelicaSystem","title":"OMJulia.getOutputs","text":"getInputs(omc, name=nothing)\n\nReturn output variables parsed from xml file. If output variables have no start value the returned value is \"None\".\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of output variables to read from xml file. If nothing is provided read all output variables.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.getParameters","page":"ModelicaSystem","title":"OMJulia.getParameters","text":"getParameters(omc, name=nothing)\n\nReturn parameter variables parsed from xml file.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of parameters to read from xml file. If nothing is provided read all parameters.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.getSimulationOptions","page":"ModelicaSystem","title":"OMJulia.getSimulationOptions","text":"getSimulationOptions(omc, name=nothing)\n\nReturn SimulationOption variables parsed from xml file.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of parameters to read from xml file. If nothing is provided read all parameters.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.getSolutions","page":"ModelicaSystem","title":"OMJulia.getSolutions","text":"getSolutions(omc::OMCSession, name=nothing; resultfile=nothing)\n\nRead result file and return simulation results\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of variables to read from result file. If nothing is provided read all variables.\n\nKeyword Arguments\n\nresultfile::Union{AbstractString, Nothing}: Path to result file. If nothing is provided use saved result file.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#Examples","page":"ModelicaSystem","title":"Examples","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getQuantities(mod)\ngetQuantities(mod, \"T\")\ngetQuantities(mod, [\"T\",\"cA\"])\nshowQuantities(mod)","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getContinuous(mod)\ngetContinuous(mod, [\"Qd\",\"Tc\"])","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getInputs(mod)\ngetOutputs(mod)","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getParameters(mod)\ngetParameters(mod, [\"a\",\"V\"])","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getSimulationOptions(mod)\ngetSimulationOptions(mod, [\"stepSize\",\"tolerance\"])","category":"page"},{"location":"modelicaSystem/#Reading-Simulation-Results","page":"ModelicaSystem","title":"Reading Simulation Results","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"To read the simulation results, we need to simulate the model first and use the getSolution() API to read the results","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"simulate(mod)","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"The getSolution method can be used in two different ways.","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"using default result filename\nuse the result filenames provided by user","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"This provides a way to compare simulation results and perform regression testing","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getSolutions(mod)\ngetSolutions(mod, [\"time\",\"a\"])","category":"page"},{"location":"modelicaSystem/#Examples-of-using-resultFile-provided-by-user-location","page":"ModelicaSystem","title":"Examples of using resultFile provided by user location","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getSolutions(mod, resultfile=\"C:/BouncingBal/tmpbouncingBall.mat\") //returns list of simulation variables for which results are available , the resulfile location is provided by user\ngetSolutions(mod, [\"time\",\"h\"], resultfile=\"C:/BouncingBal/tmpbouncingBall.mat\") // return list of array","category":"page"},{"location":"modelicaSystem/#Set-Methods","page":"ModelicaSystem","title":"Set Methods","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"setInputs\nsetParameters\nsetSimulationOptions","category":"page"},{"location":"modelicaSystem/#OMJulia.setInputs","page":"ModelicaSystem","title":"OMJulia.setInputs","text":"setInputs(omc, name)\n\nSet new values for input variables.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}}: String \"Name=value\" or vector of strings [\"Name1=value1\",\"Name2=value2\",\"Name3=value3\"])\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.setParameters","page":"ModelicaSystem","title":"OMJulia.setParameters","text":"setParameters(omc, name; verbose=true)\n\nSet parameter values for parameter variables defined by users\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}}: String \"Name=value\" or vector of strings [\"Name1=value1\",\"Name2=value2\",\"Name3=value3\"])\n\nKeyword Arguments\n\nverbose::Bool: Display additional info if setParameters failed.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.setSimulationOptions","page":"ModelicaSystem","title":"OMJulia.setSimulationOptions","text":"setSimulationOptions(omc, name)\n\nSet simulation option values like stopTime or stepSize.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}}: String \"Name=value\" or vector of strings [\"Name1=value1\",\"Name2=value2\",\"Name3=value3\"])\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#Examples-2","page":"ModelicaSystem","title":"Examples","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"setInputs(mod, \"cAi=100\")\nsetInputs(mod, [\"cAi=100\",\"Ti=200\",\"Vdi=300\",\"Tc=250\"])","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"setParameters(mod, \"a=3\")\nsetParameters(mod, [\"a=4\",\"V=200\"])","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"setSimulationOptions(mod, [\"stopTime=2.0\", \"tolerance=1e-08\"])","category":"page"},{"location":"modelicaSystem/#Advanced-Simulation","page":"ModelicaSystem","title":"Advanced Simulation","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"simulate","category":"page"},{"location":"modelicaSystem/#OMJulia.simulate","page":"ModelicaSystem","title":"OMJulia.simulate","text":"simulate(omc; resultfile=nothing, simflags=\"\", verbose=false)\n\nSimulate modelica model.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session, see OMCSession().\n\nKeyword Arguments\n\nresultFile::Union{String, Nothing}: Result file to write simulation results into.\nsimflags::String: Simulation flags, see Simulation Runtime Flags.\nverbose::Bool: [debug] Log cmd call to log.txt and error.txt.\n\nExamples\n\nsimulate(omc)\n\nSpecify result file:\n\nsimulate(omc, resultfile=\"tmpresult.mat\")\n\nSet simulation runtime flags:\n\nsimulate(omc, simflags=\"-noEmitEvent -override=e=0.3,g=9.3\")\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"An example of how to do advanced simulation to set parameter values using set methods and finally simulate the \"ModSeborgCSTRorg.mo\" model is given below .","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getParameters(mod)\nsetParameters(mod, \"a=3.0\")","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"To check whether new values are updated to model , we can again query the getParameters().","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getParameters(mod)","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"Similary we can also use setInputs() to set a value for the inputs during various time interval can also be done using the following.","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"setInputs(mod, \"cAi=100\")","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"And finally we simulate the model","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"simulate(mod)","category":"page"},{"location":"modelicaSystem/#Linearization","page":"ModelicaSystem","title":"Linearization","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"linearize\ngetLinearizationOptions\nsetLinearizationOptions\ngetLinearInputs\ngetLinearOutputs\ngetLinearStates","category":"page"},{"location":"modelicaSystem/#OMJulia.linearize","page":"ModelicaSystem","title":"OMJulia.linearize","text":"function which returns the linearize model of modelica model, The function returns four matrices A, B, C, D\n\nlinearize(omc; lintime = nothing, simflags= nothing, verbose=true)\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\n\nKeyword Arguments\n\nlintime : Value specifies a time where the linearization of the model should be performed\nsimflags: Simulation flags, see Simulation Runtime Flags.\n\nExamples of using linearize() API\n\nlinearize(omc)\n\nSpecify result file:\n\nlinearize(omc, lintime=\"0.5\")\n\nSet simulation runtime flags:\n\nlinearize(omc, simflags=\"-noEmitEvent\")\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.getLinearizationOptions","page":"ModelicaSystem","title":"OMJulia.getLinearizationOptions","text":"getLinearizationOptions(omc, name=nothing)\n\nReturn linearization options.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}, Nothing}: Names of linearization options. If nothing is provided return all linearization options.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.setLinearizationOptions","page":"ModelicaSystem","title":"OMJulia.setLinearizationOptions","text":"setLinearizationOptions(omc, name)\n\nSet linearization options.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nname::Union{<:AbstractString, Array{<:AbstractString,1}}: String \"Name=value\" or vector of strings [\"Name1=value1\",\"Name2=value2\",\"Name3=value3\"])\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.getLinearInputs","page":"ModelicaSystem","title":"OMJulia.getLinearInputs","text":"getLinearInputs(omc)\n\nReturn linear input variables after the model is linearized\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.getLinearOutputs","page":"ModelicaSystem","title":"OMJulia.getLinearOutputs","text":"getLinearOutputs(omc)\n\nReturn linear output variables after the model is linearized\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#OMJulia.getLinearStates","page":"ModelicaSystem","title":"OMJulia.getLinearStates","text":"getLinearStates(omc)\n\nReturn linear state variables after the model is linearized\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#Examples-3","page":"ModelicaSystem","title":"Examples","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getLinearizationOptions(mod)\ngetLinearizationOptions(mod, [\"startTime\",\"stopTime\"])","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"setLinearizationOptions(mod,[\"stopTime=2.0\",\"tolerance=1e-06\"])","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"res = linearize(mod)","category":"page"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"getLinearInputs(mod)\ngetLinearOutputs(mod)\ngetLinearStates(mod)","category":"page"},{"location":"modelicaSystem/#Sensitivity-Analysis","page":"ModelicaSystem","title":"Sensitivity Analysis","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"sensitivity","category":"page"},{"location":"modelicaSystem/#OMJulia.sensitivity","page":"ModelicaSystem","title":"OMJulia.sensitivity","text":"sensitivity(omc::OMCSession, Vp, Vv, Ve=[1e-2])\n\nMethod for computing numeric sensitivity of OpenModelica object.\n\nArguments\n\nomc::OMCSession: OpenModelica compiler session.\nVp::Array{<:AbstractString, 1}: Modelica Parameter names.\nVv::Array{<:AbstractString, 1}: Modelica Variable names.\nVe::Array{Float64, 1}: Excitations of parameters; defaults to scalar 1e-2\n\nReturn\n\nVSname::Vector{Vector{String}}: Vector of sensitivity names\nVSarray::Vector{Vector{Vector{Float64}}}: Vector of sensitivies: vector of elements per parameter\n\nEach element containing time series per variable\n\n\n\n\n\n","category":"function"},{"location":"modelicaSystem/#Examples-4","page":"ModelicaSystem","title":"Examples","text":"","category":"section"},{"location":"modelicaSystem/","page":"ModelicaSystem","title":"ModelicaSystem","text":"(Sn, Sa) = sensitivity(mod, [\"UA\",\"EdR\"], [\"T\",\"cA\"], [1e-2,1e-4])\nOMJulia.quit(mod) # hide","category":"page"}] } diff --git a/dev/sendExpression/index.html b/dev/sendExpression/index.html index 5ed25d5..b4b1901 100644 --- a/dev/sendExpression/index.html +++ b/dev/sendExpression/index.html @@ -2,4 +2,4 @@ sendExpression · OMJulia.jl

      sendExpression

      Start a new OMCSession and send scripting API expressions to the omc session with sendExpression().

      OMJulia.sendExpressionFunction
      sendExpression(omc, expr; parsed=true)

      Send API call to OpenModelica ZMQ server. See OpenModelica User's Guide Scripting API for a complete list of all functions.

      Note

      Some characters in argument expr need to be escaped. E.g. " becomes \". For example scripting API call

      loadFile("/path/to/M.mo")

      will translate to

      sendExpression(omc, "loadFile(\"/path/to/M.mo\")")
      Warn

      On Windows path separation symbol \ needs to be escaped \\ or replaced to Unix style path / to prevent warnings.

      loadFile("C:\\path\\to\\M.mo")

      translate to

      sendExpression(omc, "loadFile(\"C:\\\\path\\\\to\\\\M.mo\")")  # Windows
       sendExpression(omc, "loadFile(\"/c/path/to/M.mo\")")           # Windows

      Example

      using OMJulia
       omc = OMJulia.OMCSession()
      -OMJulia.sendExpression(omc, "getVersion()")
      source

      Examples

      [ Info: Path to zmq file="/tmp/openmodelica.runner.port.julia.ZKFUGawJfP"
      julia> version = OMJulia.sendExpression(omc, "getVersion()")"OpenModelica 1.24.0~dev-98-g8cc47a0"
      julia> OMJulia.quit(omc)
      +OMJulia.sendExpression(omc, "getVersion()")source

      Examples

      [ Info: Path to zmq file="/tmp/openmodelica.runner.port.julia.FWaK8SgXBX"
      julia> version = OMJulia.sendExpression(omc, "getVersion()")"OpenModelica 1.24.0~dev-98-g8cc47a0"
      julia> OMJulia.quit(omc)