Advanced API
A Julia style scripting API that handles low level API calls.
ModelicaSystem
OMJulia.ModelicaSystem
— FunctionModelicaSystem(omc, fileName, 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, seeOMCSession()
.fileName
: Path to Modelica file.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"]
).
Keyword Arguments
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, "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()
.
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, seeOMCSession()
.
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()
.
OMJulia.OMCSession
— TypeOMCSession <: Any
OMC session struct.
OMCSession(omc=nothing)
Create new OpenModelica session.
Arguments
omc::Union{String, Nothing}
: Path to OpenModelica compiler. Use omc fromPATH
if nothing is provided.
See also ModelicaSystem
, OMJulia.quit
.
OMJulia.quit
— Functionquit(omc::OMCSession; timeout=4::Integer)
Quit OMCSession.
Arguments
- `omc::OMCSession`: OMC session.
Keywords
- `timeout=4::Integer`: Timeout in seconds.
See also OMJulia.OMCSession
.
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
// Parameters
parameter Real V = 100 "Reactor volume, L";
parameter Real rho = 1e3 "Liquid density, g/L";
parameter Real a = 1 "Stoichiometric constant, -";
parameter Real EdR = 8750 "Activation temperature, K";
parameter Real k0 = exp(EdR/350) "Pre-exponential factor, 1/min";
parameter Real cph = 0.239 "Specific heat capacity of mixture, J.g-1.K-1";
parameter Real DrHt = -5e4 "Molar enthalpy of reaction, J/mol";
parameter Real UA = 5e4 "Heat transfer parameter, J/(min.K)";
// Initial state parameters
parameter Real cA0 = 0.5 "Initial concentration of A, mol/L";
parameter Real T0 = 350 "Initial temperature, K";
// Declaring variables
// -- states
Real cA(start = cA0, fixed = true) "Initializing concentration of A in reactor, mol/L";
Real T(start = T0, fixed = true) "Initializing temperature in reactor, K";
// -- auxiliary variables
Real r "Rate of reaction, mol/(L.s)";
Real k "Reaction 'constant', ...";
Real Qd "Heat flow rate, J/min";
// -- input variables
input Real Vdi "Volumetric flow rate through reactor, L/min";
input Real cAi "Influent molar concentration of A, mol/L";
input Real Ti "Influent temperature, K";
input Real Tc "Cooling temperature', K";
// -- output variables
output Real y_T "Reactor temperature, K";
// Equations constituting the model
equation
// Differential equations
der(cA) = Vdi*(cAi-cA)/V- a*r;
der(T) = Vdi*(Ti-T)/V + (-DrHt)*r/(rho*cph) + Qd/(rho*V*cph);
// Algebraic equations
r = k*cA^a;
k = k0*exp(-EdR/T);
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.1m1NtMp5qD" 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} @0x000000000379e300, WeakRef[WeakRef(ZMQ.Socket(Ptr{Nothing} @0x0000000002fc0240, FileWatching._FDWatcher(Ptr{Nothing} @0x00000000037b5a40, 30, (1, 0), Base.GenericCondition{Base.Threads.SpinLock}(Base.IntrusiveLinkedList{Task}(nothing, nothing), Base.Threads.SpinLock(0)), 0, (false, false))))]), ZMQ.Socket(Ptr{Nothing} @0x0000000002fc0240, FileWatching._FDWatcher(Ptr{Nothing} @0x00000000037b5a40, 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.1m1NtMp5qD`, 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.getWorkDirectory
— FunctiongetWorkDirectory(omc)
Return working directory of OMJulia.OMCsession omc
.
julia> getWorkDirectory(mod)
"/tmp/jl_TVABu3"
Build Model
OMJulia.buildModel
— FunctionbuildModel(omc; variableFilter=nothing)
Build modelica model.
Arguments
omc::OMCSession
: OpenModelica compiler session.
Keyword Arguments
variableFilter
: Regex to filter variables in result file.
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.getQuantities
— FunctiongetQuantities(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
.
OMJulia.showQuantities
— FunctionshowQuantities(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
.
OMJulia.getContinuous
— FunctiongetContinuous(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.
OMJulia.getInputs
— FunctiongetInputs(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.
OMJulia.getOutputs
— FunctiongetInputs(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.
OMJulia.getParameters
— FunctiongetParameters(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.
OMJulia.getSimulationOptions
— FunctiongetSimulationOptions(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.
OMJulia.getSolutions
— FunctiongetSolutions(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.
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"…) 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" => "5e4", "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 variability ⋯ │ String Union… String String String ⋯ ─────┼────────────────────────────────────────────────────────────────────────── 1 │ None Initializing temperature in reac… T None continuous ⋯ 2 │ None Initializing concentration of A … cA None continuous 3 │ None der(Initializing temperature in … der(T) None continuous 4 │ None der(Initializing concentration o… der(cA) None continuous 5 │ None $cse1 None continuous ⋯ 6 │ None Heat flow rate, J/min Qd None continuous 7 │ None Cooling temperature', K Tc None continuous 8 │ None Influent temperature, K Ti None continuous ⋮ │ ⋮ ⋮ ⋮ ⋮ ⋮ ⋱ 17 │ None Heat transfer parameter, J/(min.… UA 5e4 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 5 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" => "-5e4" "T0" => "350.0" "cph" => "0.239" "k0" => "None" "V" => "100.0" "EdR" => "8750.0" "UA" => "5e4" "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"
Reading Simulation Results
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]
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.setInputs
— FunctionsetInputs(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"])
OMJulia.setParameters
— FunctionsetParameters(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.
OMJulia.setSimulationOptions
— FunctionsetSimulationOptions(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"])
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.simulate
— Functionsimulate(omc; resultfile=nothing, simflags="", verbose=false)
Simulate modelica model.
Arguments
omc::OMCSession
: OpenModelica compiler session, seeOMCSession()
.
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 tolog.txt
anderror.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")
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" "k0" => "None" "V" => "200" "EdR" => "8750.0" "UA" => "5e4" "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" => "-5e4" "T0" => "350.0" "cph" => "0.239" "k0" => "None" "V" => "200" "EdR" => "8750.0" "UA" => "5e4" "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
Linearization
OMJulia.linearize
— Functionfunction 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")
OMJulia.getLinearizationOptions
— FunctiongetLinearizationOptions(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.
OMJulia.setLinearizationOptions
— FunctionsetLinearizationOptions(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"])
OMJulia.getLinearInputs
— FunctiongetLinearInputs(omc)
Return linear input variables after the model is linearized
Arguments
omc::OMCSession
: OpenModelica compiler session.
OMJulia.getLinearOutputs
— FunctiongetLinearOutputs(omc)
Return linear output variables after the model is linearized
Arguments
omc::OMCSession
: OpenModelica compiler session.
OMJulia.getLinearStates
— FunctiongetLinearStates(omc)
Return linear state variables after the model is linearized
Arguments
omc::OMCSession
: OpenModelica compiler session.
Examples
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_TVABu3/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 Analysis
OMJulia.sensitivity
— Functionsensitivity(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 namesVSarray::Vector{Vector{Vector{Float64}}}
: Vector of sensitivies: vector of elements per parameter
Each element containing time series per variable
Examples
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 ([["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]]])