From 659cd674696b663979e7be5bff5e9207b9e5c3ca Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Mon, 13 Nov 2023 21:32:40 +0100 Subject: [PATCH] Implement skip zip results in RunOptions. It's part of the osw schema and use in openstuido-workflow-gem --- src/utilities/filetypes/RunOptions.cpp | 49 +++++++++++++++++++ src/utilities/filetypes/RunOptions.hpp | 14 ++++++ src/utilities/filetypes/RunOptions_Impl.hpp | 9 ++++ .../filetypes/test/WorkflowJSON_GTest.cpp | 17 +++++++ 4 files changed, 89 insertions(+) diff --git a/src/utilities/filetypes/RunOptions.cpp b/src/utilities/filetypes/RunOptions.cpp index 9c1aabb7cce..affdfcfd006 100644 --- a/src/utilities/filetypes/RunOptions.cpp +++ b/src/utilities/filetypes/RunOptions.cpp @@ -50,6 +50,10 @@ namespace detail { root["skip_energyplus_preprocess"] = m_skipEnergyPlusPreprocess; } + if (!m_is_skipZipResults_defaulted) { + root["skip_zip_results"] = m_skipZipResults; + } + if (!m_is_cleanup_defaulted) { root["cleanup"] = m_cleanup; } @@ -200,6 +204,27 @@ namespace detail { onUpdate(); } + bool RunOptions_Impl::skipZipResults() const { + return m_skipZipResults; + } + + bool RunOptions_Impl::isSkipZipResultsDefaulted() const { + return m_is_skipZipResults_defaulted; + } + + bool RunOptions_Impl::setSkipZipResults(bool skipZipResults) { + m_skipZipResults = skipZipResults; + m_is_skipZipResults_defaulted = false; + onUpdate(); + return true; + } + + void RunOptions_Impl::resetSkipZipResults() { + m_skipZipResults = DEFAULT_SKIPZIPRESULTS; + m_is_skipZipResults_defaulted = true; + onUpdate(); + } + bool RunOptions_Impl::cleanup() const { return m_cleanup; } @@ -277,6 +302,10 @@ namespace detail { setSkipEnergyPlusPreprocess(other.skipEnergyPlusPreprocess()); } + if (!other.isSkipZipResultsDefaulted()) { + setSkipZipResults(other.skipZipResults()); + } + if (!other.isCleanupDefaulted()) { setCleanup(other.cleanup()); } @@ -382,6 +411,10 @@ boost::optional RunOptions::fromString(const std::string& s) { result.setSkipEnergyPlusPreprocess(value["skip_energyplus_preprocess"].asBool()); } + if (value.isMember("skip_zip_results") && value["skip_zip_results"].isBool()) { + result.setSkipZipResults(value["skip_zip_results"].asBool()); + } + if (value.isMember("output_adapter")) { Json::Value outputAdapter = value["output_adapter"]; if (outputAdapter.isMember("custom_file_name") && outputAdapter.isMember("class_name")) { @@ -504,6 +537,22 @@ void RunOptions::resetSkipEnergyPlusPreprocess() { getImpl()->resetSkipEnergyPlusPreprocess(); } +bool RunOptions::skipZipResults() const { + return getImpl()->skipZipResults(); +} + +bool RunOptions::isSkipZipResultsDefaulted() const { + return getImpl()->isSkipZipResultsDefaulted(); +} + +bool RunOptions::setSkipZipResults(bool skipZipResults) { + return getImpl()->setSkipZipResults(skipZipResults); +} + +void RunOptions::resetSkipZipResults() { + getImpl()->resetSkipZipResults(); +} + bool RunOptions::cleanup() const { return getImpl()->cleanup(); } diff --git a/src/utilities/filetypes/RunOptions.hpp b/src/utilities/filetypes/RunOptions.hpp index 83623e97af4..1705c5627fe 100644 --- a/src/utilities/filetypes/RunOptions.hpp +++ b/src/utilities/filetypes/RunOptions.hpp @@ -62,16 +62,19 @@ class UTILITIES_API RunOptions /// Serialize to JSON formatted string std::string string() const; + /** Print debugging messages, defaults to false */ bool debug() const; bool isDebugDefaulted() const; bool setDebug(bool debug); void resetDebug(); + /** Create, export and run using epjson format. Default is false */ bool epjson() const; bool isEpjsonDefaulted() const; bool setEpjson(bool epjson); void resetEpjson(); + /** Speeds up workflow by skipping steps not needed for running simulations, defaults to false */ bool fast() const; bool isFastDefaulted() const; bool setFast(bool fast); @@ -82,16 +85,27 @@ class UTILITIES_API RunOptions bool setPreserveRunDir(bool preserveRunDir); void resetPreserveRunDir(); + /** Skips the call to the EnergyPlus ExpandObjects program, defaults to false */ bool skipExpandObjects() const; bool isSkipExpandObjectsDefaulted() const; bool setSkipExpandObjects(bool skipExpandObjects); void resetSkipExpandObjects(); + /** Does not add add default output requests to EnergyPlus input if true. + * Requests from reporting measures are added in either case, defaults to false */ bool skipEnergyPlusPreprocess() const; bool isSkipEnergyPlusPreprocessDefaulted() const; bool setSkipEnergyPlusPreprocess(bool skipEnergyPlusPreprocess); void resetSkipEnergyPlusPreprocess(); + /** Skips creating the data_point.zip file. Setting to `true` can cause issues with workflows expecting .zip files to signal completion + * (e.g., OpenStudio Analysis Framework), defaults to false */ + bool skipZipResults() const; + bool isSkipZipResultsDefaulted() const; + bool setSkipZipResults(bool skipZipResults); + void resetSkipZipResults(); + + /** Remove unnecessary files during post processing, defaults to true */ bool cleanup() const; bool isCleanupDefaulted() const; bool setCleanup(bool cleanup); diff --git a/src/utilities/filetypes/RunOptions_Impl.hpp b/src/utilities/filetypes/RunOptions_Impl.hpp index db961e45999..9c97d07cf7e 100644 --- a/src/utilities/filetypes/RunOptions_Impl.hpp +++ b/src/utilities/filetypes/RunOptions_Impl.hpp @@ -66,6 +66,11 @@ namespace detail { bool setCleanup(bool cleanup); void resetCleanup(); + bool skipZipResults() const; + bool isSkipZipResultsDefaulted() const; + bool setSkipZipResults(bool skipZipResults); + void resetSkipZipResults(); + boost::optional customOutputAdapter() const; bool setCustomOutputAdapter(const CustomOutputAdapter& adapter); void resetCustomOutputAdapter(); @@ -94,6 +99,7 @@ namespace detail { static constexpr bool DEFAULT_SKIPEXPANDOBJECTS = false; static constexpr bool DEFAULT_SKIPENERGYPLUSPREPROCESS = false; static constexpr bool DEFAULT_CLEANUP = true; + static constexpr bool DEFAULT_SKIPZIPRESULTS = false; bool m_debug = DEFAULT_DEBUG; bool m_is_debug_defaulted = true; @@ -117,6 +123,9 @@ namespace detail { bool m_cleanup = DEFAULT_CLEANUP; bool m_is_cleanup_defaulted = true; + bool m_skipZipResults = DEFAULT_SKIPZIPRESULTS; + bool m_is_skipZipResults_defaulted = true; + ForwardTranslatorOptions m_forwardTranslatorOptions; boost::optional m_customOutputAdapter; }; diff --git a/src/utilities/filetypes/test/WorkflowJSON_GTest.cpp b/src/utilities/filetypes/test/WorkflowJSON_GTest.cpp index 5028f4bd578..d88b5b8247a 100644 --- a/src/utilities/filetypes/test/WorkflowJSON_GTest.cpp +++ b/src/utilities/filetypes/test/WorkflowJSON_GTest.cpp @@ -1236,6 +1236,19 @@ TEST(Filetypes, RunOptions_GettersSetters) { ASSERT_TRUE(runOptions.isSkipEnergyPlusPreprocessDefaulted()); ASSERT_TRUE(runOptions.isSkipEnergyPlusPreprocessDefaulted()); + // Ctor Default + ASSERT_FALSE(runOptions.skipZipResults()); + ASSERT_TRUE(runOptions.isSkipZipResultsDefaulted()); + // Set to opposite of default + ASSERT_TRUE(runOptions.setSkipZipResults(true)); + ASSERT_TRUE(runOptions.skipZipResults()); + ASSERT_FALSE(runOptions.isSkipZipResultsDefaulted()); + // Reset + runOptions.resetSkipZipResults(); + ASSERT_FALSE(runOptions.skipZipResults()); + ASSERT_TRUE(runOptions.isSkipZipResultsDefaulted()); + ASSERT_TRUE(runOptions.isSkipZipResultsDefaulted()); + // Ctor Default ASSERT_TRUE(runOptions.cleanup()); ASSERT_TRUE(runOptions.isCleanupDefaulted()); @@ -1362,6 +1375,8 @@ TEST(Filetypes, RunOptions_overrideValuesWith) { ASSERT_TRUE(runOptions.isSkipExpandObjectsDefaulted()); ASSERT_FALSE(runOptions.skipEnergyPlusPreprocess()); ASSERT_TRUE(runOptions.isSkipEnergyPlusPreprocessDefaulted()); + ASSERT_FALSE(runOptions.skipZipResults()); + ASSERT_TRUE(runOptions.isSkipZipResultsDefaulted()); ASSERT_TRUE(runOptions.cleanup()); ASSERT_TRUE(runOptions.isCleanupDefaulted()); @@ -1401,6 +1416,8 @@ TEST(Filetypes, RunOptions_overrideValuesWith) { ASSERT_TRUE(runOptions.isSkipExpandObjectsDefaulted()); ASSERT_FALSE(runOptions.skipEnergyPlusPreprocess()); ASSERT_TRUE(runOptions.isSkipEnergyPlusPreprocessDefaulted()); + ASSERT_FALSE(runOptions.skipEnergyPlusPreprocess()); + ASSERT_TRUE(runOptions.isSkipEnergyPlusPreprocessDefaulted()); ASSERT_TRUE(runOptions.cleanup()); ASSERT_TRUE(runOptions.isCleanupDefaulted());