diff --git a/dev/index.html b/dev/index.html
index 3785b1b..1ce2a08 100644
--- a/dev/index.html
+++ b/dev/index.html
@@ -1,2 +1,2 @@
-
Home · OMJulia.jl Julia scripting OpenModelica interface.
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.
Make sure OpenModelica is installed.
Install OMJulia.jl with:
julia> import Pkg; Pkg.add("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
Theme
documenter-light documenter-dark
This document was generated with Documenter.jl version 0.27.25 on Tuesday 12 September 2023 . Using Julia version 1.9.3.
+Home · OMJulia.jl Julia scripting OpenModelica interface.
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.
Make sure OpenModelica is installed.
Install OMJulia.jl with:
julia> import Pkg; Pkg.add("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
Theme
documenter-light documenter-dark
This document was generated with Documenter.jl version 0.27.25 on Thursday 5 October 2023 . Using Julia version 1.9.3.
diff --git a/dev/modelicaSystem/index.html b/dev/modelicaSystem/index.html
index a19a5a2..144ce43 100644
--- a/dev/modelicaSystem/index.html
+++ b/dev/modelicaSystem/index.html
@@ -4,7 +4,7 @@
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 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 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 Let us see the usage of ModelicaSystem
with the help of Modelica model ModSeborgCSTRorg
model ModSeborgCSTRorg
+ModelicaSystem(mod, "BouncingBall.mo", "BouncingBall", ["Modelica", "SystemDynamics", "dcmotor.mo"])
See also OMCSession()
.
source 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 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 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
@@ -47,192 +47,54 @@
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.J7uyg7Srin"
-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} @0x0000000002f26b30, WeakRef[WeakRef(ZMQ.Socket(Ptr{Nothing} @0x0000000002dce6d0, FileWatching._FDWatcher(Ptr{Nothing} @0x00000000020e5cb0, 30, (1, 0), Base.GenericCondition{Base.Threads.SpinLock}(Base.IntrusiveLinkedList{Task}(nothing, nothing), Base.Threads.SpinLock(0)), 0, (false, false))))]), ZMQ.Socket(Ptr{Nothing} @0x0000000002dce6d0, FileWatching._FDWatcher(Ptr{Nothing} @0x00000000020e5cb0, 30, (1, 0), Base.GenericCondition{Base.Threads.SpinLock}(Base.IntrusiveLinkedList{Task}(nothing, nothing), Base.Threads.SpinLock(0)), 0, (false, false))), Process(`omc --interactive=zmq -z=julia.J7uyg7Srin`, 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.fZRG4JxRwS"
+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} @0x00000000028c53e0, WeakRef[WeakRef(ZMQ.Socket(Ptr{Nothing} @0x00000000029d9100, FileWatching._FDWatcher(Ptr{Nothing} @0x000000000250fe90, 30, (1, 0), Base.GenericCondition{Base.Threads.SpinLock}(Base.IntrusiveLinkedList{Task}(nothing, nothing), Base.Threads.SpinLock(0)), 0, (false, false))))]), ZMQ.Socket(Ptr{Nothing} @0x00000000029d9100, FileWatching._FDWatcher(Ptr{Nothing} @0x000000000250fe90, 30, (1, 0), Base.GenericCondition{Base.Threads.SpinLock}(Base.IntrusiveLinkedList{Task}(nothing, nothing), Base.Threads.SpinLock(0)), 0, (false, false))), Process(`omc --interactive=zmq -z=julia.fZRG4JxRwS`, 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")
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
.
getWorkDirectory(omc)
Return working directory of OMJulia.OMCsession omc
.
source julia> getWorkDirectory(mod)
"/tmp/jl_xbVkbX"
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")
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 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 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 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 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 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 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 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 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"…)
- Dict{Any, Any}("name" => "der(cA)", "max" => "None", "start" => "None", "min" => "None", "aliasvariable" => nothing, "variability" => "continuous", "changeable" => "false", "causality" => "local", "description" => "der(Initializing concentration of A in reactor, mol/L)", "alias" => "noAlias"…)
- Dict{Any, Any}("name" => "\$cse1", "max" => "None", "start" => "None", "min" => "None", "aliasvariable" => nothing, "variability" => "continuous", "changeable" => "false", "causality" => "local", "description" => nothing, "alias" => "noAlias"…)
- Dict{Any, Any}("name" => "Qd", "max" => "None", "start" => "None", "min" => "None", "aliasvariable" => nothing, "variability" => "continuous", "changeable" => "false", "causality" => "local", "description" => "Heat flow rate, J/min", "alias" => "noAlias"…)
- Dict{Any, Any}("name" => "Tc", "max" => "None", "start" => "None", "min" => "None", "aliasvariable" => nothing, "variability" => "continuous", "changeable" => "true", "causality" => "input", "description" => "Cooling temperature', K", "alias" => "noAlias"…)
- Dict{Any, Any}("name" => "Ti", "max" => "None", "start" => "None", "min" => "None", "aliasvariable" => nothing, "variability" => "continuous", "changeable" => "true", "causality" => "input", "description" => "Influent temperature, K", "alias" => "noAlias"…)
- Dict{Any, Any}("name" => "Vdi", "max" => "None", "start" => "None", "min" => "None", "aliasvariable" => nothing, "variability" => "continuous", "changeable" => "true", "causality" => "input", "description" => "Volumetric flow rate through reactor, L/min", "alias" => "noAlias"…)
- Dict{Any, Any}("name" => "cAi", "max" => "None", "start" => "None", "min" => "None", "aliasvariable" => nothing, "variability" => "continuous", "changeable" => "true", "causality" => "input", "description" => "Influent molar concentration of A, mol/L", "alias" => "noAlias"…)
- ⋮
- Dict{Any, Any}("name" => "EdR", "max" => "None", "start" => "8750.0", "min" => "None", "aliasvariable" => nothing, "variability" => "parameter", "changeable" => "true", "causality" => "parameter", "description" => "Activation temperature, K", "alias" => "noAlias"…)
- Dict{Any, Any}("name" => "T0", "max" => "None", "start" => "350.0", "min" => "None", "aliasvariable" => nothing, "variability" => "parameter", "changeable" => "true", "causality" => "parameter", "description" => "Initial temperature, K", "alias" => "noAlias"…)
- Dict{Any, Any}("name" => "UA", "max" => "None", "start" => "50000.0", "min" => "None", "aliasvariable" => nothing, "variability" => "parameter", "changeable" => "true", "causality" => "parameter", "description" => "Heat transfer parameter, J/(min.K)", "alias" => "noAlias"…)
- Dict{Any, Any}("name" => "V", "max" => "None", "start" => "100.0", "min" => "None", "aliasvariable" => nothing, "variability" => "parameter", "changeable" => "true", "causality" => "parameter", "description" => "Reactor volume, L", "alias" => "noAlias"…)
- Dict{Any, Any}("name" => "a", "max" => "None", "start" => "1.0", "min" => "None", "aliasvariable" => nothing, "variability" => "parameter", "changeable" => "true", "causality" => "parameter", "description" => "Stoichiometric constant, -", "alias" => "noAlias"…)
- Dict{Any, Any}("name" => "cA0", "max" => "None", "start" => "0.5", "min" => "None", "aliasvariable" => nothing, "variability" => "parameter", "changeable" => "true", "causality" => "parameter", "description" => "Initial concentration of A, mol/L", "alias" => "noAlias"…)
- Dict{Any, Any}("name" => "cph", "max" => "None", "start" => "0.239", "min" => "None", "aliasvariable" => nothing, "variability" => "parameter", "changeable" => "true", "causality" => "parameter", "description" => "Specific heat capacity of mixture, J.g-1.K-1", "alias" => "noAlias"…)
- Dict{Any, Any}("name" => "k0", "max" => "None", "start" => "None", "min" => "None", "aliasvariable" => nothing, "variability" => "parameter", "changeable" => "false", "causality" => "calculatedParameter", "description" => "Pre-exponential factor, 1/min", "alias" => "noAlias"…)
- Dict{Any, Any}("name" => "rho", "max" => "None", "start" => "1000.0", "min" => "None", "aliasvariable" => nothing, "variability" => "parameter", "changeable" => "true", "causality" => "parameter", "description" => "Liquid density, g/L", "alias" => "noAlias"…)
julia> getQuantities(mod, "T")
1-element Vector{Dict{Any, Any}}:
- Dict("name" => "T", "max" => "None", "start" => "None", "min" => "None", "aliasvariable" => nothing, "variability" => "continuous", "changeable" => "false", "causality" => "local", "description" => "Initializing temperature in reactor, K", "alias" => "noAlias"…)
julia> getQuantities(mod, ["T","cA"])
2-element Vector{Dict{Any, Any}}:
- Dict("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("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"…)
julia> showQuantities(mod)
23×10 DataFrame
- Row │ max description name start variabili ⋯
- │ String Union… String String String ⋯
-─────┼──────────────────────────────────────────────────────────────────────────
- 1 │ None Initializing temperature in reac… T None continuou ⋯
- 2 │ None Initializing concentration of A … cA None continuou
- 3 │ None der(Initializing temperature in … der(T) None continuou
- 4 │ None der(Initializing concentration o… der(cA) None continuou
- 5 │ None $cse1 None continuou ⋯
- 6 │ None Heat flow rate, J/min Qd None continuou
- 7 │ None Cooling temperature', K Tc None continuou
- 8 │ None Influent temperature, K Ti None continuou
- ⋮ │ ⋮ ⋮ ⋮ ⋮ ⋮ ⋱
- 17 │ None Heat transfer parameter, J/(min.… UA 50000.0 parameter ⋯
- 18 │ None Reactor volume, L V 100.0 parameter
- 19 │ None Stoichiometric constant, - a 1.0 parameter
- 20 │ None Initial concentration of A, mol/L cA0 0.5 parameter
- 21 │ None Specific heat capacity of mixtur… cph 0.239 parameter ⋯
- 22 │ None Pre-exponential factor, 1/min k0 None parameter
- 23 │ None Liquid density, g/L rho 1000.0 parameter
- 6 columns and 8 rows omitted
julia> getContinuous(mod)
Dict{Any, Any} with 13 entries:
- "T" => "None"
- "der(T)" => "None"
- "Tc" => "None"
- "r" => "None"
- "cA" => "None"
- "\$cse1" => "None"
- "cAi" => "None"
- "k" => "None"
- "Qd" => "None"
- "der(cA)" => "None"
- "Ti" => "None"
- "Vdi" => "None"
- "y_T" => "None"
julia> getContinuous(mod, ["Qd","Tc"])
2-element Vector{String}:
- "None"
- "None"
julia> getInputs(mod)
Dict{Any, Any} with 4 entries:
- "Ti" => "None"
- "cAi" => "None"
- "Vdi" => "None"
- "Tc" => "None"
julia> getOutputs(mod)
Dict{Any, Any} with 1 entry:
- "y_T" => "None"
julia> getParameters(mod)
Dict{Any, Any} with 10 entries:
- "DrHt" => "-50000.0"
- "T0" => "350.0"
- "cph" => "0.239"
- "k0" => "None"
- "V" => "100.0"
- "EdR" => "8750.0"
- "UA" => "50000.0"
- "a" => "1.0"
- "cA0" => "0.5"
- "rho" => "1000.0"
julia> getParameters(mod, ["a","V"])
2-element Vector{String}:
- "1.0"
- "100.0"
julia> getSimulationOptions(mod)
Dict{Any, Any} with 5 entries:
- "startTime" => "0"
- "stopTime" => "1"
- "solver" => "dassl"
- "stepSize" => "0.002"
- "tolerance" => "1e-06"
julia> getSimulationOptions(mod, ["stepSize","tolerance"])
2-element Vector{String}:
- "0.002"
- "1e-06"
To read the simulation results, we need to simulate the model first and use the getSolution() API to read the results
julia> simulate(mod)
The getSolution method can be used in two different ways.
using default result filename use the result filenames provided by user This provides a way to compare simulation results and perform regression testing
julia> getSolutions(mod)
23-element Vector{String}:
- "DrHt"
- "EdR"
- "Qd"
- "T"
- "T0"
- "Tc"
- "Ti"
- "UA"
- "V"
- "Vdi"
- ⋮
- "cph"
- "der(T)"
- "der(cA)"
- "k"
- "k0"
- "r"
- "rho"
- "time"
- "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]
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
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 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 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 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"])
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" => "-50000.0"
- "T0" => "350.0"
- "cph" => "0.239"
- "k0" => "None"
- "V" => "200"
- "EdR" => "8750.0"
- "UA" => "50000.0"
- "a" => "4"
- "cA0" => "0.5"
- "rho" => "1000.0"
julia> setParameters(mod, "a=3.0")
"3.0"
To check whether new values are updated to model , we can again query the getParameters().
julia> getParameters(mod)
Dict{Any, Any} with 10 entries:
- "DrHt" => "-50000.0"
- "T0" => "350.0"
- "cph" => "0.239"
- "k0" => "None"
- "V" => "200"
- "EdR" => "8750.0"
- "UA" => "50000.0"
- "a" => "3.0"
- "cA0" => "0.5"
- "rho" => "1000.0"
Similary we can also use setInputs() to set a value for the inputs during various time interval can also be done using the following.
julia> setInputs(mod, "cAi=100")
true
And finally we simulate the model
julia> simulate(mod)
stopTime=2.0
-
-V=200
-
-a=3.0
-
-tolerance=1e-08
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 performedsimflags
: 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 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 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 getLinearInputs(omc)
Return linear input variables after the model is linearized
Arguments
omc::OMCSession
: OpenModelica compiler session.source getLinearOutputs(omc)
Return linear output variables after the model is linearized
Arguments
omc::OMCSession
: OpenModelica compiler session.source getLinearStates(omc)
Return linear state variables after the model is linearized
Arguments
omc::OMCSession
: OpenModelica compiler session.source julia> getLinearizationOptions(mod)
Dict{AbstractString, AbstractString} with 4 entries:
+ "ModSeborgCSTRorg")
ERROR: Error: Error building simulator. Build log: clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg.o ModSeborgCSTRorg.c
+clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg_functions.o ModSeborgCSTRorg_functions.c
+clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg_records.o ModSeborgCSTRorg_records.c
+clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg_01exo.o ModSeborgCSTRorg_01exo.c
+clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg_02nls.o ModSeborgCSTRorg_02nls.c
+clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg_03lsy.o ModSeborgCSTRorg_03lsy.c
+clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg_04set.o ModSeborgCSTRorg_04set.c
+clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg_05evt.o ModSeborgCSTRorg_05evt.c
+clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg_06inz.o ModSeborgCSTRorg_06inz.c
+clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg_07dly.o ModSeborgCSTRorg_07dly.c
+clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg_08bnd.o ModSeborgCSTRorg_08bnd.c
+clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg_09alg.o ModSeborgCSTRorg_09alg.c
+clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg_10asr.o ModSeborgCSTRorg_10asr.c
+clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg_11mix.o ModSeborgCSTRorg_11mix.c
+clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg_12jac.o ModSeborgCSTRorg_12jac.c
+clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg_13opt.o ModSeborgCSTRorg_13opt.c
+clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg_14lnz.o ModSeborgCSTRorg_14lnz.c
+ModSeborgCSTRorg_14lnz.c:31:1: warning: non-void function does not return a value [-Wreturn-type]
+}
+^
+1 warning generated.
+clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg_15syn.o ModSeborgCSTRorg_15syn.c
+clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg_16dae.o ModSeborgCSTRorg_16dae.c
+clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg_17inl.o ModSeborgCSTRorg_17inl.c
+clang -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o ModSeborgCSTRorg_18spd.o ModSeborgCSTRorg_18spd.c
+clang -I. -o ModSeborgCSTRorg ModSeborgCSTRorg.o ModSeborgCSTRorg_functions.o ModSeborgCSTRorg_records.o ModSeborgCSTRorg_01exo.o ModSeborgCSTRorg_02nls.o ModSeborgCSTRorg_03lsy.o ModSeborgCSTRorg_04set.o ModSeborgCSTRorg_05evt.o ModSeborgCSTRorg_06inz.o ModSeborgCSTRorg_07dly.o ModSeborgCSTRorg_08bnd.o ModSeborgCSTRorg_09alg.o ModSeborgCSTRorg_10asr.o ModSeborgCSTRorg_11mix.o ModSeborgCSTRorg_12jac.o ModSeborgCSTRorg_13opt.o ModSeborgCSTRorg_14lnz.o ModSeborgCSTRorg_15syn.o ModSeborgCSTRorg_16dae.o ModSeborgCSTRorg_17inl.o ModSeborgCSTRorg_18spd.o -L"/home/runner/work/OMJulia.jl/OMJulia.jl/docs/testmodels" -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ModSeborgCSTRorg -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -L"/usr/bin/../lib/x86_64-linux-gnu/omc" -L"/usr/bin/../lib" -Wl,-rpath,"/usr/bin/../lib/x86_64-linux-gnu/omc" -Wl,-rpath,"/usr/bin/../lib" -Wl,--no-as-needed -Wl,--disable-new-dtags -lSimulationRuntimeC -llapack -lblas -lm -lomcgc -lryu -lpthread -rdynamic -Wl,--no-undefined
+/usr/bin/ld: cannot find -lryu: No such file or directory
+clang: error: linker command failed with exit code 1 (use -v to see invocation)
+make: *** [ModSeborgCSTRorg.makefile:37: omc_main_target] Error 1
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
.
getWorkDirectory(omc)
Return working directory of OMJulia.OMCsession omc
.
source julia> getWorkDirectory(mod)
"/tmp/jl_1j4R3i"
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")
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 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 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 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 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 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 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 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 julia> getQuantities(mod)
Any[]
julia> getQuantities(mod, "T")
Any[]
julia> getQuantities(mod, ["T","cA"])
Any[]
julia> showQuantities(mod)
ERROR: BoundsError: attempt to access 0-element Vector{Any} at index [1]
julia> getContinuous(mod)
Dict{Any, Any}()
julia> getContinuous(mod, ["Qd","Tc"])
2-element Vector{Int64}:
+ 0
+ 0
julia> getInputs(mod)
Dict{Any, Any}()
julia> getOutputs(mod)
Dict{Any, Any}()
julia> getParameters(mod)
Dict{Any, Any}()
julia> getParameters(mod, ["a","V"])
2-element Vector{Int64}:
+ 0
+ 0
julia> getSimulationOptions(mod)
Dict{Any, Any}()
julia> getSimulationOptions(mod, ["stepSize","tolerance"])
2-element Vector{Int64}:
+ 0
+ 0
To read the simulation results, we need to simulate the model first and use the getSolution() API to read the results
julia> simulate(mod)
The getSolution method can be used in two different ways.
using default result filename use the result filenames provided by user This provides a way to compare simulation results and perform regression testing
julia> getSolutions(mod)
ERROR: Result file /tmp/jl_1j4R3i/ModSeborgCSTRorg_res.mat does not exist !
julia> getSolutions(mod, ["time","a"])
ERROR: Result file /tmp/jl_1j4R3i/ModSeborgCSTRorg_res.mat does not exist !
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
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 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 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 julia> setInputs(mod, "cAi=100")
ERROR: cAi is not an input variable
julia> setInputs(mod, ["cAi=100","Ti=200","Vdi=300","Tc=250"])
ERROR: cAi is not an input variable
julia> setParameters(mod, "a=3")
[ Info: setParameters() failed: " a" is not a parameter
julia> setParameters(mod, ["a=4","V=200"])
[ Info: setParameters() failed: " a" is not a parameter
+[ Info: setParameters() failed: " V" is not a parameter
julia> setSimulationOptions(mod, ["stopTime=2.0", "tolerance=1e-08"])
ERROR: "stopTime" is not a simulation option
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}()
julia> setParameters(mod, "a=3.0")
[ Info: setParameters() failed: " a" is not a parameter
To check whether new values are updated to model , we can again query the getParameters().
julia> getParameters(mod)
Dict{Any, Any}()
Similary we can also use setInputs() to set a value for the inputs during various time interval can also be done using the following.
julia> setInputs(mod, "cAi=100")
ERROR: cAi is not an input variable
And finally we simulate the model
julia> simulate(mod)
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 performedsimflags
: 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 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 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 getLinearInputs(omc)
Return linear input variables after the model is linearized
Arguments
omc::OMCSession
: OpenModelica compiler session.source getLinearOutputs(omc)
Return linear output variables after the model is linearized
Arguments
omc::OMCSession
: OpenModelica compiler session.source getLinearStates(omc)
Return linear state variables after the model is linearized
Arguments
omc::OMCSession
: OpenModelica compiler session.source julia> getLinearizationOptions(mod)
Dict{AbstractString, AbstractString} with 4 entries:
"startTime" => "0.0"
"stopTime" => "1.0"
"stepSize" => "0.002"
"tolerance" => "1e-6"
julia> getLinearizationOptions(mod, ["startTime","stopTime"])
2-element Vector{String}:
"0.0"
- "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_xbVkbX/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}}:
- [2.392863999884836 1.799622215304339e7; -0.07082366975834854 -258067.3256746422]
- [1.046025104602511 1.5 -20.52354925763564 0.0; 0.0 0.0 0.4999912819590698 1.5]
- [1.0 0.0]
- [0.0 0.0 0.0 0.0]
julia> getLinearInputs(mod)
4-element Vector{String}:
- "Tc"
- "Ti"
- "Vdi"
- "cAi"
julia> getLinearOutputs(mod)
1-element Vector{String}:
- "y_T"
julia> getLinearStates(mod)
2-element Vector{String}:
- "T"
- "cA"
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-2Return
VSname::Vector{Vector{String}}
: Vector of sensitivity namesVSarray::Vector{Vector{Vector{Float64}}}
: Vector of sensitivies: vector of elements per parameterEach element containing time series per variable
source julia> (Sn, Sa) = sensitivity(mod, ["UA","EdR"], ["T","cA"], [1e-2,1e-4])
stopTime=2.0
-
-V=200
-
-a=3.0
-
-tolerance=1e-08
-
-stopTime=2.0
-
-V=200
-
-UA=50500.0
-
-a=3.0
-
-tolerance=1e-08
-
-stopTime=2.0
-
-V=200
-
-EdR=8750.875
-
-UA=50000.0
-
-a=3.0
-
-tolerance=1e-08
+ "1.0"
julia> setLinearizationOptions(mod,["stopTime=2.0","tolerance=1e-06"])
julia> res = linearize(mod)
ERROR: Linearization cannot be performed as the model is not build, use ModelicaSystem() to build the model first
julia> getLinearInputs(mod)
ERROR: Model is not linearized
julia> getLinearOutputs(mod)
Model is not Linearized
julia> getLinearStates(mod)
Model is not Linearized
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-2Return
VSname::Vector{Vector{String}}
: Vector of sensitivity namesVSarray::Vector{Vector{Vector{Float64}}}
: Vector of sensitivies: vector of elements per parameterEach element containing time series per variable
source julia> (Sn, Sa) = sensitivity(mod, ["UA","EdR"], ["T","cA"], [1e-2,1e-4])
ERROR: MethodError: no method matching parse(::Type{Float64}, ::Int64)
-([["Sensitivity.UA.T", "Sensitivity.UA.cA"], ["Sensitivity.EdR.T", "Sensitivity.EdR.cA"]], [[[0.0, -8.46484032376793e-6, -1.8798798871330292e-5, -4.054143004407251e-5, -0.0002802572975637076, -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.03215445409032873, -0.03216487956045239, -0.03217521894061974, -0.03217521894061974], [0.0, 2.601676771796235e-9, 3.3445380128060974e-8, 2.2605955135546197e-7, 3.531872343070397e-6, 8.329957789199316e-8, 7.168512584540543e-8, 6.345060944540349e-8, 5.638188856171844e-8, 5.040525208062363e-8 … 8.856962310426018e-9, 8.860592887278192e-9, 8.865492741880112e-9, 8.867668825999867e-9, 8.868961481592243e-9, 8.86904980795973e-9, 8.868635808971862e-9, 8.870353771222184e-9, 8.872947805761873e-9, 8.872947805761873e-9]], [[0.0, -2.413557467662031e-6, -1.3162186275751861e-5, 0.00015636715482157473, 0.01317791023413, 0.0042572811244099285, 0.0030510811233658125, 0.002350161991801412, 0.0018775321397177841, 0.0015375293686312424 … 0.00011258585228850799, 0.00011259551164195207, 0.00011268012895016, 0.00011274436006455549, 0.00011269701125066993, 0.0001126057852941033, 0.00011244580673519522, 0.00011218779504166118, 0.000111797775649133, 0.000111797775649133], [0.0, 3.464740799025938e-8, 1.8925106383603308e-7, -2.2433035990080237e-6, -0.00018911546028326548, -6.305955485792174e-5, -4.596477555188613e-5, -3.606039447237982e-5, -2.9394320518992346e-5, -2.4605578297357384e-5 … -1.5254439210011378e-6, -1.52539591180333e-6, -1.5253540044091085e-6, -1.5253116510925702e-6, -1.5252627386591909e-6, -1.5252130899819083e-6, -1.5251617968127914e-6, -1.5251077768125128e-6, -1.5250497614149674e-6, -1.5250497614149674e-6]]])
Theme
documenter-light documenter-dark
This document was generated with Documenter.jl version 0.27.25 on Tuesday 12 September 2023 . Using Julia version 1.9.3.