Skip to content

Commit bf603de

Browse files
arun3688lochel
authored andcommitted
update OMPython-OMjulia-OMMatlab documentation
1 parent e613a91 commit bf603de

File tree

3 files changed

+102
-46
lines changed

3 files changed

+102
-46
lines changed

doc/UsersGuide/source/omjulia.rst

Lines changed: 73 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ To get started, create an OMJulia session object:
4141

4242
>>> using OMJulia
4343
>>> omc= OMJulia.OMCSession()
44-
>>> omc.sendExpression("loadModel(Modelica)")
45-
"True"
46-
>>> omc.sendExpression("model a Real s; equation s=sin(10*time); end a;")
47-
"{a}"
48-
>>> omc.sendExpression("simulate(a)")
49-
>>> omc.sendExpression("plot(s)")
50-
"true"
44+
>>> sendExpression(omc,"loadModel(Modelica)")
45+
true
46+
>>> sendExpression(omc,"model a Real s; equation s=sin(10*time); end a;")
47+
1-element Array{Symbol,1}:
48+
:a
49+
>>> sendExpression(omc,"simulate(a)")
50+
>>> sendExpression(omc,"plot(s)")
51+
true
5152

5253
.. figure :: media/sineplot.png
5354
:name: sineplot
@@ -62,7 +63,7 @@ To get started, create a ModelicaSystem object:
6263

6364
>>> using OMJulia
6465
>>> mod = OMJulia.OMCSession()
65-
>>> mod.ModelicaSystem("BouncingBall.mo","BouncingBall")
66+
>>> ModelicaSystem(mod,"BouncingBall.mo","BouncingBall")
6667

6768
The object constructor requires a minimum of 2 input arguments which are strings, and third input argument which is optional .
6869

@@ -72,10 +73,24 @@ The object constructor requires a minimum of 2 input arguments which are strings
7273
- The second input argument must be a string with the name of the Modelica model
7374
including the namespace if the model is wrapped within a Modelica package.
7475

75-
- The third input argument (optional) is used to specify the list of dependent libraries
76+
- The third input argument (optional) is used to specify the list of dependent libraries or dependent Modelica files
7677
The argument can be passed as a string or array of strings e.g.,
7778

78-
>>> mod.ModelicaSystem("BouncingBall.mo","BouncingBall",["Modelica", "SystemDynamics"])
79+
>>> ModelicaSystem(mod,"BouncingBall.mo","BouncingBall",["Modelica", "SystemDynamics", "dcmotor.mo"])
80+
81+
WorkDirectory
82+
~~~~~~~~~~~~~
83+
For each OMJulia session a temporary work directory is created and the results are published in that working directory, Inorder to get the workdirectory the users can
84+
use the following API
85+
86+
>>> getWorkDirectory(mod)
87+
"C:/Users/arupa54/AppData/Local/Temp/jl_5pbewl"
88+
89+
BuildModel
90+
~~~~~~~~~~
91+
The buildModel API can be used after ModelicaSystem(), in case the model needs to be updated or additional simulationflags needs to be set using sendExpression()
92+
93+
>>> buildModel(mod)
7994

8095

8196
Standard get methods
@@ -99,45 +114,56 @@ Three calling possibilities are accepted using getXXX() where "XXX" can be any o
99114
Usage of getMethods
100115
~~~~~~~~~~~~~~~~~~~
101116

102-
>>> mod.getQuantities() // method-1, list of all variables from xml file
117+
>>> getQuantities(mod) // method-1, list of all variables from xml file
103118
[{"aliasvariable": None, "Name": "height", "Variability": "continuous", "Value": "1.0", "alias": "noAlias", "Changeable": "true", "Description": None}, {"aliasvariable": None, "Name": "c", "Variability": "parameter", "Value": "0.9", "alias": "noAlias", "Changeable": "true", "Description": None}]
104119

