Skip to content

Commit

Permalink
Fix #4020 - AvailabilityManagerNightCycle: Ensure ModelObjectLists ar…
Browse files Browse the repository at this point in the history
…e handled in clone/remove
  • Loading branch information
jmarrec committed Aug 4, 2020
1 parent 7ae58b2 commit 82673d4
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 18 deletions.
98 changes: 81 additions & 17 deletions src/model/AvailabilityManagerNightCycle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,82 @@ namespace detail {
return result;
}

ModelObject AvailabilityManagerNightCycle_Impl::clone(Model model) const {
AvailabilityManagerNightCycle avmClone = ModelObject_Impl::clone(model).cast<AvailabilityManagerNightCycle>();

// Now recreate the lists
// Control Zone List
ModelObjectList controlThermalZoneList = ModelObjectList(model);
controlThermalZoneList.setName(this->name().get() + " Control Zone List");
bool ok = avmClone.getImpl<detail::AvailabilityManager_Impl>()->setPointer(
OS_AvailabilityManager_NightCycleFields::ControlZoneorZoneListName, controlThermalZoneList.handle()
);
OS_ASSERT(ok);

// Cooling Control Zone List
ModelObjectList coolingControlThermalZoneList = ModelObjectList(model);
coolingControlThermalZoneList.setName(this->name().get() + " Cooling Control Zone List");
ok = avmClone.getImpl<detail::AvailabilityManager_Impl>()->setPointer(
OS_AvailabilityManager_NightCycleFields::CoolingControlZoneorZoneListName, coolingControlThermalZoneList.handle()
);
OS_ASSERT(ok);

// Heating Control Zone List
ModelObjectList heatingControlThermalZoneList = ModelObjectList(model);
heatingControlThermalZoneList.setName(this->name().get() + " Heating Control Zone List");
ok = avmClone.getImpl<detail::AvailabilityManager_Impl>()->setPointer(
OS_AvailabilityManager_NightCycleFields::HeatingControlZoneorZoneListName, heatingControlThermalZoneList.handle()
);
OS_ASSERT(ok);

// Heating Zone Fans Only Zone List
ModelObjectList heatingZoneFansOnlyThermalZoneList = ModelObjectList(model);
heatingZoneFansOnlyThermalZoneList.setName(this->name().get() + " Heating Zone Fans Only Zone List");
ok = avmClone.getImpl<detail::AvailabilityManager_Impl>()->setPointer(
OS_AvailabilityManager_NightCycleFields::HeatingZoneFansOnlyZoneorZoneListName, heatingZoneFansOnlyThermalZoneList.handle()
);
OS_ASSERT(ok);

return avmClone;
}

std::vector<IdfObject> AvailabilityManagerNightCycle_Impl::remove() {
std::vector<IdfObject> result;

// Remove the ModelObjectLists. You have to clear them first, or it'll also remove the ThermalZones contained within.
{
ModelObjectList mo_list = controlThermalZoneList();
mo_list.removeAllModelObjects();
std::vector<IdfObject> removedMoList = mo_list.remove();
result.insert(result.end(), removedMoList.begin(), removedMoList.end());
}

{
ModelObjectList mo_list = coolingControlThermalZoneList();
mo_list.removeAllModelObjects();
std::vector<IdfObject> removedMoList = mo_list.remove();
result.insert(result.end(), removedMoList.begin(), removedMoList.end());
}

{
ModelObjectList mo_list = heatingControlThermalZoneList();
mo_list.removeAllModelObjects();
std::vector<IdfObject> removedMoList = mo_list.remove();
result.insert(result.end(), removedMoList.begin(), removedMoList.end());
}

{
ModelObjectList mo_list = heatingZoneFansOnlyThermalZoneList();
mo_list.removeAllModelObjects();
std::vector<IdfObject> removedMoList = mo_list.remove();
result.insert(result.end(), removedMoList.begin(), removedMoList.end());
}

std::vector<IdfObject> AvailabilityManagerNightCycle = ModelObject_Impl::remove();
result.insert(result.end(), AvailabilityManagerNightCycle.begin(), AvailabilityManagerNightCycle.end());

return result;
}

boost::optional<AirLoopHVAC> AvailabilityManagerNightCycle_Impl::airLoopHVAC() const {
if (boost::optional<Loop> _loop = loop()) {
Expand Down Expand Up @@ -245,10 +321,7 @@ namespace detail {
}
void AvailabilityManagerNightCycle_Impl::clearControlThermalZoneList() {
ModelObjectList mo_list = controlThermalZoneList();
for (const ModelObject& mo : mo_list.modelObjects()) {
mo_list.removeModelObject(mo);
}
// Assert size = 0?
mo_list.removeAllModelObjects();
}


Expand Down Expand Up @@ -301,10 +374,7 @@ namespace detail {

void AvailabilityManagerNightCycle_Impl::clearCoolingControlThermalZoneList() {
ModelObjectList mo_list = coolingControlThermalZoneList();
for (const ModelObject& mo : mo_list.modelObjects()) {
mo_list.removeModelObject(mo);
}
// Assert size = 0?
mo_list.removeAllModelObjects();
}


Expand Down Expand Up @@ -355,10 +425,7 @@ namespace detail {

void AvailabilityManagerNightCycle_Impl::clearHeatingControlThermalZoneList() {
ModelObjectList mo_list = heatingControlThermalZoneList();
for (const ModelObject& mo : mo_list.modelObjects()) {
mo_list.removeModelObject(mo);
}
// Assert size = 0?
mo_list.removeAllModelObjects();
}


Expand Down Expand Up @@ -411,10 +478,7 @@ namespace detail {

void AvailabilityManagerNightCycle_Impl::clearHeatingZoneFansOnlyThermalZoneList() {
ModelObjectList mo_list = heatingZoneFansOnlyThermalZoneList();
for (const ModelObject& mo : mo_list.modelObjects()) {
mo_list.removeModelObject(mo);
}
// Assert size = 0?
mo_list.removeAllModelObjects();
}


Expand Down Expand Up @@ -691,4 +755,4 @@ AvailabilityManagerNightCycle::AvailabilityManagerNightCycle(std::shared_ptr<det
/// @endcond

} // model
} // openstudio
} // openstudio
9 changes: 8 additions & 1 deletion src/model/AvailabilityManagerNightCycle_Impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ namespace detail {

virtual std::vector<ScheduleTypeKey> getScheduleTypeKeys(const Schedule& schedule) const override;

// Cloning should ensure we do have modelObjectLists for control zones, but they should be empty
// as it is not connected to an AirLoopHVAC (yet) and it wouldn't make sense to have zones there
virtual ModelObject clone(Model model) const override;

// Clears the ModelObjectLists, then remove them
virtual std::vector<IdfObject> remove() override;

boost::optional<AirLoopHVAC> airLoopHVAC() const;

Schedule applicabilitySchedule() const;
Expand Down Expand Up @@ -142,4 +149,4 @@ namespace detail {
} // model
} // openstudio

#endif // MODEL_AVAILABILITYMANAGERNIGHTCYCLE_IMPL_HPP
#endif // MODEL_AVAILABILITYMANAGERNIGHTCYCLE_IMPL_HPP

0 comments on commit 82673d4

Please sign in to comment.