Skip to content

Commit

Permalink
#336 Added health check for connections from SSP
Browse files Browse the repository at this point in the history
  • Loading branch information
eidekrist committed Sep 16, 2019
1 parent 98a3fe2 commit 5592700
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
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
40 changes: 32 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,25 @@ std::ostream& operator<<(std::ostream& os, streamer<std::variant<Ts...>> sv)
return os;
}

cse::variable_id find_variable(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 << "Problem adding connection: 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 << "Problem adding connection: 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 +331,21 @@ 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 = find_variable(slaves, connection.startElement, connection.startConnector);
cse::variable_id input = find_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) {
BOOST_LOG_SEV(log::logger(), log::error)
<< "Encountered error while adding connection from "
<< connection.startElement << ":" << connection.startConnector << " to "
<< connection.endElement << ":" << connection.endConnector
<< ": " << e.what();
throw;
}
}

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

0 comments on commit 5592700

Please sign in to comment.