-
Notifications
You must be signed in to change notification settings - Fork 29
Add hot-gas reheat unitary system (Coil:Heating:Desuperheater) #891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ski90Moo
wants to merge
6
commits into
openstudiocoalition:develop
Choose a base branch
from
Ski90Moo:feature/desuperheater-hotgas-reheat
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+243
−2
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
265372c
chore: gitignore in-source CMake/Conan/Qt build artifacts (#2)
Ski90Moo d1e217e
feat: add hot-gas reheat unitary system with Coil:Heating:Desuperheater
Ski90Moo e77a9b0
refactor: generalize clone lateral-reference fixup beyond desuperheater
Ski90Moo 59177f7
fix: correct clone fixup for fields clone() clears instead of staling
Ski90Moo 203331f
fix: reach loop-branch equipment when fixing up cloned references
Ski90Moo 39e82f5
fix: reach outdoor-air/relief branch equipment in clone fixup too
Ski90Moo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,8 +28,15 @@ profile/ | |
|
|
||
| *.sublime-workspace | ||
|
|
||
| # Qt-generated files | ||
| src/openstudio_lib/moc_*.cpp | ||
| # Qt moc/rcc-generated files, wherever CMake drops them in the tree | ||
| moc_*.cpp | ||
| moc_*.cpp_parameters | ||
| qrc_*.cpp | ||
| *.qrc.depends | ||
| **/__/ | ||
| *_autogen/ | ||
| .lupdate/ | ||
| .qt/ | ||
|
|
||
| *.sublime-project | ||
| cmake-build-debug | ||
|
|
@@ -45,3 +52,61 @@ clang_format.patch | |
| conan-cache | ||
| .ccache | ||
| CMakeUserPresets.json | ||
|
|
||
| # This repo is built in-place at the repo root (not an out-of-source build/ dir), so | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest not building in-source |
||
| # CMake/Conan/MSBuild drop generated files alongside tracked source. Ignore those. | ||
| /CMakeCache.txt | ||
| /CMakePresets.json | ||
| /CPackConfig.cmake | ||
| /CPackSourceConfig.cmake | ||
| /cmakedeps_macros.cmake | ||
| /conan_toolchain.cmake | ||
| /conanbuild.bat | ||
| /conanbuildenv-*.bat | ||
| /conandeps_legacy.cmake | ||
| /conanrun.bat | ||
| /conanrunenv-*.bat | ||
| /deactivate_conanbuild.bat | ||
| /deactivate_conanrun.bat | ||
| /*-Target-release.cmake | ||
| /*-release-x86_64-data.cmake | ||
| /*Config.cmake | ||
| /*ConfigVersion.cmake | ||
| /*Targets.cmake | ||
| /*-config.cmake | ||
| /*-config-version.cmake | ||
| /Find*.cmake | ||
| /module-*.cmake | ||
| /get_output_vars.rb | ||
| /output_vars_list.txt | ||
| /aqtinstall.log | ||
| /build_output.txt | ||
| /Products/ | ||
| /_deps/ | ||
| /OpenStudio-3.11.0/ | ||
|
|
||
| # CMake-generated Visual Studio projects/solution, wherever they land | ||
| CMakeFiles/ | ||
| cmake_install.cmake | ||
| *.vcxproj | ||
| *.vcxproj.filters | ||
| *.sln | ||
|
|
||
| # Compiled translation binaries (built from the tracked .ts sources) | ||
| translations/*.qm | ||
|
|
||
| __pycache__/ | ||
|
|
||
| # EnergyPlus local-docs workflow output (see ENERGYPLUS_DOCS_WORKFLOW.md, itself gitignored) | ||
| /ENERGYPLUS_DOCS_WORKFLOW.md | ||
| /EnergyPlus/ | ||
| /EnergyPlusDocsArchive/ | ||
|
|
||
| # configure_file()-generated from tracked .in templates; AnalyticsHelperSecrets.hxx in | ||
| # particular is populated with real secret values at configure time -- never commit it. | ||
| src/openstudio_lib/AnalyticsHelperSecrets.hxx | ||
| src/openstudio_lib/AnalyticsHelperSecrets.hxx.tmp | ||
| src/openstudio_app/AboutBox.hpp | ||
| src/model_editor/AboutBox.hpp | ||
| src/openstudio_app/OpenStudioApp.rc | ||
| src/utilities/OpenStudioApplicationPathHelpers.cxx | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,6 +92,8 @@ | |
| #include <openstudio/model/CoilHeatingElectric_Impl.hpp> | ||
| #include <openstudio/model/CoilHeatingWater.hpp> | ||
| #include <openstudio/model/CoilHeatingWater_Impl.hpp> | ||
| #include <openstudio/model/ParentObject.hpp> | ||
| #include <openstudio/model/ParentObject_Impl.hpp> | ||
| #include <openstudio/model/Model.hpp> | ||
| #include <openstudio/model/Model_Impl.hpp> | ||
| #include <openstudio/model/Node.hpp> | ||
|
|
@@ -126,6 +128,8 @@ | |
| #include <openstudio/utilities/core/Compare.hpp> | ||
| #include <openstudio/utilities/idd/OS_ComponentData_FieldEnums.hxx> | ||
|
|
||
| #include <map> | ||
|
|
||
| #include <QMessageBox> | ||
| #include <QTimer> | ||
| #include <QPushButton> | ||
|
|
@@ -519,6 +523,117 @@ void HVACLayoutController::addLibraryObjectToTopLevel(const OSItemId& itemId) { | |
| message.exec(); | ||
| } | ||
|
|
||
| namespace { | ||
| // ModelObject::clone() clones each child individually and reattaches it via setParent(), so | ||
| // true parent-child edges are correctly remapped to point within the new subtree. But children | ||
| // are cloned one at a time rather than as a batch sharing a single old->new handle table, so any | ||
| // *lateral* object-list reference between two siblings in the cloned subtree (e.g. | ||
| // CoilHeatingDesuperheater::heatingSource() pointing at a sibling cooling coil, or a | ||
| // SetpointManager's node references) is left broken on the clone -- for some field/type | ||
| // combinations still pointing at the original object, for others (empirically, heatingSource()) | ||
| // cleared to empty outright. The functions below fix that up generically, for any object type, | ||
| // rather than special casing each lateral-reference field as it's discovered. | ||
|
|
||
| // ParentObject::children() is true ownership (e.g. a UnitarySystem's fan/coils) but does *not* | ||
| // include HVACComponents placed on a Loop's supply/demand branches -- a UnitarySystem sitting on | ||
| // an AirLoopHVAC's supply branch is reachable via supplyComponents(), not children(). The same | ||
| // gap exists one level deeper: equipment on an AirLoopHVACOutdoorAirSystem's outdoor-air/relief | ||
| // branches (e.g. an evaporative cooler, or a SetpointManager:MixedAir sitting on one of those | ||
| // nodes) is reachable only via oaComponents()/reliefComponents(), not children() either. Cloning | ||
| // a whole loop (the "copy system" toolbar action) needs all of these, or the branch equipment -- | ||
| // and anything lateral-referenced from inside it -- is never visited at all. | ||
| // | ||
| // Returned as separate groups, each matched and recursed into independently: cloning a loop does | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sense to me but I wonder two things:
|
||
| // not carry over the connected thermal zones on the demand side, so original vs. clone | ||
| // demandComponents() can legitimately have different sizes. Treating everything as one combined | ||
| // list would let a benign demand-side mismatch abort recursion into the other groups too, where | ||
| // the equipment (and any lateral references inside it) *does* line up 1:1 with the original. | ||
| std::vector<std::vector<model::ModelObject>> childSubtreeObjectGroups(const model::ModelObject& object) { | ||
| std::vector<std::vector<model::ModelObject>> groups; | ||
| if (boost::optional<model::Loop> loop = object.optionalCast<model::Loop>()) { | ||
| groups.push_back(loop->supplyComponents()); | ||
| groups.push_back(loop->demandComponents()); | ||
| } | ||
| if (boost::optional<model::AirLoopHVACOutdoorAirSystem> oaSystem = object.optionalCast<model::AirLoopHVACOutdoorAirSystem>()) { | ||
| groups.push_back(oaSystem->oaComponents()); | ||
| groups.push_back(oaSystem->reliefComponents()); | ||
| } | ||
| if (boost::optional<model::ParentObject> parent = object.optionalCast<model::ParentObject>()) { | ||
| groups.push_back(parent->children()); | ||
| } | ||
| return groups; | ||
| } | ||
|
|
||
| // Walks `original` and `clone` in parallel -- childSubtreeObjectGroups() order is deterministic | ||
| // and preserved by clone() -- building a map from each original object's handle to its | ||
| // corresponding clone. | ||
| void buildCloneHandleMap(const model::ModelObject& original, const model::ModelObject& clone, | ||
| std::map<Handle, model::ModelObject>& handleMap) { | ||
| handleMap.emplace(original.handle(), clone); | ||
|
|
||
| std::vector<std::vector<model::ModelObject>> originalGroups = childSubtreeObjectGroups(original); | ||
| std::vector<std::vector<model::ModelObject>> cloneGroups = childSubtreeObjectGroups(clone); | ||
| for (size_t g = 0; g < originalGroups.size() && g < cloneGroups.size(); ++g) { | ||
| const std::vector<model::ModelObject>& originalChildren = originalGroups[g]; | ||
| const std::vector<model::ModelObject>& cloneChildren = cloneGroups[g]; | ||
| if (originalChildren.size() == cloneChildren.size()) { | ||
| for (size_t i = 0; i < originalChildren.size(); ++i) { | ||
| buildCloneHandleMap(originalChildren[i], cloneChildren[i], handleMap); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // For every lateral object-list field on `original` whose target was itself cloned (i.e. has an | ||
| // entry in handleMap), forces the corresponding field on `clonedObject` to point at that clone. | ||
| // Fields are read from `original`, not from `clonedObject`: clone() doesn't necessarily leave a | ||
| // lateral reference pointing at the stale original object -- for CoilHeatingDesuperheater's | ||
| // heatingSource() it clears the field outright -- so the only reliable source of "what this | ||
| // field is supposed to point at" is the original. | ||
| void remapLateralReferences(const model::ModelObject& original, model::ModelObject clonedObject, | ||
| const std::map<Handle, model::ModelObject>& handleMap) { | ||
| IddObject iddObject = original.iddObject(); | ||
| for (unsigned index = 0; index < original.numFields(); ++index) { | ||
| if (iddObject.objectLists(index).empty()) { | ||
| continue; | ||
| } | ||
| boost::optional<WorkspaceObject> originalTarget = original.getTarget(index); | ||
| if (!originalTarget) { | ||
| continue; | ||
| } | ||
| auto it = handleMap.find(originalTarget->handle()); | ||
| if (it == handleMap.end()) { | ||
| continue; | ||
| } | ||
| boost::optional<WorkspaceObject> clonedTarget = clonedObject.getTarget(index); | ||
| if (clonedTarget && clonedTarget->handle() == it->second.handle()) { | ||
| continue; | ||
| } | ||
| clonedObject.setPointer(index, it->second.handle()); | ||
| } | ||
|
|
||
| std::vector<std::vector<model::ModelObject>> originalGroups = childSubtreeObjectGroups(original); | ||
| std::vector<std::vector<model::ModelObject>> cloneGroups = childSubtreeObjectGroups(clonedObject); | ||
| for (size_t g = 0; g < originalGroups.size() && g < cloneGroups.size(); ++g) { | ||
| const std::vector<model::ModelObject>& originalChildren = originalGroups[g]; | ||
| const std::vector<model::ModelObject>& cloneChildren = cloneGroups[g]; | ||
| if (originalChildren.size() == cloneChildren.size()) { | ||
| for (size_t i = 0; i < originalChildren.size(); ++i) { | ||
| remapLateralReferences(originalChildren[i], cloneChildren[i], handleMap); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // `original` is the subtree that was cloned; `clonedObject` is its clone. Re-links any lateral | ||
| // reference in the clone that still points into (or should point into) the original subtree. | ||
| void fixupClonedReferences(const model::ModelObject& original, model::ModelObject clonedObject) { | ||
| std::map<Handle, model::ModelObject> handleMap; | ||
| buildCloneHandleMap(original, clonedObject, handleMap); | ||
| remapLateralReferences(original, clonedObject, handleMap); | ||
| } | ||
| } // namespace | ||
|
|
||
| void HVACLayoutController::addLibraryObjectToModelNode(const OSItemId& itemId, model::HVACComponent& comp) { | ||
| model::OptionalModelObject object; | ||
| bool remove = false; | ||
|
|
@@ -527,7 +642,9 @@ void HVACLayoutController::addLibraryObjectToModelNode(const OSItemId& itemId, m | |
| object = doc->getModelObject(itemId); | ||
| if (object) { | ||
| if (!doc->fromModel(itemId)) { | ||
| model::ModelObject original = object.get(); | ||
| object = object->clone(comp.model()); | ||
| fixupClonedReferences(original, object.get()); | ||
| remove = true; | ||
| } | ||
| } | ||
|
|
@@ -893,6 +1010,7 @@ void HVACSystemsController::onCopySystemClicked() { | |
| auto loop = currentLoop(); | ||
| if (loop) { | ||
| auto clone = loop->clone(loop->model()); | ||
| fixupClonedReferences(loop.get(), clone); | ||
| setCurrentHandle(toQString(clone.handle())); | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also happening because you are building in-source.