Skip to content

Commit

Permalink
delete parameter bindings references in ssd (#1079)
Browse files Browse the repository at this point in the history
  • Loading branch information
arun3688 authored Sep 6, 2021
1 parent 738b794 commit c5c0169
Show file tree
Hide file tree
Showing 34 changed files with 4,356 additions and 46 deletions.
52 changes: 52 additions & 0 deletions doc/UsersGuide/source/api/addResources.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#CAPTION#
addResources
------------

Adds an external resources to an existing SSP. The external resources should be a ".ssv" or ".ssm" file
#END#

#LUA#
.. code-block:: lua
status = oms_addResources(cref, path)
-- Example
oms_importFile("addExternalResources1.ssp")
-- add list of external resources from filesystem to ssp
oms_addResources("addExternalResources", "../../resources/externalRoot.ssv")
oms_addResources("addExternalResources:externalSystem.ssv", "../../resources/externalSystem1.ssv")
oms_addResources("addExternalResources", "../../resources/externalGain.ssv")
-- export the ssp with new resources
oms_export("addExternalResources", "addExternalResources1.ssp")
#END#

#PYTHON#
.. code-block:: python
status = oms.addResources(cref, path)
## Example
from OMSimulator import OMSimulator
oms = OMSimulator()
oms.importFile("addExternalResources1.ssp")
## add list of external resources from filesystem to ssp
oms.addResources("addExternalResources", "../../resources/externalRoot.ssv")
oms.addResources("addExternalResources:externalSystem.ssv", "../../resources/externalSystem1.ssv")
oms.addResources("addExternalResources", "../../resources/externalGain.ssv")
## export the ssp with new resources
oms_export("addExternalResources", "addExternalResources1.ssp")
#END#

#CAPI#
.. code-block:: c
oms_status_enu_t oms_addResources(const char* cref_, const char* path)
#END#


#DESCRIPTION#
#END#
63 changes: 63 additions & 0 deletions doc/UsersGuide/source/api/deleteResources.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#CAPTION#
deleteResources
---------------

Deletes the reference and resource file in a SSP. Deletion of ".ssv" and ".ssm" files are currently supported. The API can be used in two ways.

1) deleting only the reference file in ".ssd".
2) deleting both reference and resource files in ".ssp".

To delete only the reference file in ssd, the user should provide the full qualified cref of the ".ssv" file associated with a system or subsystem or component (e.g) "model.root:root1.ssv".

To delete both the reference and resource file in ssp, it is enough to provide only the model cref of the ".ssv" file (e.g) "model:root1.ssv".

When deleting only the references of a ".ssv" file, if a parameter mapping file ".ssm" is binded to a ".ssv" file then the ".ssm" file will also be deleted.
It is not possible to delete the references of ".ssm" seperately as the ssm file is binded to a ssv file.

The filename of the reference or resource file is provided by the users using colon suffix at the end of cref. (e.g) ":root.ssv"

#END#

#LUA#
.. code-block:: lua
status = oms_deleteResources(cref)
-- Example
oms_importFile("deleteResources1.ssp")
-- delete only the references in ".ssd" file
oms_deleteResources("deleteResources.root:root.ssv")
-- delete both references and resources
oms_deleteResources("deleteResources:root.ssv")
oms_export("deleteResources1.ssp")
#END#

#PYTHON#
.. code-block:: python
status = oms.deleteResources(cref))
## Example
from OMSimulator import OMSimulator
oms = OMSimulator()
oms.importFile("deleteResources1.ssp")
## delete only the references in ".ssd" file
oms.deleteResources("deleteResources.root:root.ssv")
## delete both references and resources
oms.deleteResources("deleteResources:root.ssv")
oms.export("deleteResources1.ssp")
#END#

#CAPI#
.. code-block:: c
oms_status_enu_t oms_deleteResources(const char* cref);
#END#


#DESCRIPTION#
#END#
64 changes: 64 additions & 0 deletions doc/UsersGuide/source/api/newResources.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#CAPTION#
newResources
------------

Adds a new empty resources to the SSP. The resource file is a ".ssv" file where the parameter values set by the users using
"oms_setReal()", "oms_setInteger()" and "oms_setReal()" are writtern to the file. Currently only ".ssv" files can be created.

The filename of the resource file is provided by the users using colon suffix at the end of cref. (e.g) ":root.ssv"
#END#

#LUA#
.. code-block:: lua
status = oms_newResources(cref)
-- Example
oms_newModel("newResources")
oms_addSystem("newResources.root", oms_system_wc)
oms_addConnector("newResources.root.Input1", oms_causality_input, oms_signal_type_real)
oms_addConnector("newResources.root.Input2", oms_causality_input, oms_signal_type_real)
-- add Top level new resources, the filename is provided using the colon suffix ":root.ssv"
oms_newResources("newResources.root:root.ssv")
oms_setReal("newResources.root.Input1", 10)
-- export the ssp with new resources
oms_export("newResources", "newResources.ssp")
#END#

