src/radiance/WindowGroup.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 "WindowGroup.hpp" | ||
| 7 | #include "ForwardTranslator.hpp" | ||
| 8 | |||
| 9 | #include "../model/ShadingControl.hpp" | ||
| 10 | #include "../model/Construction.hpp" | ||
| 11 | #include "../model/Material.hpp" | ||
| 12 | #include "../model/Material_Impl.hpp" | ||
| 13 | #include "../model/ShadingMaterial.hpp" | ||
| 14 | #include "../model/ShadingMaterial_Impl.hpp" | ||
| 15 | #include "../model/Blind.hpp" | ||
| 16 | #include "../model/Blind_Impl.hpp" | ||
| 17 | #include "../model/DaylightRedirectionDevice.hpp" | ||
| 18 | #include "../model/DaylightRedirectionDevice_Impl.hpp" | ||
| 19 | #include "../model/Screen.hpp" | ||
| 20 | #include "../model/Screen_Impl.hpp" | ||
| 21 | #include "../model/Shade.hpp" | ||
| 22 | #include "../model/Shade_Impl.hpp" | ||
| 23 | #include "../model/Schedule.hpp" | ||
| 24 | #include "../utilities/geometry/Geometry.hpp" | ||
| 25 | |||
| 26 | namespace openstudio { | ||
| 27 | namespace radiance { | ||
| 28 | |||
| 29 | 3 | WindowGroup::WindowGroup(const openstudio::Vector3d& outwardNormal, const model::Space& space, const model::ConstructionBase& construction, | |
| 30 | 3 | const boost::optional<model::ShadingControl>& shadingControl) | |
| 31 |
4/4✓ Branch 2 taken 3 times.
✓ Branch 5 taken 3 times.
✓ Branch 8 taken 3 times.
✓ Branch 11 taken 3 times.
|
3 | : m_outwardNormal(outwardNormal), m_space(space), m_construction(construction), m_shadingControl(shadingControl) { |
| 32 | // start with a gross name, forward translator is in charge of nice names | ||
| 33 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | m_name = "WG" + toString(createUUID()); |
| 34 |
1/1✓ Branch 1 taken 3 times.
|
3 | m_outwardNormal.normalize(); |
| 35 | 3 | } | |
| 36 | |||
| 37 | ✗ | bool WindowGroup::operator==(const WindowGroup& other) const { | |
| 38 | ✗ | if (!m_shadingControl && !other.shadingControl()) { | |
| 39 | |||
| 40 | ✗ | if (m_space.handle() == other.space().handle()) { | |
| 41 | ✗ | if (m_construction.handle() == other.construction().handle()) { | |
| 42 | ✗ | double angle = std::abs(radToDeg(getAngle(m_outwardNormal, other.outwardNormal()))); | |
| 43 | ✗ | const double tol = 1.0; | |
| 44 | ✗ | if (angle < tol) { | |
| 45 | ✗ | return true; | |
| 46 | } | ||
| 47 | } | ||
| 48 | } | ||
| 49 | ✗ | return false; | |
| 50 | |||
| 51 | ✗ | } else if (m_shadingControl && !other.shadingControl()) { | |
| 52 | ✗ | return false; | |
| 53 | ✗ | } else if (!m_shadingControl && other.shadingControl()) { | |
| 54 | ✗ | return false; | |
| 55 | } | ||
| 56 | |||
| 57 | ✗ | if (m_space.handle() == other.space().handle()) { | |
| 58 | ✗ | if (m_construction.handle() == other.construction().handle()) { | |
| 59 | ✗ | if (m_shadingControl->handle() == other.shadingControl()->handle()) { | |
| 60 | ✗ | double angle = std::abs(radToDeg(getAngle(m_outwardNormal, other.outwardNormal()))); | |
| 61 | ✗ | const double tol = 1.0; | |
| 62 | ✗ | if (angle < tol) { | |
| 63 | ✗ | return true; | |
| 64 | } | ||
| 65 | } | ||
| 66 | } | ||
| 67 | } | ||
| 68 | ✗ | return false; | |
| 69 | } | ||
| 70 | |||
| 71 | 15 | std::string WindowGroup::name() const { | |
| 72 | 15 | return m_name; | |
| 73 | } | ||
| 74 | |||
| 75 | 3 | void WindowGroup::setName(const std::string& name) { | |
| 76 | 3 | m_name = name; | |
| 77 | 3 | } | |
| 78 | |||
| 79 | ✗ | openstudio::Vector3d WindowGroup::outwardNormal() const { | |
| 80 | ✗ | return m_outwardNormal; | |
| 81 | } | ||
| 82 | |||
| 83 | ✗ | model::Space WindowGroup::space() const { | |
| 84 | ✗ | return m_space; | |
| 85 | } | ||
| 86 | |||
| 87 | ✗ | model::ConstructionBase WindowGroup::construction() const { | |
| 88 | ✗ | return m_construction; | |
| 89 | } | ||
| 90 | |||
| 91 | ✗ | boost::optional<model::ShadingControl> WindowGroup::shadingControl() const { | |
| 92 | ✗ | return m_shadingControl; | |
| 93 | } | ||
| 94 | |||
| 95 | ✗ | std::string WindowGroup::interiorShadeBSDF() const { | |
| 96 | ✗ | std::string result = "air.xml"; | |
| 97 | ✗ | if (m_shadingControl) { | |
| 98 | |||
| 99 | ✗ | std::string shadingType = m_shadingControl->shadingType(); | |
| 100 | ✗ | if (istringEqual("InteriorShade", shadingType)) { | |
| 101 | ✗ | result = "05_shadecloth_light.xml"; | |
| 102 | ✗ | } else if (istringEqual("ExteriorShade", shadingType)) { | |
| 103 | // shouldn't get here but use air if we do | ||
| 104 | ✗ | } else if (istringEqual("ExteriorScreen", shadingType)) { | |
| 105 | // shouldn't get here but use air if we do | ||
| 106 | ✗ | } else if (istringEqual("InteriorBlind", shadingType)) { | |
| 107 | ✗ | result = "blinds.xml"; | |
| 108 | ✗ | } else if (istringEqual("ExteriorBlind", shadingType)) { | |
| 109 | // shouldn't get here but use air if we do | ||
| 110 | ✗ | } else if (istringEqual("BetweenGlassShade", shadingType)) { | |
| 111 | // shouldn't get here but use air if we do | ||
| 112 | ✗ | } else if (istringEqual("BetweenGlassBlind", shadingType)) { | |
| 113 | // shouldn't get here but use air if we do | ||
| 114 | ✗ | } else if (istringEqual("SwitchableGlazing", shadingType)) { | |
| 115 | // shouldn't get here but use air if we do | ||
| 116 | ✗ | } else if (istringEqual("InteriorDaylightRedirectionDevice", shadingType)) { | |
| 117 | ✗ | result = "1xliloX.xml"; | |
| 118 | } else { | ||
| 119 | ✗ | LOG(Warn, "Unknown shadingType '" << shadingType << "' found for ShadingControl '" << m_shadingControl->name().get() << "'"); | |
| 120 | } | ||
| 121 | ✗ | } | |
| 122 | ✗ | return result; | |
| 123 | ✗ | } | |
| 124 | |||
| 125 | ✗ | std::string WindowGroup::shadingControlType() const { | |
| 126 | ✗ | std::string result = "AlwaysOff"; | |
| 127 | ✗ | if (m_shadingControl) { | |
| 128 | ✗ | result = m_shadingControl->shadingControlType(); | |
| 129 | |||
| 130 | ✗ | if (istringEqual("OnIfScheduleAllows", result)) { | |
| 131 | ✗ | result = "OnIfHighSolarOnWindow"; | |
| 132 | ✗ | LOG(Warn, "ShadingControlType 'OnIfHighSolarOnWindow' is not currently supported for ShadingControl '" | |
| 133 | << m_shadingControl->name().get() << "', using 'OnIfHighSolarOnWindow' instead."); | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | ✗ | return result; | |
| 138 | ✗ | } | |
| 139 | |||
| 140 | ✗ | std::string WindowGroup::shadingControlSetpoint() const { | |
| 141 | ✗ | std::string result = "n/a"; | |
| 142 | ✗ | if (m_shadingControl) { | |
| 143 | ✗ | std::string shadingControlType = this->shadingControlType(); | |
| 144 | |||
| 145 | ✗ | if (istringEqual("AlwaysOff", shadingControlType)) { | |
| 146 | ✗ | result = "n/a"; | |
| 147 | ✗ | } else if (istringEqual("AlwaysOn", shadingControlType)) { | |
| 148 | ✗ | result = "n/a"; | |
| 149 | ✗ | } else if (istringEqual("OnIfHighSolarOnWindow", shadingControlType)) { | |
| 150 | ✗ | boost::optional<double> d = m_shadingControl->setpoint(); | |
| 151 | ✗ | if (d) { | |
| 152 | ✗ | std::stringstream ss; | |
| 153 | ✗ | ss << *d; | |
| 154 | ✗ | result = ss.str(); | |
| 155 | ✗ | } else { | |
| 156 | // setting default in lux | ||
| 157 | ✗ | result = "5000"; | |
| 158 | } | ||
| 159 | ✗ | } else if (istringEqual("OnIfScheduleAllows", shadingControlType)) { | |
| 160 | ✗ | boost::optional<openstudio::model::Schedule> schedule = m_shadingControl->schedule(); | |
| 161 | ✗ | if (schedule) { | |
| 162 | ✗ | result = schedule->name().get(); | |
| 163 | } else { | ||
| 164 | ✗ | result = ""; | |
| 165 | } | ||
| 166 | ✗ | } else { | |
| 167 | ✗ | result = "n/a"; | |
| 168 | ✗ | LOG(Warn, "Unknown shadingControlType '" << shadingControlType << "' for ShadingControl '" << m_shadingControl->name().get() << "'."); | |
| 169 | } | ||
| 170 | ✗ | } | |
| 171 | |||
| 172 | ✗ | return result; | |
| 173 | ✗ | } | |
| 174 | |||
| 175 | 3 | void WindowGroup::addWindowPolygon(const openstudio::Point3dVector& windowPolygon) { | |
| 176 | 3 | m_windowPolygons.push_back(windowPolygon); | |
| 177 | 3 | } | |
| 178 | |||
| 179 | 3 | WindowGroupControl WindowGroup::windowGroupControl() const { | |
| 180 | 3 | boost::optional<double> largestArea; | |
| 181 | 3 | boost::optional<Point3d> centroid; | |
| 182 | 3 | boost::optional<Vector3d> outwardNormal; | |
| 183 | |||
| 184 |
2/2✓ Branch 5 taken 3 times.
✓ Branch 6 taken 3 times.
|
6 | for (const auto& windowPolygon : m_windowPolygons) { |
| 185 |
1/1✓ Branch 1 taken 3 times.
|
3 | boost::optional<double> area = getArea(windowPolygon); |
| 186 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (area) { |
| 187 |
2/8✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
|
3 | if (!largestArea || (*area > *largestArea)) { |
| 188 |
1/1✓ Branch 1 taken 3 times.
|
3 | boost::optional<Point3d> tmpCentroid = getCentroid(windowPolygon); |
| 189 |
1/1✓ Branch 1 taken 3 times.
|
3 | boost::optional<Vector3d> tmpOutwardNormal = getOutwardNormal(windowPolygon); |
| 190 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
6 | if (tmpCentroid && tmpOutwardNormal) { |
| 191 | 3 | largestArea = area; | |
| 192 |
1/1✓ Branch 1 taken 3 times.
|
3 | centroid = tmpCentroid; |
| 193 |
1/1✓ Branch 1 taken 3 times.
|
3 | outwardNormal = tmpOutwardNormal; |
| 194 | } | ||
| 195 | 3 | } | |
| 196 | } | ||
| 197 | } | ||
| 198 | |||
| 199 | 3 | WindowGroupControl result; | |
| 200 | 3 | result.largestArea = largestArea; | |
| 201 |
1/1✓ Branch 1 taken 3 times.
|
3 | result.centroid = centroid; |
| 202 |
1/1✓ Branch 1 taken 3 times.
|
3 | result.outwardNormal = outwardNormal; |
| 203 | |||
| 204 | 6 | return result; | |
| 205 | 3 | } | |
| 206 | |||
| 207 | ✗ | std::string WindowGroup::windowGroupPoints() const { | |
| 208 | ✗ | WindowGroupControl control = this->windowGroupControl(); | |
| 209 | |||
| 210 | ✗ | std::string result; | |
| 211 | ✗ | if (control.centroid && control.outwardNormal) { | |
| 212 | |||
| 213 | ✗ | double offset = 0.05; | |
| 214 | ✗ | Vector3d vec = control.outwardNormal.get(); | |
| 215 | ✗ | vec.setLength(offset); | |
| 216 | ✗ | Point3d wcPoint = control.centroid.get() + vec; | |
| 217 | |||
| 218 | ✗ | result = formatString(wcPoint.x()) + " " + formatString(wcPoint.y()) + " " + formatString(wcPoint.z()) + " " | |
| 219 | ✗ | + formatString(control.outwardNormal->x()) + " " + formatString(control.outwardNormal->y()) + " " | |
| 220 | ✗ | + formatString(control.outwardNormal->z()) + "\n"; | |
| 221 | ✗ | } | |
| 222 | |||
| 223 | ✗ | return result; | |
| 224 | ✗ | } | |
| 225 | |||
| 226 | } // namespace radiance | ||
| 227 | } // namespace openstudio | ||
| 228 |