diff --git a/src/cpp/algorithm.cpp b/src/cpp/algorithm.cpp index cf7b01330..8d5190374 100644 --- a/src/cpp/algorithm.cpp +++ b/src/cpp/algorithm.cpp @@ -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; diff --git a/src/cpp/execution.cpp b/src/cpp/execution.cpp index f00d4edc1..e0b08b25e 100644 --- a/src/cpp/execution.cpp +++ b/src/cpp/execution.cpp @@ -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()); } diff --git a/src/cpp/ssp_parser.cpp b/src/cpp/ssp_parser.cpp index f479a24a6..98fa41def 100644 --- a/src/cpp/ssp_parser.cpp +++ b/src/cpp/ssp_parser.cpp @@ -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 #include @@ -252,6 +252,28 @@ std::ostream& operator<<(std::ostream& os, streamer> sv) return os; } +cse::variable_id get_variable( + const std::map& 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 @@ -312,16 +334,23 @@ std::pair 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(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));