#PYTHON#
.. code-block:: python
status = oms.newResources(cref)
## Example
from OMSimulator import OMSimulator
oms = OMSimulator()
oms.newModel("newResources")
oms.addSystem("newResources.root", oms_system_wc)
oms.addConnector("newResources.root.Input1", oms.input, oms_signal_type_real)
oms.addConnector("newResources.root.Input2", oms.input, oms_signal_type_real)
## add Top level resources, the filename is provided using the colon suffix ":root.ssv"
oms.newResources("newResources.root:root.ssv")
oms.setReal("newResources.root.Input1", 10)
## export the ssp with new resources
oms.export("newResources", "newResources.ssp")
#END#

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


#DESCRIPTION#

#END#
67 changes: 67 additions & 0 deletions doc/UsersGuide/source/api/referenceResources.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#CAPTION#
referenceResources
------------------

Switches the references of ".ssv" and ".ssm" in a SSP file. Referencing of ".ssv" and ".ssm" files are currently supported. The API can be used in two ways.

1) Referencing only the ".ssv" file.
2) Referencing both the ".ssv" along with the ".ssm" file.

This API should be used in combination with "oms_deleteResources".To switch with a new reference, the old reference must be deleted first using "oms_deleteResources" and then reference with new resources.

When deleting only the references of a ".ssv" file, if a parameter mapping file ".ssm" is binded to a ".ssv" file, then the reference of ".ssm" file will also be deleted.
It is not possible to delete the references of ".ssm" seperately as the ssm file is binded to a ssv file. Hence it is not possible to switch the reference of ".ssm" file alone.
So inorder to switch the reference of ".ssm" file, the users need to bind the reference of ".ssm" file along with the ".ssv".

The filename of the reference or resource file is provided by the users using colon suffix at the end of cref (e.g) ":root.ssv",
and the ".ssm" file is optional and is provided by the user as the second argument to the API.


#END#

#LUA#
.. code-block:: lua
status = oms_referenceResources(cref, ssmFile)
-- Example
oms_importFile("referenceResources1.ssp")
-- delete only the references in ".ssd" file
oms_deleteResources("referenceResources1.root:root.ssv")
-- usage-1 switch with new references, only ssv file
oms_referenceResources("referenceResources1.root:Config1.ssv")
-- usage-2 switch with new references, both ssv and ssm file
oms_referenceResources("referenceResources1.root:Config1.ssv", "Config1.ssm")
oms_export("referenceResources1.ssp")
#END#

#PYTHON#
.. code-block:: python
status = oms.referenceResources(cref, ssmFile)
## Example
from OMSimulator import OMSimulator
oms = OMSimulator()
oms.importFile("referenceResources1.ssp")
## delete only the references in ".ssd" file
oms.deleteResources("referenceResources1.root:root.ssv")
## usage-1 switch with new references, only ssv file
oms.referenceResources("referenceResources1.root:Config1.ssv")
## usage-2 switch with new references, both ssv and ssm file
oms.referenceResources("referenceResources1.root:Config1.ssv", "Config1.ssm")
#END#

#CAPI#
.. code-block:: c
oms_status_enu_t oms_referenceResources(const char* cref, const char* ssmFile);
#END#


#DESCRIPTION#
#END#
5 changes: 4 additions & 1 deletion src/OMSimulatorLib/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ namespace oms
virtual oms_status_enu_t setReal(const ComRef& cref, double value) { return logError_NotImplemented; }
virtual oms_status_enu_t setRealInputDerivative(const ComRef& cref, const SignalDerivative& der) { return logError_NotImplemented; }
virtual oms_status_enu_t stepUntil(double stopTime) { return oms_status_ok; }
virtual oms_status_enu_t newResources(std::string& filename) { return logError_NotImplemented; }
virtual oms_status_enu_t newResources(const std::string& ssvFileName, const std::string& ssmFileName, bool externalResources) { return logError_NotImplemented; }
virtual oms_status_enu_t addResources(std::string& filename) { return logError_NotImplemented; }
virtual oms_status_enu_t deleteReferencesInSSD(const std::string& filename) {return logError_NotImplemented;}
virtual oms_status_enu_t deleteResourcesInSSP(const std::string& filename) {return logError_NotImplemented;}

const ComRef& getCref() const { return cref; }
ComRef getFullCref() const;
Expand Down
28 changes: 25 additions & 3 deletions src/OMSimulatorLib/ComponentFMUCS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,23 +684,45 @@ oms::ComRef oms::ComponentFMUCS::getValidCref(ComRef cref)
return tail;
}

