src/energyplus/ReverseTranslator/ReverseTranslateZonePropertyUserViewFactorsBySurfaceName.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #include "../ReverseTranslator.hpp" | ||
| 7 | |||
| 8 | #include "../../model/ZonePropertyUserViewFactorsBySurfaceName.hpp" | ||
| 9 | #include "../../model/ZonePropertyUserViewFactorsBySurfaceName_Impl.hpp" | ||
| 10 | #include "../../model/ThermalZone.hpp" | ||
| 11 | #include "../../model/ThermalZone_Impl.hpp" | ||
| 12 | #include "../../model/Space.hpp" | ||
| 13 | #include "../../model/Space_Impl.hpp" | ||
| 14 | |||
| 15 | #include "../../utilities/idf/WorkspaceExtensibleGroup.hpp" | ||
| 16 | |||
| 17 | #include <utilities/idd/ZoneProperty_UserViewFactors_BySurfaceName_FieldEnums.hxx> | ||
| 18 | #include <utilities/idd/ZoneList_FieldEnums.hxx> | ||
| 19 | #include <utilities/idd/Space_FieldEnums.hxx> | ||
| 20 | #include <utilities/idd/SpaceList_FieldEnums.hxx> | ||
| 21 | #include "../../utilities/idd/IddEnums.hpp" | ||
| 22 | #include <utilities/idd/IddEnums.hxx> | ||
| 23 | |||
| 24 | #include "../../utilities/core/Assert.hpp" | ||
| 25 | |||
| 26 | using namespace openstudio::model; | ||
| 27 | |||
| 28 | namespace openstudio { | ||
| 29 | |||
| 30 | namespace energyplus { | ||
| 31 | |||
| 32 | 4 | OptionalModelObject ReverseTranslator::translateZonePropertyUserViewFactorsBySurfaceName(const WorkspaceObject& workspaceObject) { | |
| 33 |
4/5✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
|
4 | if (workspaceObject.iddObject().type() != IddObjectType::ZoneProperty_UserViewFactors_BySurfaceName) { |
| 34 | ✗ | LOG(Error, "WorkspaceObject is not IddObjectType: ZonePropertyUserViewFactorsBySurfaceName"); | |
| 35 | ✗ | return boost::none; | |
| 36 | } | ||
| 37 | |||
| 38 | boost::optional<WorkspaceObject> target = | ||
| 39 |
1/1✓ Branch 1 taken 4 times.
|
4 | workspaceObject.getTarget(ZoneProperty_UserViewFactors_BySurfaceNameFields::ZoneorZoneListorSpaceorSpaceListName); |
| 40 | |||
| 41 | 4 | std::vector<ThermalZone> thermalZones; | |
| 42 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (target) { |
| 43 | |||
| 44 | 4 | std::vector<WorkspaceObject> i_zones; | |
| 45 |
5/6✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
|
4 | if (target->iddObject().type() == IddObjectType::Zone) { |
| 46 | |||
| 47 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | i_zones.push_back(target.get()); |
| 48 | |||
| 49 | ✗ | } else if (target->iddObject().type() == IddObjectType::ZoneList) { | |
| 50 | |||
| 51 | ✗ | for (const IdfExtensibleGroup& zeg : target->extensibleGroups()) { | |
| 52 | ✗ | OptionalWorkspaceObject target_zone = zeg.cast<WorkspaceExtensibleGroup>().getTarget(ZoneListExtensibleFields::ZoneName); | |
| 53 | ✗ | if (target_zone) { | |
| 54 | ✗ | i_zones.push_back(target_zone.get()); | |
| 55 | } | ||
| 56 | ✗ | } | |
| 57 | |||
| 58 | ✗ | } else if (target->iddObject().type() == IddObjectType::Space) { | |
| 59 | |||
| 60 | ✗ | boost::optional<WorkspaceObject> target_zone = target->getTarget(SpaceFields::ZoneName); | |
| 61 | ✗ | if (target_zone) { | |
| 62 | ✗ | i_zones.push_back(target_zone.get()); | |
| 63 | } | ||
| 64 | |||
| 65 | ✗ | } else if (target->iddObject().type() == IddObjectType::SpaceList) { | |
| 66 | |||
| 67 | ✗ | for (const IdfExtensibleGroup& seg : target->extensibleGroups()) { | |
| 68 | ✗ | OptionalWorkspaceObject target_space = seg.cast<WorkspaceExtensibleGroup>().getTarget(SpaceListExtensibleFields::SpaceName); | |
| 69 | ✗ | if (target_space) { | |
| 70 | ✗ | boost::optional<WorkspaceObject> target_zone = target_space->getTarget(SpaceFields::ZoneName); | |
| 71 | ✗ | if (target_zone) { | |
| 72 | ✗ | i_zones.push_back(target_zone.get()); | |
| 73 | } | ||
| 74 | ✗ | } | |
| 75 | ✗ | } | |
| 76 | |||
| 77 | } else { | ||
| 78 | ✗ | LOG(Error, | |
| 79 | "For ZonePropertyUserViewFactorsBySurfaceName, an extensible group entry is neither a Zone or ZoneList or Space or SpaceList, skipping."); | ||
| 80 | ✗ | return boost::none; | |
| 81 | } | ||
| 82 | |||
| 83 |
2/2✓ Branch 5 taken 4 times.
✓ Branch 6 taken 4 times.
|
8 | for (const WorkspaceObject& i_zone : i_zones) { |
| 84 | // Zone is translated, and a Space is returned instead | ||
| 85 |
1/1✓ Branch 1 taken 4 times.
|
4 | OptionalModelObject _mo = translateAndMapWorkspaceObject(i_zone); |
| 86 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (_mo) { |
| 87 |
3/4✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
|
8 | if (boost::optional<Space> _space = _mo->optionalCast<Space>()) { |
| 88 |
3/4✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
|
8 | if (auto _zone = _space->thermalZone()) { |
| 89 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | thermalZones.push_back(_zone.get()); |
| 90 | 4 | } | |
| 91 | 4 | } | |
| 92 | } | ||
| 93 | 4 | } | |
| 94 | 4 | } | |
| 95 | |||
| 96 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | if (thermalZones.empty()) { |
| 97 | ✗ | LOG(Error, "Error importing object: " << workspaceObject.briefDescription() << " Can't find associated ThermalZone."); | |
| 98 | |||
| 99 | ✗ | return boost::none; | |
| 100 | } | ||
| 101 | |||
| 102 | 4 | boost::optional<ModelObject> result; | |
| 103 |
2/2✓ Branch 5 taken 4 times.
✓ Branch 6 taken 4 times.
|
8 | for (const ThermalZone& thermalZone : thermalZones) { |
| 104 | |||
| 105 |
1/1✓ Branch 1 taken 4 times.
|
4 | openstudio::model::ZonePropertyUserViewFactorsBySurfaceName zoneProp = thermalZone.getZonePropertyUserViewFactorsBySurfaceName(); |
| 106 | |||
| 107 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | if (!result) { |
| 108 |
1/1✓ Branch 1 taken 4 times.
|
4 | result = zoneProp; |
| 109 | } | ||
| 110 | |||
| 111 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 4 times.
|
8 | for (const IdfExtensibleGroup& idfGroup : workspaceObject.extensibleGroups()) { |
| 112 |
1/1✓ Branch 1 taken 4 times.
|
4 | auto workspaceGroup = idfGroup.cast<WorkspaceExtensibleGroup>(); |
| 113 | |||
| 114 | boost::optional<WorkspaceObject> fromTarget = | ||
| 115 |
1/1✓ Branch 1 taken 4 times.
|
4 | workspaceGroup.getTarget(ZoneProperty_UserViewFactors_BySurfaceNameExtensibleFields::FromSurface); |
| 116 |
1/1✓ Branch 1 taken 4 times.
|
4 | boost::optional<WorkspaceObject> toTarget = workspaceGroup.getTarget(ZoneProperty_UserViewFactors_BySurfaceNameExtensibleFields::ToSurface); |
| 117 | |||
| 118 | 4 | boost::optional<ModelObject> toModelObject; | |
| 119 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | boost::optional<ModelObject> fromModelObject = translateAndMapWorkspaceObject(*fromTarget); |
| 120 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
|
4 | if (fromTarget != toTarget) { |
| 121 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | toModelObject = translateAndMapWorkspaceObject(*toTarget); |
| 122 | } else { | ||
| 123 |
1/1✓ Branch 1 taken 2 times.
|
2 | toModelObject = fromModelObject; |
| 124 | } | ||
| 125 | |||
| 126 |
1/1✓ Branch 1 taken 4 times.
|
4 | OptionalDouble _viewFactor = workspaceGroup.getDouble(ZoneProperty_UserViewFactors_BySurfaceNameExtensibleFields::ViewFactor); |
| 127 | |||
| 128 | // If the objects translated ok, and the viewFactor double value exists | ||
| 129 |
4/8✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
|
12 | if (fromModelObject && toModelObject && _viewFactor) { |
| 130 | // try to create a viewFactor, which will throw in case wrong type, or wrong double value. Here we let it slide though | ||
| 131 | try { | ||
| 132 |
4/4✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
|
4 | ViewFactor viewFactor(fromModelObject.get(), toModelObject.get(), _viewFactor.get()); |
| 133 | // add the view factor | ||
| 134 |
2/3✓ Branch 1 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
|
4 | if (!zoneProp.addViewFactor(viewFactor)) { |
| 135 | ✗ | LOG(Warn, "Adding ViewFactor in ThermalZone " << thermalZone.nameString() << " failed for viewFactor=" << viewFactor << "."); | |
| 136 | } | ||
| 137 | 4 | } catch (...) { | |
| 138 | // The ViewFactor Ctor threw, so there's a wrong type, or a wrong double | ||
| 139 | ✗ | LOG(Error, "Could not create ViewFactor in ThermalZone " | |
| 140 | << thermalZone.nameString() << " for fromModelObject=(" << fromModelObject->briefDescription() << "), toModelObject=(" | ||
| 141 | << toModelObject->briefDescription() << ") and viewFactor=" << _viewFactor.get() << "."); | ||
| 142 | ✗ | } | |
| 143 | } | ||
| 144 | 8 | } | |
| 145 | 4 | } | |
| 146 | |||
| 147 | 4 | return result; | |
| 148 | 4 | } | |
| 149 | |||
| 150 | } // namespace energyplus | ||
| 151 | |||
| 152 | } // namespace openstudio | ||
| 153 |