105-
>>> mod.getQuantities("height") // method-2, to query information about single quantity
120+
>>> getQuantities(mod,"height") // method-2, to query information about single quantity
106121
[{"aliasvariable": None, "Name": "height", "Variability": "continuous", "Value": "1.0", "alias": "noAlias", "Changeable": "true", "Description": None}]
107122

108-
>>> mod.getQuantities(["c","radius"]) // method-3, to query information about list of quantity
123+
>>> getQuantities(mod,["c","radius"]) // method-3, to query information about list of quantity
109124
[{"aliasvariable": None, "Name": "c", "Variability": "parameter", "Value": "0.9", "alias": "noAlias", "Changeable": "true", "Description": None}, {"aliasvariable": None, "Name": "radius", "Variability": "parameter", "Value": "0.1", "alias": "noAlias", "Changeable": "true", "Description": None}]
110125

111-
>>> mod.getContinuous() // method-1, list of continuous variable
126+
>>> getContinuous(mod) // method-1, list of continuous variable
112127
{"velocity": "-1.825929609047952", "der(velocity)": "-9.8100000000000005", "der(height)": "-1.825929609047952", "height": "0.65907039052943617"}
113128

114-
>>> mod.getContinuous(["velocity","height"]) // method-2, get specific variable value information
129+
>>> getContinuous(mod,["velocity","height"]) // method-2, get specific variable value information
115130
["-1.825929609047952", "0.65907039052943617"]
116131

117-
>>> mod.getInputs()
132+
>>> getInputs(mod)
118133
{}
119134

120-
>>> mod.getOutputs()
135+
>>> getOutputs(mod)
121136
{}
122137

123-
>>> mod.getParameters() // method-1
138+
>>> getParameters(mod) // method-1
124139
{"c": "0.9", "radius": "0.1"}
125140

126-
>>> mod.getParameters(["c","radius"]) // method-2
141+
>>> getParameters(mod,["c","radius"]) // method-2
127142
["0.9", "0.1"]
128143

129-
>>> mod.getSimulationOptions() // method-1
144+
>>> getSimulationOptions(mod) // method-1
130145
{"stepSize": "0.002", "stopTime": "1.0", "tolerance": "1e-06", "startTime": "0.0", "solver": "dassl"}
131146

132-
>>> mod.getSimulationOptions(["stepSize","tolerance"]) // method-2
147+
>>> getSimulationOptions(mod,["stepSize","tolerance"]) // method-2
133148
["0.002", "1e-06"]
134149

