Skip to content

Commit

Permalink
add python support for oms_exportSSVTemplate (#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
arun3688 committed Nov 11, 2020
1 parent eab0ce5 commit 0822d01
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 3 deletions.
38 changes: 38 additions & 0 deletions doc/UsersGuide/source/api/exportSSVTemplate.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#CAPTION#
exportSSVTemplate
-----------------

Exports all signals that have start values of one or multiple FMUs to a SSV file that are read from modelDescription.xml. The function can be called for a top level model or a certain FMU component.
If called for a top level model, start values of all FMUs are exported to the SSV file. If called for a component, start values of just this FMU are exported to the SSV file.
#END#

#LUA#
.. code-block:: lua
status = oms_exportSSVTemplate(cref, filename)
#END#

#PYTHON#
.. code-block:: python
status = oms.exportSSVTemplate(cref, filename)
#END#

#CAPI#
.. code-block:: c
oms_status_enu_t oms_exportSSVTemplate(const char* cref, const char* filename)
#END#

#OMC#
.. code-block:: Modelica
# not available
#END#

#DESCRIPTION#
#END#
2 changes: 1 addition & 1 deletion doc/UsersGuide/source/api/exportSnapshot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ doesn't need to call free.
#PYTHON#
.. code-block:: python
contents, status = oms_exportSnapshot(cref)
contents, status = oms.exportSnapshot(cref)
#END#

Expand Down
2 changes: 1 addition & 1 deletion doc/UsersGuide/source/api/importSnapshot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Loads a snapshot to restore a previous model state. The model must be in virgin
#PYTHON#
.. code-block:: python
status = oms_importSnapshot(cref, snapshot)
status = oms.importSnapshot(cref, snapshot)
#END#

Expand Down
2 changes: 1 addition & 1 deletion doc/UsersGuide/source/api/loadSnapshot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Loads a snapshot to restore a previous model state. The model must be in virgin
#PYTHON#
.. code-block:: python
status = oms_loadSnapshot(cref, snapshot)
status = oms.loadSnapshot(cref, snapshot)
#END#

Expand Down
4 changes: 4 additions & 0 deletions src/OMSimulatorPython/OMSimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ def __init__(self, omslib=None, temp_directory=None):
self.obj.oms_exportDependencyGraphs.restype = ctypes.c_int
self.obj.oms_exportSnapshot.argtypes = [ctypes.c_char_p]
self.obj.oms_exportSnapshot.restype = ctypes.c_int
self.obj.oms_exportSSVTemplate.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
self.obj.oms_exportSSVTemplate.restype = ctypes.c_int
self.obj.oms_faultInjection.argtypes = [ctypes.c_char_p, ctypes.c_int, ctypes.c_double]
self.obj.oms_faultInjection.restype = ctypes.c_int
self.obj.oms_getBoolean.argtypes = [ctypes.c_char_p, ctypes.POINTER(ctypes.c_bool)]
Expand Down Expand Up @@ -279,6 +281,8 @@ def exportSnapshot(self, ident):
contents = ctypes.c_char_p()
status = self.obj.oms_exportSnapshot(self.checkstring(ident), ctypes.byref(contents))
return [self.checkstring(contents.value), status]
def exportSSVTemplate(self, ident, filename):
return self.obj.oms_exportSSVTemplate(self.checkstring(ident), self.checkstring(filename))
def listUnconnectedConnectors(self, ident):
contents = ctypes.c_char_p()
status = self.obj.oms_listUnconnectedConnectors(self.checkstring(ident), ctypes.byref(contents))
Expand Down
94 changes: 94 additions & 0 deletions testsuite/OMSimulator/exportSSVTemplate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
## status: correct
## linux: yes
## mingw: yes
## win: no
## mac: no

from OMSimulator import OMSimulator
oms = OMSimulator()

oms.setCommandLineOption("--suppressPath=true")
oms.setTempDirectory("./exportssvtemplate_py/")


def readFile(filename):
f = open(filename, "r")
content = f.read()
print(content)
f:close()



oms.newModel("test")

oms.addSystem("test.Root", oms.system_wc)

oms.addSubModel("test.Root.Gain", "../resources/Modelica.Blocks.Math.Gain.fmu")
oms.addSubModel("test.Root.add", "../resources/Modelica.Blocks.Math.Add.fmu")

oms.exportSSVTemplate("test", "template.ssv")
readFile("template.ssv")

oms.exportSSVTemplate("test.Root.add", "add.ssv")
readFile("add.ssv")

oms.exportSSVTemplate("test.Root.Gain", "gain.ssv")
readFile("gain.ssv")


## Result:
## <?xml version="1.0" encoding="UTF-8"?>
## <ssv:ParameterSet xmlns:ssc="http://ssp-standard.org/SSP1/SystemStructureCommon" xmlns:ssv="http://ssp-standard.org/SSP1/SystemStructureParameterValues" version="1.0" name="modelDescriptionStartValues">
## <ssv:Parameters>
## <ssv:Parameter name="add.u2">
## <ssv:Real value="0" />
## </ssv:Parameter>
## <ssv:Parameter name="add.u1">
## <ssv:Real value="0" />
## </ssv:Parameter>
## <ssv:Parameter name="add.k2">
## <ssv:Real value="1" />
## </ssv:Parameter>
## <ssv:Parameter name="add.k1">
## <ssv:Real value="1" />
## </ssv:Parameter>
## <ssv:Parameter name="Gain.u">
## <ssv:Real value="0" />
## </ssv:Parameter>
## <ssv:Parameter name="Gain.k">
## <ssv:Real value="1" />
## </ssv:Parameter>
## </ssv:Parameters>
## </ssv:ParameterSet>
##
## <?xml version="1.0" encoding="UTF-8"?>
## <ssv:ParameterSet xmlns:ssc="http://ssp-standard.org/SSP1/SystemStructureCommon" xmlns:ssv="http://ssp-standard.org/SSP1/SystemStructureParameterValues" version="1.0" name="modelDescriptionStartValues">
## <ssv:Parameters>
## <ssv:Parameter name="add.u2">
## <ssv:Real value="0" />
## </ssv:Parameter>
## <ssv:Parameter name="add.u1">
## <ssv:Real value="0" />
## </ssv:Parameter>
## <ssv:Parameter name="add.k2">
## <ssv:Real value="1" />
## </ssv:Parameter>
## <ssv:Parameter name="add.k1">
## <ssv:Real value="1" />
## </ssv:Parameter>
## </ssv:Parameters>
## </ssv:ParameterSet>
##
## <?xml version="1.0" encoding="UTF-8"?>
## <ssv:ParameterSet xmlns:ssc="http://ssp-standard.org/SSP1/SystemStructureCommon" xmlns:ssv="http://ssp-standard.org/SSP1/SystemStructureParameterValues" version="1.0" name="modelDescriptionStartValues">
## <ssv:Parameters>
## <ssv:Parameter name="Gain.u">
## <ssv:Real value="0" />
## </ssv:Parameter>
## <ssv:Parameter name="Gain.k">
## <ssv:Real value="1" />
## </ssv:Parameter>
## </ssv:Parameters>
## </ssv:ParameterSet>
##
## endResult

0 comments on commit 0822d01

Please sign in to comment.