|
23 | 23 | #include <xercesc/util/XMLString.hpp>
|
24 | 24 | #include <xercesc/util/XMLUni.hpp>
|
25 | 25 |
|
| 26 | +#include <algorithm> |
26 | 27 | #include <ios>
|
27 | 28 | #include <iostream>
|
28 | 29 | #include <memory>
|
@@ -804,12 +805,14 @@ constexpr uint64_t operator"" _hash(const char* str, size_t len)
|
804 | 805 |
|
805 | 806 | void add_power_bonds(const std::vector<osp_config_parser::PowerBondConnection>& pbConnections, system_structure& systemStructure)
|
806 | 807 | {
|
807 |
| - std::set<std::string> powerbondNames; |
| 808 | + std::vector<std::string> powerBondNames; |
| 809 | + std::set<std::string> uniquePowerBondNames; |
808 | 810 | for (const auto& pbConnection : pbConnections) {
|
809 |
| - powerbondNames.insert(pbConnection.name); |
| 811 | + powerBondNames.emplace_back(pbConnection.name); |
| 812 | + uniquePowerBondNames.insert(pbConnection.name); |
810 | 813 | }
|
811 | 814 |
|
812 |
| - for (const auto& pbName : powerbondNames) { |
| 815 | + for (const auto& pbName : uniquePowerBondNames) { |
813 | 816 | std::vector<osp_config_parser::PowerBondConnection> aPowerBond;
|
814 | 817 | std::copy_if(pbConnections.begin(), pbConnections.end(), std::back_inserter(aPowerBond), [pbName](osp_config_parser::PowerBondConnection conn) {
|
815 | 818 | return pbName == conn.name;
|
@@ -888,6 +891,17 @@ void add_power_bonds(const std::vector<osp_config_parser::PowerBondConnection>&
|
888 | 891 | }
|
889 | 892 |
|
890 | 893 | systemStructure.add_power_bond(pbName, powerbond);
|
| 894 | + |
| 895 | + // Check that the number of unique power bond names is equal to the number of power bonds. Otherwise, it is not possible to correctly connect the bonds. |
| 896 | + std::sort(powerBondNames.begin(), powerBondNames.end()); |
| 897 | + auto uniqueCount = static_cast<int>(std::unique(powerBondNames.begin(), powerBondNames.end()) - powerBondNames.begin()); |
| 898 | + auto numPowerBonds = static_cast<int>(systemStructure.get_power_bonds().size()); |
| 899 | + |
| 900 | + if (uniqueCount != systemStructure.get_power_bonds().size()) { |
| 901 | + std::ostringstream oss; |
| 902 | + oss << "The number of powerbonds (" << numPowerBonds << ") is not equal to the number of unique power bond names (" << uniqueCount << ") found in the configured system. Power bond names must be unique pr. bond, that is found on only and exactly the two VariableConnections that form the bond."; |
| 903 | + throw std::runtime_error(oss.str()); |
| 904 | + } |
891 | 905 | }
|
892 | 906 | }
|
893 | 907 |
|
|
0 commit comments