135-
>>> mod.getSolutions() // method-1 returns list of simulation variables for which results are available
150+
The getSolution method can be used in two different ways.
151+
1) using default result filename
152+
2) use the result filenames provided by user
153+
154+
This provides a way to compare simulation results and perform regression testing
155+
156+
>>> getSolutions(mod) // method-1 returns list of simulation variables for which results are available
136157
["time", "height", ""velocity", "der(height)", "der(velocity)", "c", "radius"]
137158

138-
>>> mod.getSolutions(["time","height"]) // method-2, return list of array
159+
>>> getSolutions(mod,["time","height"]) // return list of array
160+
161+
>>> getSolutions(mod,resultfile="c:/tmpbouncingBall.mat") // method-2 returns list of simulation variables for which results are available , the resulfile location is provided by user
162+
["time", "height", ""velocity", "der(height)", "der(velocity)", "c", "radius"]
139163

140-
>>> mod.showQuantities() // same as getQuantities() but returns the results in the form table
164+
>>> getSolutions(mod,["time","h"],resultfile="c:/tmpbouncingBall.mat") // return list of array
165+
166+
>>> showQuantities(mod) // same as getQuantities() but returns the results in the form table
141167

142168
Standard set methods
143169
~~~~~~~~~~~~~~~~~~~~
@@ -154,38 +180,42 @@ Two setting possibilities are accepted using setXXXs(),where "XXX" can be any of
154180
Usage of setMethods
155181
~~~~~~~~~~~~~~~~~~~
156182

157-
>>> mod.setInputs("cAi=1") // method-1
183+
>>> setInputs(mod,"cAi=1") // method-1
158184

159-
>>> mod.setInputs(["cAi=1","Ti=2"]) // method-2
185+
>>> setInputs(mod,["cAi=1","Ti=2"]) // method-2
160186

161-
>>> mod.setParameters("radius=14") // method-1
187+
>>> setParameters(mod,"radius=14") // method-1
162188

163-
>>> mod.setParameters(["radius=14","c=0.5"]) // method-2 setting parameter value using array of string
189+
>>> setParameters(mod,["radius=14","c=0.5"]) // method-2 setting parameter value using array of string
164190

165-
>>> mod.setSimulationOptions(["stopTime=2.0","tolerance=1e-08"])
191+
>>> setSimulationOptions(mod,["stopTime=2.0","tolerance=1e-08"])
166192

167193

168194
Advanced Simulation
169195
~~~~~~~~~~~~~~~~~~~
170196
An example of how to do advanced simulation to set parameter values using set methods and finally simulate the "BouncingBall.mo" model is given below .
171197

172-
>>> mod.getParameters()
198+
>>> getParameters(mod)
173199
{"c": "0.9", "radius": "0.1"}
174200

175-
>>> mod.setParameters(["radius=14","c=0.5"])
201+
>>> setParameters(mod,["radius=14","c=0.5"])
176202

177203
To check whether new values are updated to model , we can again query the getParameters().
178204

179-
>>> mod.getParameters()
205+
>>> getParameters(mod)
180206
{"c": "0.5", "radius": "14"}
181207

182208
Similary we can also use setInputs() to set a value for the inputs during various time interval can also be done using the following.
183209

184-
>>> mod.setInputs("cAi=1")
210+
>>> setInputs(mod,"cAi=1")
211+
212+
And then finally we can simulate the model using, The simulate() API can be used in two methods
213+
1) without any arguments
214+
2) resultfile names provided by user (only filename is allowed and not the location)
185215

186-
And then finally we can simulate the model using.
216+
>>> simulate(mod) // method-1 default result file name will be used
217+
>>> simulate(mod,resultfile="tmpbouncingBall.mat") // method-2 resultfile name provided by users
187218

188-
>>> mod.simulate()
189219

190220
Linearization
191221
~~~~~~~~~~~~~
@@ -201,21 +231,21 @@ The following methods are available for linearization of a modelica model
201231
Usage of Linearization methods
202232
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
203233

204-
>>> mod.getLinearizationOptions() // method-1
234+
>>> getLinearizationOptions(mod) // method-1
205235
{"stepSize": "0.002", "stopTime": "1.0", "startTime": "0.0", "numberOfIntervals": "500.0", "tolerance": "1e-08"}
206236

207-
>>> mod.getLinearizationOptions(["startTime","stopTime"]) // method-2
237+
>>> getLinearizationOptions(mod,["startTime","stopTime"]) // method-2
208238
["0.0", "1.0"]
209239

210-
>>> mod.setLinearizationOptions(["stopTime=2.0","tolerance=1e-06"])
240+
>>> setLinearizationOptions(mod,["stopTime=2.0","tolerance=1e-06"])
211241

212-
>>> mod.linearize() //returns a list 2D arrays (matrices) A, B, C and D.
242+
>>> linearize(mod) //returns a list 2D arrays (matrices) A, B, C and D.
213243

214-
>>> mod.getLinearInputs() //returns a list of strings of names of inputs used when forming matrices.
244+
>>> getLinearInputs(mod) //returns a list of strings of names of inputs used when forming matrices.
215245

216-
>>> mod.getLinearOutputs() //returns a list of strings of names of outputs used when forming matrices.
246+
>>> getLinearOutputs(mod) //returns a list of strings of names of outputs used when forming matrices.
217247

