Skip to content

Commit a5bc99b

Browse files
arun3688adrpo
authored andcommitted
add enhancedOMPython features
1 parent 801d0f7 commit a5bc99b

File tree

1 file changed

+72
-2
lines changed

1 file changed

+72
-2
lines changed

UsersGuide/source/ompython.rst

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,78 @@ OMPython provides user friendly features like:
5252

5353
- Easy access to the library and testing of OpenModelica commands.
5454

55-
Test Commands
56-
~~~~~~~~~~~~~
55+
Features of Enhanced OMPython
56+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57+
Some more improvements are added to OMPython functionality for querying more information about the models
58+
and simulate them. A list of new user friendly API functionality allows user to extract information about models using python
59+
objects. A list of API functionality is described below.
60+
61+
To get started, create a ModelicaSystem object:
62+
63+
>>> from OMPython import ModelicaSystem
64+
>>> mod=ModelicaSystem("BouncingBall.mo","BouncingBall")
65+
66+
The object constructor requires a minimum of 2 input arguments which are strings, and may need a third string input argument.
67+
68+
- The first input argument must be a string with the file name of the Modelica code, with Modelica file extension ".mo"
69+
If the Modelica file is not in the current directory of Python, then the file path must also be included
70+
71+
- The second input argument must be a string with the name of the Modelica model
72+
including the namespace if the model is wrapped within a Modelica package
73+
74+
- A third input argument is used if the Modelica model builds on other Modelica code, e.g. the Modelica Standard Library.
75+
76+
Standard get methods API
77+
~~~~~~~~~~~~~~~~~~~~~~~~~
78+
79+
>>> mod.getQuantities()
80+
>>> mod.getContinuous()
81+
>>> mod.getInputs()
82+
>>> mod.getOutputs()
83+
>>> mod.getParameters()
84+
>>> mod.getSimulationOptions()
85+
86+
Two calling possibilities are accepted using getXXX() where "XXX" can be any of the above functions (eg:) getParameters().
87+
88+
- getXXX() without input argument, returns a dictionary with names as keys and values as values.
89+
- getXXX(S), where S is a sequence of strings of names, returns a tuple of values for the specified names.
90+
91+
92+
Standard set methods API
93+
~~~~~~~~~~~~~~~~~~~~~~~~~
94+
95+
>>> mod.setInputs()
96+
>>> mod.setParameters()
97+
>>> mod.setSimulationOptions()
98+
99+
Two calling possibilities are accepted using setXXXs(),where "XXX" can be any of above functions.
100+
101+
- setXXX(k) with K being a sequence of keyword assignments of type quantity name = value Here, the quantity name could be
102+
a parameter name (i.e., not a string), an input name, etc.
103+
- setXXXs(**D), with D being a dictionary with quantity names as keywords and values as described with the alternative
104+
input argument K.
105+
106+
Example usage of Above API
107+
~~~~~~~~~~~~~~~~~~~~~~~~~~
108+
An example of how to get parameter names and change the value of parameters using set methods and finally simulate the "BouncingBall.mo" model is given below.
109+
110+
>>> mod.getParameters()
111+
{'c': 0.9, 'radius': 0.1}
112+
113+
>>> mod.setParameters(radius=14,c=0.5) //setting parameter value using first option
114+
>>> mod.setParameters(**{"radius":14,"c":0.5}) // setting parameter value using second option
115+
116+
To check whether new values are updated to model , we can again query the getParameters().
117+
118+
>>> mod.getParameters()
119+
{'c': 0.5, 'radius': 14}
120+
121+
And then finally we can simulate the model using.
122+
123+
>>> mod.simulate()
124+
125+
Test Commands using old OMPython features
126+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57127

58128
To test the command outputs, simply create an OMCSession object by
59129
importing from the OMPython library within Python interepreter. The

0 commit comments

Comments
 (0)