oms_status_enu_t oms::ComponentFMUCS::newResources(std::string& filename)
oms_status_enu_t oms::ComponentFMUCS::newResources(const std::string& ssvFilename, const std::string& ssmFilename, bool externalResources)
{
Values resources;
if (!values.hasResources())
{
resources.allresources[filename] = resources;
resources.allresources["resources/" + ssvFilename] = resources;
resources.externalResources = externalResources; // set if resources is "external" or "newResources", if "external" only references will be set in ssd
if(!ssmFilename.empty())
resources.ssmFile = "resources/" + ssmFilename;
values.parameterResources.push_back(resources);
}
else
{
// generate empty ssv file, if more resources are added to same level
values.parameterResources[0].allresources[filename] = resources;
resources.externalResources = externalResources; // set if resources is "external" or "newResources", if "external" only references will be set in ssd
if(!ssmFilename.empty())
resources.ssmFile = "resources/" + ssmFilename;;
values.parameterResources[0].allresources["resources/" + ssvFilename] = resources;
}

return oms_status_ok;
}

oms_status_enu_t oms::ComponentFMUCS::deleteReferencesInSSD(const std::string& filename)
{
if (values.hasResources())
return values.deleteReferencesInSSD(filename);

return oms_status_error;
}

oms_status_enu_t oms::ComponentFMUCS::deleteResourcesInSSP(const std::string& filename)
{
if (values.hasResources())
return values.deleteResourcesInSSP(filename);

return oms_status_error;
}

oms_status_enu_t oms::ComponentFMUCS::initialize()
{
clock.reset();
Expand Down
5 changes: 4 additions & 1 deletion src/OMSimulatorLib/ComponentFMUCS.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,13 @@ namespace oms

void getFilteredSignals(std::vector<Connector>& filteredSignals) const;

oms_status_enu_t newResources(std::string& filename);
oms_status_enu_t newResources(const std::string& ssvFilename, const std::string& ssmFilename, bool externalResources);
oms_status_enu_t setResourcesHelper1(Values value);
oms_status_enu_t setResourcesHelper2(Values value);

oms_status_enu_t deleteReferencesInSSD(const std::string& filename);
oms_status_enu_t deleteResourcesInSSP(const std::string& filename);

protected:
ComponentFMUCS(const ComRef& cref, System* parentSystem, const std::string& fmuPath);

Expand Down
28 changes: 25 additions & 3 deletions src/OMSimulatorLib/ComponentFMUME.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,23 +710,45 @@ oms_status_enu_t oms::ComponentFMUME::doEventIteration()
return oms_status_ok;
}

oms_status_enu_t oms::ComponentFMUME::newResources(std::string& filename)
oms_status_enu_t oms::ComponentFMUME::newResources(const std::string& ssvFilename, const std::string& ssmFilename, bool externalResources)
{
Values resources;
if (!values.hasResources())
{
resources.allresources[filename] = resources;
resources.allresources["resources/" + ssvFilename] = resources;
resources.externalResources = externalResources; // set if resources is "external" or "newResources", if "external" only references will be set in ssd
if(!ssmFilename.empty())
resources.ssmFile = "resources/" + ssmFilename;
values.parameterResources.push_back(resources);
}
else
{
// generate empty ssv file, if more resources are added to same level
values.parameterResources[0].allresources[filename] = resources;
resources.externalResources = externalResources; // set if resources is "external" or "newResources", if "external" only references will be set in ssd
if(!ssmFilename.empty())
resources.ssmFile = "resources/" + ssmFilename;
values.parameterResources[0].allresources["resources/" + ssvFilename] = resources;
}

return oms_status_ok;
}

oms_status_enu_t oms::ComponentFMUME::deleteReferencesInSSD(const std::string& filename)
{
if (values.hasResources())
return values.deleteReferencesInSSD(filename);

return oms_status_error;
}

oms_status_enu_t oms::ComponentFMUME::deleteResourcesInSSP(const std::string& filename)
{
if (values.hasResources())
return values.deleteResourcesInSSP(filename);

return oms_status_error;
}

oms_status_enu_t oms::ComponentFMUME::initialize()
{
clock.reset();
Expand Down
5 changes: 4 additions & 1 deletion src/OMSimulatorLib/ComponentFMUME.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,13 @@ namespace oms

void getFilteredSignals(std::vector<Connector>& filteredSignals) const;

oms_status_enu_t newResources(std::string& filename);
oms_status_enu_t newResources(const std::string& ssvFilename, const std::string& ssmFilename, bool externalResources);
oms_status_enu_t setResourcesHelper1(Values value);
oms_status_enu_t setResourcesHelper2(Values value);

oms_status_enu_t deleteReferencesInSSD(const std::string& filename);
oms_status_enu_t deleteResourcesInSSP(const std::string& filename);

protected:
ComponentFMUME(const ComRef& cref, System* parentSystem, const std::string& fmuPath);

Expand Down
Loading

0 comments on commit c5c0169

Please sign in to comment.