Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify ssv related code in class Model #948

Merged
merged 4 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/OMSimulatorLib/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace oms
Connector* getConnector(const ComRef& cref);
Connector** getConnectors() {return &connectors[0];}
oms_status_enu_t deleteConnector(const ComRef& cref);
oms_status_enu_t getAllResources(std::vector<std::string>& resources) const {resources.push_back(path); return oms_status_ok;}
void getAllResources(std::vector<std::string>& resources) const {resources.push_back(path);}
const std::string& getPath() const {return path;}
const std::string& getTempDir() const {return tempDir;}
void setTempDir(const std::string& tempDir) {this->tempDir = tempDir;}
Expand Down
18 changes: 8 additions & 10 deletions src/OMSimulatorLib/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,10 +795,14 @@ oms_status_enu_t oms::Model::exportToFile(const std::string& filename) const
int parameterNodeCount = std::distance(node_parameters.begin(), node_parameters.end());
std::string ssvFileName = "";

std::vector<std::string> resources;

// check parameter bindings exist and export to ssv file and also update the ssd file with parameterBindings at the top level
if (parameterNodeCount > 0)
{
ssvFileName = "resources/" + std::string(this->getCref()) + ".ssv";
resources.push_back(ssvFileName);

filesystem::path ssvPath = filesystem::path(tempDir) / ssvFileName;
//std::cout << "\n ssvPath : " << ssvPath << " filename : " << ssvFileName;
ssvdoc.save_file(ssvPath.string().c_str());
Expand Down Expand Up @@ -830,13 +834,7 @@ oms_status_enu_t oms::Model::exportToFile(const std::string& filename) const
// -9 Compress better
// -j exclude path. store only the file name

std::vector<std::string> resources;
if (!ssvFileName.empty())
{
resources.push_back(ssvFileName);
}
if (oms_status_ok != getAllResources(resources))
return logError("failed to gather all resources");
getAllResources(resources);

std::string cd = Scope::GetInstance().getWorkingDirectory();
Scope::GetInstance().setWorkingDirectory(tempDir);
Expand All @@ -859,12 +857,12 @@ oms_status_enu_t oms::Model::exportToFile(const std::string& filename) const
return oms_status_ok;
}

oms_status_enu_t oms::Model::getAllResources(std::vector<std::string>& resources) const
void oms::Model::getAllResources(std::vector<std::string>& resources) const
{
resources.push_back("SystemStructure.ssd");

if (system)
return system->getAllResources(resources);
return oms_status_ok;
system->getAllResources(resources);
}

oms_status_enu_t oms::Model::setStartTime(double value)
Expand Down
2 changes: 1 addition & 1 deletion src/OMSimulatorLib/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace oms
bool copyResources() {return copy_resources;}

oms::Element** getElements() {return &elements[0];}
oms_status_enu_t getAllResources(std::vector<std::string>& resources) const;
void getAllResources(std::vector<std::string>& resources) const;

oms_status_enu_t instantiate();
oms_status_enu_t initialize();
Expand Down
19 changes: 9 additions & 10 deletions src/OMSimulatorLib/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,9 @@ oms_status_enu_t oms::System::importFromSSD(const pugi::xml_node& node, const st
else if(name == oms::ssp::Version1_0::ssd::parameter_bindings)
{
std::string parent_node = it->parent().parent().name();
// top level parameter bindings belonging to <ssd:SystemStructureDescription> provided either as inline or .ssv files
// top-level parameter bindings belonging to
// <ssd:SystemStructureDescription> provided either as inline or
// .ssv files
if (parent_node == oms::ssp::Draft20180219::ssd::system_structure_description)
{
// check for multiple ssv files or parameter bindings
Expand Down Expand Up @@ -557,9 +559,10 @@ oms_status_enu_t oms::System::importFromSSD(const pugi::xml_node& node, const st
}
}
else
// heirarchial level parameter bindings belonging to <ssd:Elements> provided either as inline or .ssv files
// hierarchical level parameter bindings belonging to
// <ssd:Elements> provided either as inline or .csv files
{
if (oms_status_ok != values.importFromSSD(*it, sspVersion, getModel()->getTempDirectory()))
if (oms_status_ok != values.importFromSSD(*it, sspVersion, getModel()->getTempDirectory()))
return logError("Failed to import " + std::string(oms::ssp::Version1_0::ssd::parameter_bindings));
}
}
Expand Down Expand Up @@ -1687,17 +1690,13 @@ bool oms::System::copyResources()
return parentModel->copyResources();
}

