|
27 | 27 | #include <unordered_map> |
28 | 28 | #include <utility> |
29 | 29 | #include <vector> |
| 30 | +#include <iostream> |
| 31 | +#include <optional> |
30 | 32 |
|
31 | 33 |
|
32 | 34 | namespace cosim |
@@ -119,6 +121,7 @@ class osp_config_parser |
119 | 121 | std::string description; |
120 | 122 | double stepSize = 0.1; |
121 | 123 | double startTime = 0.0; |
| 124 | + std::optional<double> endTime; |
122 | 125 | }; |
123 | 126 |
|
124 | 127 | const SimulationInformation& get_simulation_information() const; |
@@ -431,6 +434,11 @@ osp_config_parser::osp_config_parser( |
431 | 434 | simulationInformation_.startTime = boost::lexical_cast<double>(tc(stNodes->item(0)->getTextContent()).get()); |
432 | 435 | } |
433 | 436 |
|
| 437 | + auto etNodes = rootElement->getElementsByTagName(tc("EndTime").get()); |
| 438 | + if (etNodes->getLength() > 0) { |
| 439 | + simulationInformation_.endTime = boost::lexical_cast<double>(tc(etNodes->item(0)->getTextContent()).get()); |
| 440 | + } |
| 441 | + |
434 | 442 | auto connectionsElement = static_cast<xercesc::DOMElement*>(rootElement->getElementsByTagName(tc("Connections").get())->item(0)); |
435 | 443 | if (connectionsElement) { |
436 | 444 | auto variableConnectionsElement = connectionsElement->getElementsByTagName(tc("VariableConnection").get()); |
@@ -914,21 +922,31 @@ osp_config load_osp_config( |
914 | 922 | const auto configFile = cosim::filesystem::is_regular_file(absolutePath) |
915 | 923 | ? absolutePath |
916 | 924 | : absolutePath / "OspSystemStructure.xml"; |
917 | | - const auto baseURI = path_to_file_uri(configFile); |
918 | 925 |
|
| 926 | + const auto baseURI = path_to_file_uri(configFile); |
919 | 927 | const auto parser = osp_config_parser(configFile); |
920 | | - |
921 | 928 | const auto& simInfo = parser.get_simulation_information(); |
| 929 | + |
922 | 930 | if (simInfo.stepSize <= 0.0) { |
923 | 931 | std::ostringstream oss; |
924 | 932 | oss << "Configured base step size [" << simInfo.stepSize << "] must be nonzero and positive"; |
925 | 933 | BOOST_LOG_SEV(log::logger(), log::error) << oss.str(); |
926 | 934 | throw std::invalid_argument(oss.str()); |
927 | 935 | } |
928 | 936 |
|
| 937 | + if (simInfo.endTime.has_value() && simInfo.startTime > simInfo.endTime.value()) { |
| 938 | + std::ostringstream oss; |
| 939 | + oss << "Configured start time [" << simInfo.startTime << "] is larger than configured end time [" << simInfo.endTime.value() << "]"; |
| 940 | + BOOST_LOG_SEV(log::logger(), log::error) << oss.str(); |
| 941 | + throw std::invalid_argument(oss.str()); |
| 942 | + } |
| 943 | + |
929 | 944 | osp_config config; |
930 | 945 | config.start_time = to_time_point(simInfo.startTime); |
931 | 946 | config.step_size = to_duration(simInfo.stepSize); |
| 947 | + if (simInfo.endTime.has_value()) { |
| 948 | + config.end_time = to_time_point(simInfo.endTime.value()); |
| 949 | + } |
932 | 950 |
|
933 | 951 | auto simulators = parser.get_elements(); |
934 | 952 |
|
|
0 commit comments