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

Added health check for connections from SSP #374

Merged
merged 2 commits into from
Sep 17, 2019
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/cpp/algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class fixed_step_algorithm::impl
auto sim = simulators_.find(i);
if (sim == simulators_.end()) {
std::ostringstream oss;
oss << "Cannot find simulator with reference " << i;
oss << "Cannot find simulator with index " << i;
throw std::out_of_range(oss.str());
}
return sim->second;
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@ class execution::impl
[=](const auto& var) { return var.causality == causality && var.type == variable.type && var.reference == variable.reference; });
if (it == variables.end()) {
std::ostringstream oss;
oss << "Cannot find variable with reference " << variable.reference
oss << "Problem adding connection: Cannot find variable with reference " << variable.reference
<< ", causality " << cse::to_text(causality)
<< " and type " << cse::to_text(variable.type)
<< " for simulator with reference " << variable.simulator
<< " for simulator with index " << variable.simulator
<< " and name " << simulators_.at(variable.simulator)->name();
throw std::out_of_range(oss.str());
}
Expand Down
45 changes: 37 additions & 8 deletions src/cpp/ssp_parser.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "cse/ssp_parser.hpp"

#include "cse/algorithm.hpp"
#include "cse/error.hpp"
#include "cse/exception.hpp"
#include "cse/fmi/fmu.hpp"
#include "cse/log/logger.hpp"
#include "cse/error.hpp"

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
Expand Down Expand Up @@ -252,6 +252,28 @@ std::ostream& operator<<(std::ostream& os, streamer<std::variant<Ts...>> sv)
return os;
}

cse::variable_id get_variable(
const std::map<std::string, slave_info>& slaves,
const std::string& element,
const std::string& connector)
{
auto slaveIt = slaves.find(element);
if (slaveIt == slaves.end()) {
std::ostringstream oss;
oss << "Cannot find slave: " << element;
throw std::out_of_range(oss.str());
}
auto slave = slaveIt->second;
auto vdIt = slave.variables.find(connector);
if (vdIt == slave.variables.end()) {
std::ostringstream oss;
oss << "Cannot find variable: " << element << ":" << connector;
throw std::out_of_range(oss.str());
}
auto variable = vdIt->second;
return {slave.index, variable.type, variable.reference};
}

} // namespace


Expand Down Expand Up @@ -312,16 +334,23 @@ std::pair<execution, simulator_map> load_ssp(
}

for (const auto& connection : parser.get_connections()) {
cse::variable_id output = {slaves[connection.startElement].index,
slaves[connection.startElement].variables[connection.startConnector].type,
slaves[connection.startElement].variables[connection.startConnector].reference};

cse::variable_id input = {slaves[connection.endElement].index,
slaves[connection.endElement].variables[connection.endConnector].type,
slaves[connection.endElement].variables[connection.endConnector].reference};
cse::variable_id output = get_variable(slaves, connection.startElement, connection.startConnector);
cse::variable_id input = get_variable(slaves, connection.endElement, connection.endConnector);

const auto c = std::make_shared<scalar_connection>(output, input);
execution.add_connection(c);
try {
execution.add_connection(c);
} catch (const std::exception& e) {
std::ostringstream oss;
oss << "Encountered error while adding connection from "
<< connection.startElement << ":" << connection.startConnector << " to "
<< connection.endElement << ":" << connection.endConnector
<< ": " << e.what();

BOOST_LOG_SEV(log::logger(), log::error) << oss.str();
throw std::runtime_error(oss.str());
}
}

return std::make_pair(std::move(execution), std::move(simulatorMap));
Expand Down