oms_status_enu_t oms::System::getAllResources(std::vector<std::string>& resources)
void oms::System::getAllResources(std::vector<std::string>& resources) const
{
for (const auto& component : components)
if (oms_status_ok != component.second->getAllResources(resources))
return oms_status_error;
component.second->getAllResources(resources);

for (const auto& subsystem : subsystems)
if (oms_status_ok != subsystem.second->getAllResources(resources))
return oms_status_error;

return oms_status_ok;
subsystem.second->getAllResources(resources);
}

oms_status_enu_t oms::System::exportDependencyGraphs(const std::string& pathInitialization, const std::string& pathEvent, const std::string& pathSimulation)
Expand Down
2 changes: 1 addition & 1 deletion src/OMSimulatorLib/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace oms
Model* getModel();
System* getParentSystem() const {return parentSystem;}
bool copyResources();
oms_status_enu_t getAllResources(std::vector<std::string>& resources);
void getAllResources(std::vector<std::string>& resources) const;
std::map<ComRef, System*>& getSubSystems() {return subsystems;}
std::map<ComRef, Component*>& getComponents() {return components;}
std::vector<Connection*>& getConnections() {return connections;}
Expand Down
9 changes: 6 additions & 3 deletions src/OMSimulatorLib/Values.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,21 @@ oms_status_enu_t oms::Values::importFromSSD(const pugi::xml_node& node, const st
return oms_status_ok;
}

bool oms::Values::empty() const
{
return realStartValues.empty() && integerStartValues.empty() && booleanStartValues.empty();
}

oms_status_enu_t oms::Values::exportToSSV(pugi::xml_node& node) const
{
// skip this if there is nothing to export
if (realStartValues.empty() && integerStartValues.empty() && booleanStartValues.empty())
if (this->empty())
return oms_status_ok;

exportStartValuesHelper(node);

return oms_status_ok;
}


oms_status_enu_t oms::Values::exportStartValuesHelper(pugi::xml_node& node) const
{
// realStartValues
Expand Down
10 changes: 7 additions & 3 deletions src/OMSimulatorLib/Values.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,15 @@ namespace oms
oms_status_enu_t exportToSSV(pugi::xml_node& ssvNode) const;
oms_status_enu_t exportToSSVTemplate(pugi::xml_node& ssvNode, const ComRef& cref); ///< start values read from modelDescription.xml and creates a ssv template
oms_status_enu_t exportToSSMTemplate(pugi::xml_node& ssmNode, const ComRef& cref); ///< start values read from modelDescription.xml and creates a ssm template

oms_status_enu_t exportStartValuesHelper(pugi::xml_node& node) const;
oms_status_enu_t exportParameterMappingInline(pugi::xml_node& node) const;
oms_status_enu_t importStartValuesHelper(pugi::xml_node& parameters);
oms_status_enu_t importParameterMapping(pugi::xml_node& parameterMapping);
oms_status_enu_t parseModelDescription(const char *filename);

bool empty() const;

oms::ComRef getMappedCrefEntry(ComRef cref) const;

std::map<ComRef, double> realStartValues; ///< parameters and start values defined before instantiating the FMU
Expand All @@ -70,14 +73,15 @@ namespace oms

std::map<ComRef, double> realValues; ///< real input values defined after initialization
std::map<ComRef, int> integerValues; ///< integer input values defined after initialization
std::map<ComRef, bool> booleanValues; ///< boolean input values defined after initialization
std::map<ComRef, bool> booleanValues; ///< boolean input values defined after initialization

std::map<ComRef, double> modelDescriptionRealStartValues; ///< real start values read from modelDescription.xml
std::map<ComRef, int> modelDescriptionIntegerStartValues; ///< integer start values read from modelDescription.xml
std::map<ComRef, double> modelDescriptionRealStartValues; ///< real start values read from modelDescription.xml
std::map<ComRef, int> modelDescriptionIntegerStartValues; ///< integer start values read from modelDescription.xml
std::map<ComRef, bool> modelDescriptionBooleanStartValues; ///< boolean start values read from modelDescription.xml

std::multimap<ComRef, ComRef> mappedEntry; ///< parameter names and values provided in the parameter source are to be mapped to the parameters of the component or system

std::string path;
};
}

Expand Down