218-
>>> mod.getLinearStates() // returns a list of strings of names of states used when forming matrices.
248+
>>> getLinearStates(mod) // returns a list of strings of names of states used when forming matrices.
219249

220250

221251
Sensitivity Analysis
@@ -239,7 +269,7 @@ The results contains the following .
239269
Usage
240270
~~~~~
241271

242-
>>> (Sn, Sa) = mod.sensitivity(["UA","EdR"],["T","cA"],[1e-2,1e-4])
272+
>>> (Sn, Sa) = sensitivity(mod,["UA","EdR"],["T","cA"],[1e-2,1e-4])
243273

244274

245275
With the above list of API calls implemented, the users can have more control over the result types, returned as Julia data structures.

doc/UsersGuide/source/ommatlab.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ use the following API
8888
>>> omc.getWorkDirectory()
8989
'C:/Users/arupa54/AppData/Local/Temp/tp7dd648e5_5de6_4f66_b3d6_90bce1fe1d58'
9090

91+
BuildModel
92+
~~~~~~~~~~
93+
The buildModel API can be used after ModelicaSystem(), in case the model needs to be updated or additional simulationflags needs to be set using sendExpression()
94+
95+
>>> buildModel(mod)
9196

9297
Standard get methods
9398
~~~~~~~~~~~~~~~~~~~~

doc/UsersGuide/source/ompython.rst

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ The object constructor requires a minimum of 2 input arguments which are strings
184184
- By default ModelicaSystem uses OMCSessionZMQ but if you want to use OMCSession
185185
then pass the argument `useCorba=True` to the constructor.
186186

187+
BuildModel
188+
~~~~~~~~~~
189+
The buildModel API can be used after ModelicaSystem(), in case the model needs to be updated or additional simulationflags needs to be set using sendExpression()
190+
191+
>>> mod.buildModel()
192+
193+
187194
Standard get methods
188195
~~~~~~~~~~~~~~~~~~~~
189196

@@ -237,10 +244,21 @@ Usage of getMethods
237244
>>> mod.getSimulationOptions("stepSize","tolerance") // method-2
238245
(0.002, 1e-06)
239246

247+
The getSolution method can be used in two different ways.
248+
1) using default result filename
249+
2) use the result filenames provided by user
250+
251+
This provides a way to compare simulation results and perform regression testing
252+
240253
>>> mod.getSolutions() // method-1 returns list of simulation variables for which results are available
241254
['time', 'height', 'velocity', 'der(height)', 'der(velocity)', 'c', 'radius']
242255

243-
>>> mod.getSolutions("time","height") // method-2, return list of numpy arrays
256+
>>> mod.getSolutions("time","height") // return list of numpy arrays
257+
258+
>>> mod.getSolutions(resultfile="c:/tmpbouncingBall.mat") // method-2 returns list of simulation variables for which results are available , the resulfile location is provided by user
259+
260+
>>> mod.getSolutions(["time","height"],resultfile="c:/tmpbouncingBall.mat") // return list of array
261+
244262

245263
Standard set methods
246264
~~~~~~~~~~~~~~~~~~~~
@@ -279,9 +297,12 @@ To check whether new values are updated to model , we can again query the getPar
279297
>>> mod.getParameters()
280298
{'c': 0.5, 'radius': 14}
281299

282-
And then finally we can simulate the model using.
300+
And then finally we can simulate the model using, The simulate() API can be used in two methods
301+
1) without any arguments
302+
2) resultfile names provided by user (only filename is allowed and not the location)
283303

284-
>>> mod.simulate()
304+
>>> mod.simulate() // method-1 default result file name will be used
305+
>>> mod.simulate(resultfile="tmpbouncingBall.mat") // method-2 resultfile name provided by users
285306

286307
Linearization
287308
~~~~~~~~~~~~~

0 commit comments

Comments
 (0)