diff --git a/developer/doc/ReleaseNotes/OpenStudio_Release_Notes_3_7_0_TDB.md b/developer/doc/ReleaseNotes/OpenStudio_Release_Notes_3_7_0_TDB.md index 3b1265716d..0d145e891d 100644 --- a/developer/doc/ReleaseNotes/OpenStudio_Release_Notes_3_7_0_TDB.md +++ b/developer/doc/ReleaseNotes/OpenStudio_Release_Notes_3_7_0_TDB.md @@ -81,6 +81,7 @@ You can also refer to the [OpenStudio SDK Python Binding Version Compatibility M * [#4932](https://github.com/NREL/OpenStudio/pull/4932) - Support undisturbed ground temperature models on GroundHeatExchangerVertical * Fix #4930 - Support undisturbed ground temperature models on GroundHeatExchangerVertical * Update `GroundHeatExchanger:Vertical` to actually use the Ground Temeprature Model field +* [#4923](https://github.com/NREL/OpenStudio/pull/4923) - Fix #4692 - Modify `Model::load` to use the VersionTranslator instead of loading it assuming the version of the loaded OSM is the same as the current SDK version being used. ## Minor changes and bug fixes diff --git a/resources/CMakeLists.txt b/resources/CMakeLists.txt index 9c47de51d5..d97a7620cd 100644 --- a/resources/CMakeLists.txt +++ b/resources/CMakeLists.txt @@ -175,6 +175,8 @@ set(model_resources_src model/ASHRAECourthouse.osm model/A205ExampleChiller.RS0001.a205.cbor model/4837_SpaceVolume.osm + model/empty361.osm + model/empty361/workflow.osw ) diff --git a/resources/model/empty361.osm b/resources/model/empty361.osm new file mode 100644 index 0000000000..9e538acfe7 --- /dev/null +++ b/resources/model/empty361.osm @@ -0,0 +1,5 @@ + +OS:Version, + {e2190a61-e3f3-4d4b-8c0b-7a9c2342180e}, !- Handle + 3.6.1; !- Version Identifier + diff --git a/resources/model/empty361/workflow.osw b/resources/model/empty361/workflow.osw new file mode 100644 index 0000000000..147ae7382b --- /dev/null +++ b/resources/model/empty361/workflow.osw @@ -0,0 +1,6 @@ +{ + "created_at" : "20230704T152451Z", + "seed_file" : "../empty361.osm", + "steps" : [], + "updated_at" : "20230704T152548Z" +} \ No newline at end of file diff --git a/src/model/Model.cpp b/src/model/Model.cpp index 06dbe153e2..18caded3bf 100644 --- a/src/model/Model.cpp +++ b/src/model/Model.cpp @@ -21,8 +21,11 @@ #include #include +#include "../osversion/VersionTranslator.hpp" + #include "../utilities/core/Assert.hpp" #include "../utilities/core/ContainersMove.hpp" +#include "../utilities/core/Filesystem.hpp" #include "../utilities/core/PathHelpers.hpp" #include "../utilities/idd/IddEnums.hpp" @@ -1840,27 +1843,26 @@ namespace model { } boost::optional Model::load(const path& osmPath) { - OptionalModel result; - OptionalIdfFile oIdfFile = IdfFile::load(osmPath, IddFileType::OpenStudio); - if (oIdfFile) { - try { - result = Model(*oIdfFile); - } catch (...) { - } - } - if (result) { - // Load the workflow.osw in the model's companion folder - path workflowJSONPath = getCompanionFolder(osmPath) / toPath("workflow.osw"); - if (exists(workflowJSONPath)) { - boost::optional workflowJSON = WorkflowJSON::load(workflowJSONPath); - if (workflowJSON) { - result->setWorkflowJSON(*workflowJSON); - } + if (!openstudio::filesystem::is_regular_file(osmPath)) { + LOG(Warn, "Path is not a valid file: " << osmPath); + return boost::none; + } + openstudio::osversion::VersionTranslator vt; + boost::optional model_ = vt.loadModel(osmPath); + if (!model_) { + LOG(Warn, "Failed to load model at " << osmPath); + return boost::none; + } + // Load the workflow.osw in the model's companion folder + const openstudio::path workflowJSONPath = getCompanionFolder(osmPath) / toPath("workflow.osw"); + if (exists(workflowJSONPath)) { + if (boost::optional workflowJSON_ = WorkflowJSON::load(workflowJSONPath)) { + model_->setWorkflowJSON(*workflowJSON_); } } - return result; + return model_; } boost::optional Model::load(const path& osmPath, const path& workflowJSONPath) { diff --git a/src/model/test/Model_GTest.cpp b/src/model/test/Model_GTest.cpp index 8ad9498582..b000740e61 100644 --- a/src/model/test/Model_GTest.cpp +++ b/src/model/test/Model_GTest.cpp @@ -129,16 +129,18 @@ #include "../ExternalInterface.hpp" #include "../ExternalInterface_Impl.hpp" -#include "../../utilities/sql/SqlFile.hpp" +#include "../../utilities/core/PathHelpers.hpp" #include "../../utilities/data/TimeSeries.hpp" #include "../../utilities/idf/IdfFile.hpp" #include "../../utilities/idf/Workspace.hpp" #include "../../utilities/idf/WorkspaceObject.hpp" #include "../../utilities/idf/ValidityReport.hpp" +#include "../../utilities/sql/SqlFile.hpp" #include "../../osversion/VersionTranslator.hpp" #include +#include #include @@ -1160,3 +1162,28 @@ TEST_F(ModelFixture, UniqueModelObjectCachedGetters) { EXPECT_TRUE(m.getOptionalUniqueModelObject()); EXPECT_EQ(++i, m.getModelObjects().size()); } + +TEST_F(ModelFixture, Model_load) { + + openstudio::path modelPath = resourcesPath() / "model" / toPath("empty361.osm"); + ASSERT_TRUE(openstudio::filesystem::exists(modelPath)); + + const openstudio::path workflowJSONPath = getCompanionFolder(modelPath) / toPath("workflow.osw"); + ASSERT_TRUE(openstudio::filesystem::exists(workflowJSONPath)); + + // Check that the versionObject is indeed translated to the current version + boost::optional model_ = Model::load(modelPath); + ASSERT_TRUE(model_); + auto versionObject_ = model_->versionObject(); + ASSERT_TRUE(versionObject_); + EXPECT_EQ(openStudioVersion(), versionObject_->getString(1).get()); + + // Check that the workflowJSON in the companion folder is correctly loaded + auto workflowJSON = model_->workflowJSON(); + auto p_ = workflowJSON.oswPath(); + ASSERT_TRUE(p_); + EXPECT_EQ(workflowJSONPath, *p_); + + ASSERT_TRUE(workflowJSON.seedFile()); + EXPECT_EQ(workflowJSON.seedFile().get(), openstudio::toPath("../empty361.osm")); +}