src/energyplus/ReverseTranslator/ReverseTranslateDaylightingControls.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/DaylightingControl.hpp" | ||
| 9 | #include "../../model/DaylightingControl_Impl.hpp" | ||
| 10 | #include "../../model/Space.hpp" | ||
| 11 | #include "../../model/Space_Impl.hpp" | ||
| 12 | #include "../../model/ThermalZone.hpp" | ||
| 13 | #include "../../model/ThermalZone_Impl.hpp" | ||
| 14 | |||
| 15 | #include "../../utilities/core/Compare.hpp" | ||
| 16 | #include "../../utilities/geometry/Geometry.hpp" | ||
| 17 | #include "../../utilities/idf/IdfExtensibleGroup.hpp" | ||
| 18 | #include "../../utilities/idf/WorkspaceExtensibleGroup.hpp" | ||
| 19 | |||
| 20 | #include <utilities/idd/Daylighting_Controls_FieldEnums.hxx> | ||
| 21 | #include <utilities/idd/Daylighting_ReferencePoint_FieldEnums.hxx> | ||
| 22 | #include "../../utilities/idd/IddEnums.hpp" | ||
| 23 | #include <utilities/idd/IddEnums.hxx> | ||
| 24 | |||
| 25 | using namespace openstudio::model; | ||
| 26 | |||
| 27 | namespace openstudio { | ||
| 28 | |||
| 29 | namespace energyplus { | ||
| 30 | |||
| 31 | 9 | OptionalModelObject ReverseTranslator::translateDaylightingControls(const WorkspaceObject& workspaceObject) { | |
| 32 |
4/5✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 9 times.
|
9 | if (workspaceObject.iddObject().type() != IddObjectType::Daylighting_Controls) { |
| 33 | ✗ | LOG(Error, "WorkspaceObject is not IddObjectType: Daylighting:Controls"); | |
| 34 | ✗ | return boost::none; | |
| 35 | } | ||
| 36 | |||
| 37 |
1/1✓ Branch 1 taken 9 times.
|
9 | std::vector<IdfExtensibleGroup> groups = workspaceObject.extensibleGroups(); |
| 38 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
|
9 | if (groups.empty()) { |
| 39 | ✗ | LOG(Warn, "Daylighting:Controls '" << workspaceObject.nameString() << "' has no reference points, will not be translated."); | |
| 40 | ✗ | return boost::none; | |
| 41 | } | ||
| 42 | |||
| 43 | 9 | OptionalModelObject result; | |
| 44 | 9 | OptionalThermalZone controlThermalZone; | |
| 45 | 9 | OptionalSpace controlSpace; | |
| 46 |
1/1✓ Branch 1 taken 9 times.
|
9 | OptionalWorkspaceObject controlZone = workspaceObject.getTarget(Daylighting_ControlsFields::ZoneorSpaceName); |
| 47 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | if (controlZone) { |
| 48 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
|
9 | OptionalModelObject modelObject = translateAndMapWorkspaceObject(*controlZone); |
| 49 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | if (modelObject) { |
| 50 |
3/4✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
|
18 | if (modelObject->optionalCast<Space>()) { |
| 51 |
3/3✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
|
9 | controlSpace = modelObject->cast<Space>(); |
| 52 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
|
9 | controlThermalZone = controlSpace->thermalZone(); |
| 53 | } | ||
| 54 | } | ||
| 55 | 9 | } | |
| 56 | |||
| 57 | 9 | OptionalDouble d; | |
| 58 | 9 | double sum = 0; | |
| 59 | 9 | std::vector<double> fractions; | |
| 60 | 9 | std::vector<std::size_t> indices; | |
| 61 | 9 | std::size_t idx = 0; | |
| 62 |
2/2✓ Branch 5 taken 16 times.
✓ Branch 6 taken 9 times.
|
25 | for (const auto& group : groups) { |
| 63 |
1/1✓ Branch 1 taken 16 times.
|
16 | boost::optional<double> fraction = group.getDouble(Daylighting_ControlsExtensibleFields::FractionofLightsControlledbyReferencePoint, true); |
| 64 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 4 not taken.
|
16 | OS_ASSERT(fraction); |
| 65 | |||
| 66 | boost::optional<WorkspaceObject> referencePoint = | ||
| 67 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
|
16 | group.cast<WorkspaceExtensibleGroup>().getTarget(Daylighting_ControlsExtensibleFields::DaylightingReferencePointName); |
| 68 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
|
16 | if (!referencePoint) { |
| 69 | ✗ | if (*fraction > 0.0) { | |
| 70 | ✗ | LOG(Warn, "Daylighting:Controls '" << workspaceObject.nameString() << "' missing reference point " << idx | |
| 71 | << ", setting fraction of zone controlled to 0."); | ||
| 72 | ✗ | fraction = 0; | |
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 |
1/1✓ Branch 1 taken 16 times.
|
16 | sum += *fraction; |
| 77 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
|
16 | fractions.push_back(*fraction); |
| 78 |
1/1✓ Branch 1 taken 16 times.
|
16 | indices.push_back(idx); |
| 79 | 16 | idx += 1; | |
| 80 | 16 | } | |
| 81 | // sort indices by fraction in descending order | ||
| 82 |
1/1✓ Branch 3 taken 9 times.
|
23 | sort(indices.begin(), indices.end(), [&fractions](const size_t& i1, const size_t& i2) { return fractions[i1] > fractions[i2]; }); |
| 83 | |||
| 84 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (sum > 1.0) { |
| 85 | ✗ | LOG(Warn, "Daylighting:Controls '" << workspaceObject.nameString() << "' specifies fraction controlled greater than one.") | |
| 86 | } | ||
| 87 | |||
| 88 | // loop over the groups in order by indices | ||
| 89 |
2/2✓ Branch 5 taken 16 times.
✓ Branch 6 taken 9 times.
|
25 | for (const auto& index : indices) { |
| 90 | 16 | const auto& group = groups[index]; | |
| 91 | |||
| 92 | 16 | bool isPrimary = false; | |
| 93 | 16 | bool isSecondary = false; | |
| 94 | |||
| 95 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | if (controlThermalZone) { |
| 96 |
4/4✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
✓ Branch 8 taken 9 times.
✓ Branch 9 taken 7 times.
|
16 | if (!controlThermalZone->primaryDaylightingControl()) { |
| 97 | 9 | isPrimary = true; | |
| 98 |
3/4✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
✓ Branch 8 taken 7 times.
✗ Branch 9 not taken.
|
7 | } else if (!controlThermalZone->secondaryDaylightingControl()) { |
| 99 | 7 | isSecondary = true; | |
| 100 | } | ||
| 101 | } | ||
| 102 | |||
| 103 | boost::optional<WorkspaceObject> referencePoint = | ||
| 104 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
|
16 | group.cast<WorkspaceExtensibleGroup>().getTarget(Daylighting_ControlsExtensibleFields::DaylightingReferencePointName); |
| 105 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
|
16 | if (!referencePoint) { |
| 106 | ✗ | LOG(Warn, "Daylighting:Controls '" << workspaceObject.nameString() << "' missing reference point " << idx << "."); | |
| 107 | ✗ | continue; | |
| 108 | ✗ | } | |
| 109 | |||
| 110 | 16 | OptionalThermalZone refThermalZone; | |
| 111 | 16 | OptionalSpace refSpace; | |
| 112 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
|
16 | OptionalWorkspaceObject refZone = referencePoint->getTarget(Daylighting_ReferencePointFields::ZoneorSpaceName); |
| 113 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | if (refZone) { |
| 114 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
|
16 | OptionalModelObject modelObject = translateAndMapWorkspaceObject(*refZone); |
| 115 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | if (modelObject) { |
| 116 |
3/4✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
|
32 | if (modelObject->optionalCast<Space>()) { |
| 117 |
3/3✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
✓ Branch 7 taken 16 times.
|
16 | refSpace = modelObject->cast<Space>(); |
| 118 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
|
16 | refThermalZone = refSpace->thermalZone(); |
| 119 | } | ||
| 120 | } | ||
| 121 | 16 | } | |
| 122 | |||
| 123 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
|
16 | if (!refSpace) { |
| 124 | ✗ | LOG(Warn, "Daylighting:ReferencePoint '" << referencePoint->nameString() << "' missing zone, will not be translated."); | |
| 125 | ✗ | continue; | |
| 126 | ✗ | } | |
| 127 | |||
| 128 |
1/1✓ Branch 1 taken 16 times.
|
16 | DaylightingControl daylightingControl(m_model); |
| 129 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 2 taken 7 times.
|
16 | if (!result) { |
| 130 |
1/1✓ Branch 1 taken 9 times.
|
9 | result = daylightingControl; |
| 131 | } | ||
| 132 | |||
| 133 |
3/3✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
✓ Branch 7 taken 16 times.
|
16 | daylightingControl.setName(referencePoint->nameString()); |
| 134 | |||
| 135 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
|
16 | daylightingControl.setSpace(*refSpace); |
| 136 | |||
| 137 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
|
16 | d = referencePoint->getDouble(Daylighting_ReferencePointFields::XCoordinateofReferencePoint); |
| 138 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | if (d) { |
| 139 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
|
16 | daylightingControl.setPositionXCoordinate(*d); |
| 140 | } | ||
| 141 | |||
| 142 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
|
16 | d = referencePoint->getDouble(Daylighting_ReferencePointFields::YCoordinateofReferencePoint); |
| 143 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | if (d) { |
| 144 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
|
16 | daylightingControl.setPositionYCoordinate(*d); |
| 145 | } | ||
| 146 | |||
| 147 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
|
16 | d = referencePoint->getDouble(Daylighting_ReferencePointFields::ZCoordinateofReferencePoint); |
| 148 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | if (d) { |
| 149 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
|
16 | daylightingControl.setPositionZCoordinate(*d); |
| 150 | } | ||
| 151 | |||
| 152 |
1/1✓ Branch 1 taken 16 times.
|
16 | d = group.getDouble(Daylighting_ControlsExtensibleFields::IlluminanceSetpointatReferencePoint); |
| 153 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | if (d) { |
| 154 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
|
16 | daylightingControl.setIlluminanceSetpoint(*d); |
| 155 | } | ||
| 156 | |||
| 157 |
1/1✓ Branch 1 taken 16 times.
|
16 | OptionalString s = workspaceObject.getString(Daylighting_ControlsFields::LightingControlType, true); |
| 158 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | if (s) { |
| 159 |
4/5✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
✓ Branch 7 taken 16 times.
✓ Branch 10 taken 16 times.
✗ Branch 11 not taken.
|
32 | if (istringEqual(*s, "Continuous")) { |
| 160 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
|
32 | daylightingControl.setLightingControlType("Continuous"); |
| 161 | ✗ | } else if (istringEqual(*s, "Stepped")) { | |
| 162 | ✗ | daylightingControl.setLightingControlType("Stepped"); | |
| 163 | ✗ | } else if (istringEqual(*s, "ContinuousOff")) { | |
| 164 | ✗ | daylightingControl.setLightingControlType("Continuous/Off"); | |
| 165 | } | ||
| 166 | } | ||
| 167 | |||
| 168 |
1/1✓ Branch 1 taken 16 times.
|
16 | d = workspaceObject.getDouble(Daylighting_ControlsFields::GlareCalculationAzimuthAngleofViewDirectionClockwisefromZoneyAxis); |
| 169 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | if (d) { |
| 170 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
|
16 | daylightingControl.setPhiRotationAroundZAxis(*d); |
| 171 | } | ||
| 172 | |||
| 173 |
1/1✓ Branch 1 taken 16 times.
|
16 | d = workspaceObject.getDouble(Daylighting_ControlsFields::MaximumAllowableDiscomfortGlareIndex); |
| 174 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 2 times.
|
16 | if (d) { |
| 175 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
|
14 | daylightingControl.setMaximumAllowableDiscomfortGlareIndex(*d); |
| 176 | } | ||
| 177 | |||
| 178 |
1/1✓ Branch 1 taken 16 times.
|
16 | d = workspaceObject.getDouble(Daylighting_ControlsFields::MinimumInputPowerFractionforContinuousorContinuousOffDimmingControl); |
| 179 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 2 times.
|
16 | if (d) { |
| 180 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
|
14 | daylightingControl.setMinimumInputPowerFractionforContinuousDimmingControl(*d); |
| 181 | } | ||
| 182 | |||
| 183 |
1/1✓ Branch 1 taken 16 times.
|
16 | d = workspaceObject.getDouble(Daylighting_ControlsFields::MinimumLightOutputFractionforContinuousorContinuousOffDimmingControl); |
| 184 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 2 times.
|
16 | if (d) { |
| 185 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
|
14 | daylightingControl.setMinimumLightOutputFractionforContinuousDimmingControl(*d); |
| 186 | } | ||
| 187 | |||
| 188 |
1/1✓ Branch 1 taken 16 times.
|
16 | OptionalInt i = workspaceObject.getInt(Daylighting_ControlsFields::NumberofSteppedControlSteps); |
| 189 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 6 times.
|
16 | if (i) { |
| 190 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
|
10 | daylightingControl.setNumberofSteppedControlSteps(*i); |
| 191 | } | ||
| 192 | |||
| 193 |
1/1✓ Branch 1 taken 16 times.
|
16 | d = workspaceObject.getDouble(Daylighting_ControlsFields::ProbabilityLightingwillbeResetWhenNeededinManualSteppedControl); |
| 194 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 2 times.
|
16 | if (d) { |
| 195 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
|
14 | daylightingControl.setProbabilityLightingwillbeResetWhenNeededinManualSteppedControl(*d); |
| 196 | } | ||
| 197 | |||
| 198 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 7 times.
|
16 | if (isPrimary) { |
| 199 |
1/1✓ Branch 1 taken 9 times.
|
9 | d = group.getDouble(Daylighting_ControlsExtensibleFields::FractionofLightsControlledbyReferencePoint, true); |
| 200 |
3/6✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
|
18 | if (d && controlThermalZone) { |
| 201 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
|
9 | controlThermalZone->setPrimaryDaylightingControl(daylightingControl); |
| 202 |
3/3✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
|
9 | controlThermalZone->setFractionofZoneControlledbyPrimaryDaylightingControl(*d); |
| 203 | } | ||
| 204 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | } else if (isSecondary) { |
| 205 |
1/1✓ Branch 1 taken 7 times.
|
7 | d = group.getDouble(Daylighting_ControlsExtensibleFields::FractionofLightsControlledbyReferencePoint, true); |
| 206 |
3/6✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
14 | if (d && controlThermalZone) { |
| 207 |
2/2✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
|
7 | controlThermalZone->setSecondaryDaylightingControl(daylightingControl); |
| 208 |
3/3✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
✓ Branch 7 taken 7 times.
|
7 | controlThermalZone->setFractionofZoneControlledbyPrimaryDaylightingControl(*d); |
| 209 | } | ||
| 210 | } else { | ||
| 211 | ✗ | d = group.getDouble(Daylighting_ControlsExtensibleFields::FractionofLightsControlledbyReferencePoint, true); | |
| 212 | ✗ | if (d && d.get() > 0) { | |
| 213 | ✗ | LOG(Warn, "Daylighting:Controls '" << workspaceObject.nameString() << "' reference point " << index << ", fraction of zone controlled " | |
| 214 | << *d << " not translated."); | ||
| 215 | } | ||
| 216 | } | ||
| 217 | 16 | } | |
| 218 | |||
| 219 | 9 | return result; | |
| 220 | 9 | } | |
| 221 | |||
| 222 | } // namespace energyplus | ||
| 223 | |||
| 224 | } // namespace openstudio | ||
| 225 |