src/model/SurfacePropertyGroundSurfaces.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 "SurfacePropertyGroundSurfaces.hpp" | ||
| 7 | #include "SurfacePropertyGroundSurfaces_Impl.hpp" | ||
| 8 | |||
| 9 | #include "Schedule.hpp" | ||
| 10 | #include "Schedule_Impl.hpp" | ||
| 11 | #include "ScheduleTypeLimits.hpp" | ||
| 12 | #include "ScheduleTypeRegistry.hpp" | ||
| 13 | #include "ModelExtensibleGroup.hpp" | ||
| 14 | #include "SurfacePropertyLocalEnvironment.hpp" | ||
| 15 | #include "SurfacePropertyLocalEnvironment_Impl.hpp" | ||
| 16 | |||
| 17 | #include <utilities/idd/IddEnums.hxx> | ||
| 18 | #include <utilities/idd/OS_SurfaceProperty_GroundSurfaces_FieldEnums.hxx> | ||
| 19 | #include <utility> | ||
| 20 | |||
| 21 | #include "../utilities/core/Assert.hpp" | ||
| 22 | |||
| 23 | namespace openstudio { | ||
| 24 | namespace model { | ||
| 25 | |||
| 26 | /*************************************************************************************************************************************************** | ||
| 27 | * G R O U N D S U R F A C E G R O U P W R A P P E R * | ||
| 28 | **************************************************************************************************************************************************/ | ||
| 29 | |||
| 30 | 45 | GroundSurfaceGroup::GroundSurfaceGroup(std::string groundSurfaceName, double viewFactor, boost::optional<Schedule> temperatureSchedule, | |
| 31 | 45 | boost::optional<Schedule> reflectanceSchedule) | |
| 32 | 45 | : m_groundSurfaceName(std::move(groundSurfaceName)), | |
| 33 | 45 | m_viewFactor(viewFactor), | |
| 34 | 45 | m_temperatureSch(std::move(temperatureSchedule)), | |
| 35 | 45 | m_reflectanceSch(std::move(reflectanceSchedule)) { | |
| 36 | |||
| 37 | // Matches the maximum value in IDD | ||
| 38 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 44 times.
|
45 | if (m_viewFactor > 1) { |
| 39 |
17/17✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 16 taken 1 time.
✓ Branch 19 taken 1 time.
✓ Branch 25 taken 1 time.
✓ Branch 28 taken 1 time.
✓ Branch 31 taken 1 time.
✓ Branch 34 taken 1 time.
✓ Branch 37 taken 1 time.
✓ Branch 40 taken 1 time.
✓ Branch 43 taken 1 time.
✓ Branch 46 taken 1 time.
✓ Branch 50 taken 1 time.
✓ Branch 53 taken 1 time.
|
1 | LOG_AND_THROW("Unable to create GroundSurfaceGroup, View Factor of " << m_viewFactor << " cannot be more than 1."); |
| 40 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
|
44 | } else if (m_viewFactor < 0) { |
| 41 | ✗ | LOG_AND_THROW("Unable to create GroundSurfaceGroup, View Factor of " << m_viewFactor << " cannot be less than 0."); | |
| 42 | } | ||
| 43 | |||
| 44 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 44 times.
|
44 | if (m_groundSurfaceName.empty()) { |
| 45 | ✗ | LOG_AND_THROW("Unable to create GroundSurfaceGroup, GroundSurfaceName cannot be empty."); | |
| 46 | } | ||
| 47 | 47 | } | |
| 48 | |||
| 49 | 68 | std::string GroundSurfaceGroup::groundSurfaceName() const { | |
| 50 | 68 | return m_groundSurfaceName; | |
| 51 | } | ||
| 52 | |||
| 53 | 48 | double GroundSurfaceGroup::viewFactor() const { | |
| 54 | 48 | return m_viewFactor; | |
| 55 | } | ||
| 56 | |||
| 57 | 64 | boost::optional<Schedule> GroundSurfaceGroup::temperatureSchedule() const { | |
| 58 | 64 | return m_temperatureSch; | |
| 59 | } | ||
| 60 | |||
| 61 | 56 | boost::optional<Schedule> GroundSurfaceGroup::reflectanceSchedule() const { | |
| 62 | 56 | return m_reflectanceSch; | |
| 63 | } | ||
| 64 | |||
| 65 | 4 | std::ostream& operator<<(std::ostream& out, const openstudio::model::GroundSurfaceGroup& groundSurfaceGroup) { | |
| 66 |
7/7✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
✓ Branch 8 taken 4 times.
✓ Branch 11 taken 4 times.
✓ Branch 14 taken 4 times.
✓ Branch 17 taken 4 times.
✓ Branch 20 taken 4 times.
|
4 | out << "(Surface = '" << groundSurfaceGroup.groundSurfaceName() << "', " << "View Factor = " << groundSurfaceGroup.viewFactor() << ", "; |
| 67 |
2/3✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
|
8 | if (groundSurfaceGroup.temperatureSchedule()) { |
| 68 |
5/5✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
✓ Branch 8 taken 4 times.
✓ Branch 11 taken 4 times.
✓ Branch 14 taken 4 times.
|
4 | out << "Temperature Schedule = '" << groundSurfaceGroup.temperatureSchedule()->nameString() << "', "; |
| 69 | } else { | ||
| 70 | ✗ | out << "No Temperature Schedule Assigned, "; | |
| 71 | } | ||
| 72 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 2 times.
|
8 | if (groundSurfaceGroup.reflectanceSchedule()) { |
| 73 |
5/5✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 8 taken 2 times.
✓ Branch 11 taken 2 times.
✓ Branch 14 taken 2 times.
|
2 | out << "Reflectance Schedule = '" << groundSurfaceGroup.reflectanceSchedule()->nameString() << "')"; |
| 74 | } else { | ||
| 75 | 2 | out << "No Reflectance Schedule Assigned)"; | |
| 76 | } | ||
| 77 | 4 | return out; | |
| 78 | } | ||
| 79 | |||
| 80 | namespace detail { | ||
| 81 | |||
| 82 | 4 | SurfacePropertyGroundSurfaces_Impl::SurfacePropertyGroundSurfaces_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) | |
| 83 | 4 | : ModelObject_Impl(idfObject, model, keepHandle) { | |
| 84 |
4/6✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 4 times.
✗ Branch 13 not taken.
|
4 | OS_ASSERT(idfObject.iddObject().type() == SurfacePropertyGroundSurfaces::iddObjectType()); |
| 85 | 4 | } | |
| 86 | |||
| 87 | ✗ | SurfacePropertyGroundSurfaces_Impl::SurfacePropertyGroundSurfaces_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, | |
| 88 | ✗ | bool keepHandle) | |
| 89 | ✗ | : ModelObject_Impl(other, model, keepHandle) { | |
| 90 | ✗ | OS_ASSERT(other.iddObject().type() == SurfacePropertyGroundSurfaces::iddObjectType()); | |
| 91 | ✗ | } | |
| 92 | |||
| 93 | 2 | SurfacePropertyGroundSurfaces_Impl::SurfacePropertyGroundSurfaces_Impl(const SurfacePropertyGroundSurfaces_Impl& other, Model_Impl* model, | |
| 94 | 2 | bool keepHandle) | |
| 95 | 2 | : ModelObject_Impl(other, model, keepHandle) {} | |
| 96 | |||
| 97 | ✗ | const std::vector<std::string>& SurfacePropertyGroundSurfaces_Impl::outputVariableNames() const { | |
| 98 | static const std::vector<std::string> result{"Surfaces Property Ground Surfaces Average Temperature", | ||
| 99 | ✗ | "Surfaces Property Ground Surfaces Average Reflectance"}; | |
| 100 | ✗ | return result; | |
| 101 | ✗ | } | |
| 102 | |||
| 103 | ✗ | IddObjectType SurfacePropertyGroundSurfaces_Impl::iddObjectType() const { | |
| 104 | ✗ | return SurfacePropertyGroundSurfaces::iddObjectType(); | |
| 105 | } | ||
| 106 | |||
| 107 | ✗ | std::vector<ScheduleTypeKey> SurfacePropertyGroundSurfaces_Impl::getScheduleTypeKeys(const Schedule& schedule) const { | |
| 108 | ✗ | std::vector<ScheduleTypeKey> result; | |
| 109 | |||
| 110 | // This is unusual, but the schedule is in the Extensible Fields (and only there) | ||
| 111 | // UnsignedVector fieldIndices = getSourceIndices(schedule.handle()); | ||
| 112 | ✗ | UnsignedVector fieldIndices; | |
| 113 | ✗ | for (const ModelExtensibleGroup& group : castVector<ModelExtensibleGroup>(extensibleGroups())) { | |
| 114 | ✗ | UnsignedVector thisFieldIndices = group.getSourceFieldIndices(schedule.handle()); | |
| 115 | ✗ | fieldIndices.insert(fieldIndices.end(), thisFieldIndices.begin(), thisFieldIndices.end()); | |
| 116 | ✗ | } | |
| 117 | |||
| 118 | // Make unique, have to sort before calling unique, unique only works on consecutive elements | ||
| 119 | ✗ | std::sort(fieldIndices.begin(), fieldIndices.end()); | |
| 120 | ✗ | fieldIndices.erase(std::unique(fieldIndices.begin(), fieldIndices.end()), fieldIndices.end()); | |
| 121 | |||
| 122 | ✗ | UnsignedVector::const_iterator b(fieldIndices.begin()); | |
| 123 | ✗ | UnsignedVector::const_iterator e(fieldIndices.end()); | |
| 124 | ✗ | if (std::find(b, e, OS_SurfaceProperty_GroundSurfacesExtensibleFields::GroundSurfaceTemperatureScheduleName) != e) { | |
| 125 | ✗ | result.emplace_back("SurfacePropertyGroundSurfaces", "Ground Surface Temperature"); | |
| 126 | ✗ | } else if (std::find(b, e, OS_SurfaceProperty_GroundSurfacesExtensibleFields::GroundSurfaceReflectanceScheduleName) != e) { | |
| 127 | ✗ | result.emplace_back("SurfacePropertyGroundSurfaces", "Ground Surface Reflectance"); | |
| 128 | } | ||
| 129 | |||
| 130 | ✗ | return result; | |
| 131 | ✗ | } | |
| 132 | |||
| 133 | // Extensible groups | ||
| 134 | |||
| 135 | 72 | unsigned int SurfacePropertyGroundSurfaces_Impl::numberofGroundSurfaceGroups() const { | |
| 136 | 72 | return numExtensibleGroups(); | |
| 137 | } | ||
| 138 | |||
| 139 | 21 | boost::optional<unsigned> SurfacePropertyGroundSurfaces_Impl::groundSurfaceGroupIndex(const std::string& groundSurfaceName) const { | |
| 140 | 21 | boost::optional<unsigned> result; | |
| 141 | |||
| 142 | // Find with custom predicate, checking handle equality between the toSurface and the fromSurface pairs | ||
| 143 | // We do it with extensibleGroups() (rather than groundSurfaceGroups()) and getString to avoid overhead | ||
| 144 | // of manipulating actual model objects (getTarget, then create a GroundSurfaceGroups wrapper, get handle convert to string...) | ||
| 145 | // and speed up the routine | ||
| 146 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | auto egs = castVector<WorkspaceExtensibleGroup>(extensibleGroups()); |
| 147 |
1/1✓ Branch 3 taken 21 times.
|
21 | auto it = std::find_if(egs.begin(), egs.end(), [&groundSurfaceName](const WorkspaceExtensibleGroup& eg) { |
| 148 |
3/3✓ Branch 1 taken 37 times.
✓ Branch 4 taken 37 times.
✓ Branch 7 taken 37 times.
|
37 | return openstudio::istringEqual(eg.getField(OS_SurfaceProperty_GroundSurfacesExtensibleFields::GroundSurfaceName).get(), groundSurfaceName); |
| 149 | }); | ||
| 150 | |||
| 151 | // If found, we compute the index by using std::distance between the start of vector and the iterator returned by std::find_if | ||
| 152 |
2/2✓ Branch 2 taken 4 times.
✓ Branch 3 taken 17 times.
|
21 | if (it != egs.end()) { |
| 153 |
1/1✓ Branch 2 taken 4 times.
|
8 | result = std::distance(egs.begin(), it); |
| 154 | } | ||
| 155 | |||
| 156 | 21 | return result; | |
| 157 | 21 | } | |
| 158 | |||
| 159 | 20 | boost::optional<unsigned> SurfacePropertyGroundSurfaces_Impl::groundSurfaceGroupIndex(const GroundSurfaceGroup& groundSurfaceGroup) const { | |
| 160 |
2/2✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
|
20 | return groundSurfaceGroupIndex(groundSurfaceGroup.groundSurfaceName()); |
| 161 | } | ||
| 162 | |||
| 163 | 26 | boost::optional<GroundSurfaceGroup> SurfacePropertyGroundSurfaces_Impl::getGroundSurfaceGroup(unsigned groupIndex) const { | |
| 164 | |||
| 165 | 26 | boost::optional<GroundSurfaceGroup> result; | |
| 166 | |||
| 167 |
3/3✓ Branch 1 taken 26 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 25 times.
|
26 | if (groupIndex >= numberofGroundSurfaceGroups()) { |
| 168 |
13/13✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 16 taken 1 time.
✓ Branch 19 taken 1 time.
✓ Branch 22 taken 1 time.
✓ Branch 25 taken 1 time.
✓ Branch 28 taken 1 time.
✓ Branch 32 taken 1 time.
✓ Branch 35 taken 1 time.
✓ Branch 38 taken 1 time.
|
1 | LOG(Error, "Asked to get GroundSurfaceGroup with index " << groupIndex << ", but " << briefDescription() << " has just " |
| 169 | << numberofGroundSurfaceGroups() << " GroundSurfaceGroups."); | ||
| 170 | 1 | return result; | |
| 171 | } | ||
| 172 | |||
| 173 |
2/2✓ Branch 1 taken 25 times.
✓ Branch 4 taken 25 times.
|
25 | auto group = getExtensibleGroup(groupIndex).cast<ModelExtensibleGroup>(); |
| 174 | |||
| 175 |
1/1✓ Branch 1 taken 25 times.
|
25 | boost::optional<std::string> surfaceName_ = group.getString(OS_SurfaceProperty_GroundSurfacesExtensibleFields::GroundSurfaceName); |
| 176 |
1/1✓ Branch 1 taken 25 times.
|
25 | boost::optional<double> viewFactor_ = group.getDouble(OS_SurfaceProperty_GroundSurfacesExtensibleFields::GroundSurfaceViewFactor); |
| 177 | boost::optional<Schedule> tempSch_ = | ||
| 178 |
1/1✓ Branch 1 taken 25 times.
|
25 | group.getModelObjectTarget<Schedule>(OS_SurfaceProperty_GroundSurfacesExtensibleFields::GroundSurfaceTemperatureScheduleName); |
| 179 | |||
| 180 | boost::optional<Schedule> reflectanceSch_ = | ||
| 181 |
1/1✓ Branch 1 taken 25 times.
|
25 | group.getModelObjectTarget<Schedule>(OS_SurfaceProperty_GroundSurfacesExtensibleFields::GroundSurfaceReflectanceScheduleName); |
| 182 | |||
| 183 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
|
25 | if (!surfaceName_) { |
| 184 | ✗ | LOG(Error, "Could not retrieve GroundSurfaceName for extensible group " << group.groupIndex() << "."); | |
| 185 | } | ||
| 186 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
|
25 | if (!viewFactor_) { |
| 187 | ✗ | LOG(Error, "Could not retrieve GroundSurfaceViewFactor for extensible group " << group.groupIndex() << "."); | |
| 188 | } | ||
| 189 | |||
| 190 | // Schedules are optional | ||
| 191 | |||
| 192 |
7/7✓ Branch 1 taken 25 times.
✓ Branch 4 taken 25 times.
✓ Branch 7 taken 25 times.
✓ Branch 10 taken 25 times.
✓ Branch 13 taken 25 times.
✓ Branch 16 taken 25 times.
✓ Branch 19 taken 25 times.
|
25 | result = GroundSurfaceGroup(surfaceName_.get(), viewFactor_.get(), tempSch_, reflectanceSch_); |
| 193 | |||
| 194 | 25 | return result; | |
| 195 | 25 | } | |
| 196 | |||
| 197 | 18 | bool SurfacePropertyGroundSurfaces_Impl::addGroundSurfaceGroup(const GroundSurfaceGroup& groundSurfaceGroup) { | |
| 198 | |||
| 199 | // Bounds checking happens in the GroundSurfaceGroup ctor | ||
| 200 | |||
| 201 | // Check if viewFactor already exists | ||
| 202 |
1/1✓ Branch 1 taken 18 times.
|
18 | boost::optional<unsigned> _existingIndex = groundSurfaceGroupIndex(groundSurfaceGroup); |
| 203 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
|
18 | if (_existingIndex) { |
| 204 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | boost::optional<GroundSurfaceGroup> _group = getGroundSurfaceGroup(_existingIndex.get()); |
| 205 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
|
2 | OS_ASSERT(_group); |
| 206 |
13/13✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
✓ Branch 19 taken 2 times.
✓ Branch 22 taken 2 times.
✓ Branch 25 taken 2 times.
✓ Branch 28 taken 2 times.
✓ Branch 32 taken 2 times.
✓ Branch 35 taken 2 times.
✓ Branch 38 taken 2 times.
|
2 | LOG(Warn, "For " << briefDescription() << ", GroundSurfaceGroup already exists, will be modified in place from " << _group.get() << " to " |
| 207 | << groundSurfaceGroup << "."); | ||
| 208 | 2 | } | |
| 209 | |||
| 210 | // If existing, get it, otherwise Push an extensible group. ModelExtensibleGroup cannot be default-constructed, so use a ternary operator | ||
| 211 | // Given that we will potentially push many extensible groups | ||
| 212 | // we will suffer from going through the internal checks in WorkspaceObject, especially in setPointer, | ||
| 213 | // and performance will be roughly O(n^2) when adding groups. | ||
| 214 | // So to improve the performance we pushExtensible group without validity check, and call setPointer without validity check (`isValid`) | ||
| 215 | 18 | std::vector<std::string> temp; | |
| 216 |
2/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
4 | ModelExtensibleGroup eg = (_existingIndex ? getExtensibleGroup(_existingIndex.get()).cast<ModelExtensibleGroup>() |
| 217 |
9/11✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
✓ Branch 3 taken 2 times.
✓ Branch 6 taken 16 times.
✓ Branch 9 taken 16 times.
✓ Branch 11 taken 16 times.
✓ Branch 12 taken 2 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 16 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
20 | : pushExtensibleGroup(temp, false).cast<ModelExtensibleGroup>()); |
| 218 | |||
| 219 | 18 | bool result = false; | |
| 220 | |||
| 221 |
2/2✓ Branch 1 taken 18 times.
✓ Branch 4 taken 18 times.
|
18 | bool surfaceNameOk = eg.setString(OS_SurfaceProperty_GroundSurfacesExtensibleFields::GroundSurfaceName, groundSurfaceGroup.groundSurfaceName()); |
| 222 | |||
| 223 |
2/2✓ Branch 1 taken 18 times.
✓ Branch 4 taken 18 times.
|
18 | bool viewFactorOk = eg.setDouble(OS_SurfaceProperty_GroundSurfacesExtensibleFields::GroundSurfaceViewFactor, groundSurfaceGroup.viewFactor()); |
| 224 | |||
| 225 | 18 | bool schTempOk = true; | |
| 226 |
3/3✓ Branch 1 taken 18 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 6 times.
|
36 | if (auto sch_ = groundSurfaceGroup.temperatureSchedule()) { |
| 227 |
3/3✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
|
12 | schTempOk = eg.setPointer(OS_SurfaceProperty_GroundSurfacesExtensibleFields::GroundSurfaceTemperatureScheduleName, sch_->handle(), false); |
| 228 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | if (!schTempOk) { |
| 229 | ✗ | LOG(Error, "Unable to add Ground Surface Group which has an incompatible Temperature Schedule to " << briefDescription()); | |
| 230 | ✗ | OS_ASSERT(false); | |
| 231 | } | ||
| 232 | } else { | ||
| 233 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
12 | eg.setString(OS_SurfaceProperty_GroundSurfacesExtensibleFields::GroundSurfaceTemperatureScheduleName, ""); |
| 234 | 18 | } | |
| 235 | |||
| 236 | 18 | bool schRefOk = true; | |
| 237 |
3/3✓ Branch 1 taken 18 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 9 times.
|
36 | if (auto sch_ = groundSurfaceGroup.reflectanceSchedule()) { |
| 238 |
3/3✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
|
9 | schRefOk = eg.setPointer(OS_SurfaceProperty_GroundSurfacesExtensibleFields::GroundSurfaceReflectanceScheduleName, sch_->handle(), false); |
| 239 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (!schRefOk) { |
| 240 | ✗ | LOG(Error, "Unable to add Ground Surface Group which has an incompatible Reflectance Schedule to " << briefDescription()); | |
| 241 | |||
| 242 | ✗ | OS_ASSERT(false); | |
| 243 | } | ||
| 244 | } else { | ||
| 245 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
|
18 | eg.setString(OS_SurfaceProperty_GroundSurfacesExtensibleFields::GroundSurfaceReflectanceScheduleName, ""); |
| 246 | 18 | } | |
| 247 | |||
| 248 |
4/8✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 18 times.
✗ Branch 7 not taken.
|
18 | if (surfaceNameOk && viewFactorOk && schTempOk && schRefOk) { |
| 249 | 18 | result = true; | |
| 250 | } else { | ||
| 251 | // Something went wrong | ||
| 252 | // So erase the new extensible group | ||
| 253 | ✗ | getObject<ModelObject>().eraseExtensibleGroup(eg.groupIndex()); | |
| 254 | ✗ | result = false; | |
| 255 | } | ||
| 256 | 18 | return result; | |
| 257 | 18 | } | |
| 258 | |||
| 259 | // Overloads, it creates a GroundSurfaceGroup wrapper, then call `addGroundSurfaceGroup(const GroundSurfaceGroup& groundSurfaceGroup)` | ||
| 260 | 9 | bool SurfacePropertyGroundSurfaces_Impl::addGroundSurfaceGroup(const std::string& groundSurfaceName, double viewFactor, | |
| 261 | boost::optional<Schedule> temperatureSchedule, | ||
| 262 | boost::optional<Schedule> reflectanceSchedule) { | ||
| 263 |
2/2✓ Branch 5 taken 9 times.
✓ Branch 8 taken 9 times.
|
9 | GroundSurfaceGroup groundSurfaceGroup(groundSurfaceName, viewFactor, std::move(temperatureSchedule), std::move(reflectanceSchedule)); |
| 264 |
1/1✓ Branch 1 taken 9 times.
|
18 | return addGroundSurfaceGroup(groundSurfaceGroup); |
| 265 | 9 | } | |
| 266 | |||
| 267 | 1 | bool SurfacePropertyGroundSurfaces_Impl::addGroundSurfaceGroups(const std::vector<GroundSurfaceGroup>& groundSurfaceGroups) { | |
| 268 | 1 | bool result = true; | |
| 269 | |||
| 270 |
2/2✓ Branch 5 taken 3 times.
✓ Branch 6 taken 1 time.
|
4 | for (const auto& groundSurfaceGroup : groundSurfaceGroups) { |
| 271 |
1/1✓ Branch 1 taken 3 times.
|
3 | bool thisResult = addGroundSurfaceGroup(groundSurfaceGroup); |
| 272 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (!thisResult) { |
| 273 | ✗ | LOG(Error, "Could not add groundSurfaceGroup " << groundSurfaceGroup << " to " << briefDescription() << ". Continuing with others."); | |
| 274 | // OS_ASSERT(false); | ||
| 275 | // result = false; | ||
| 276 | } | ||
| 277 | } | ||
| 278 | |||
| 279 | 1 | return result; | |
| 280 | } | ||
| 281 | |||
| 282 | 3 | bool SurfacePropertyGroundSurfaces_Impl::removeGroundSurfaceGroup(unsigned groupIndex) { | |
| 283 | 3 | bool result = false; | |
| 284 | |||
| 285 | 3 | unsigned int num = numberofGroundSurfaceGroups(); | |
| 286 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 2 times.
|
3 | if (groupIndex < num) { |
| 287 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | getObject<ModelObject>().eraseExtensibleGroup(groupIndex); |
| 288 | 1 | result = true; | |
| 289 | } | ||
| 290 | 3 | return result; | |
| 291 | } | ||
| 292 | |||
| 293 | 1 | void SurfacePropertyGroundSurfaces_Impl::removeAllGroundSurfaceGroups() { | |
| 294 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | getObject<ModelObject>().clearExtensibleGroups(); |
| 295 | 1 | } | |
| 296 | |||
| 297 | 5 | std::vector<GroundSurfaceGroup> SurfacePropertyGroundSurfaces_Impl::groundSurfaceGroups() const { | |
| 298 | 5 | std::vector<GroundSurfaceGroup> result; | |
| 299 | |||
| 300 |
3/3✓ Branch 1 taken 25 times.
✓ Branch 3 taken 20 times.
✓ Branch 4 taken 5 times.
|
25 | for (unsigned i = 0; i < numberofGroundSurfaceGroups(); ++i) { |
| 301 | |||
| 302 |
1/1✓ Branch 1 taken 20 times.
|
20 | boost::optional<GroundSurfaceGroup> group_ = getGroundSurfaceGroup(i); |
| 303 | |||
| 304 | // getViewFactor is responsible for handling error and issuing Error log messages. | ||
| 305 | // Here we add it to the result array if it worked, and if it didn't, we keep going | ||
| 306 | // We just issue a message about index so user can delete it easily | ||
| 307 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | if (group_) { |
| 308 |
2/2✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
|
20 | result.push_back(group_.get()); |
| 309 | } else { | ||
| 310 | ✗ | LOG(Error, briefDescription() << " has an invalid GroundSurfaceGroup group at index " << i); | |
| 311 | } | ||
| 312 | 20 | } | |
| 313 | |||
| 314 | 5 | return result; | |
| 315 | ✗ | } | |
| 316 | |||
| 317 | // Helper | ||
| 318 | 3 | boost::optional<SurfacePropertyLocalEnvironment> SurfacePropertyGroundSurfaces_Impl::surfacePropertyLocalEnvironment() const { | |
| 319 | std::vector<SurfacePropertyLocalEnvironment> localEnvs = | ||
| 320 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | getObject<ModelObject>().getModelObjectSources<SurfacePropertyLocalEnvironment>(SurfacePropertyLocalEnvironment::iddObjectType()); |
| 321 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 2 times.
|
3 | if (localEnvs.empty()) { |
| 322 | 1 | return boost::none; | |
| 323 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | } else if (localEnvs.size() == 1) { |
| 324 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | return localEnvs.at(0); |
| 325 | } else { | ||
| 326 | ✗ | LOG(Error, "More than one SurfacePropertyLocalEnvironments point to this SurfacePropertyGroundSurfaces"); | |
| 327 | ✗ | return boost::none; | |
| 328 | } | ||
| 329 | 3 | } | |
| 330 | |||
| 331 | } // namespace detail | ||
| 332 | |||
| 333 | 4 | SurfacePropertyGroundSurfaces::SurfacePropertyGroundSurfaces(const Model& model) | |
| 334 | 4 | : ModelObject(SurfacePropertyGroundSurfaces::iddObjectType(), model) { | |
| 335 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 5 not taken.
|
4 | OS_ASSERT(getImpl<detail::SurfacePropertyGroundSurfaces_Impl>()); |
| 336 | 4 | } | |
| 337 | |||
| 338 | 7737 | IddObjectType SurfacePropertyGroundSurfaces::iddObjectType() { | |
| 339 |
1/1✓ Branch 1 taken 7737 times.
|
7737 | return {IddObjectType::OS_SurfaceProperty_GroundSurfaces}; |
| 340 | } | ||
| 341 | |||
| 342 | // Extensible fields | ||
| 343 | |||
| 344 | 5 | std::vector<GroundSurfaceGroup> SurfacePropertyGroundSurfaces::groundSurfaceGroups() const { | |
| 345 |
1/1✓ Branch 3 taken 5 times.
|
5 | return getImpl<detail::SurfacePropertyGroundSurfaces_Impl>()->groundSurfaceGroups(); |
| 346 | } | ||
| 347 | |||
| 348 | 17 | unsigned int SurfacePropertyGroundSurfaces::numberofGroundSurfaceGroups() const { | |
| 349 |
1/1✓ Branch 3 taken 17 times.
|
17 | return getImpl<detail::SurfacePropertyGroundSurfaces_Impl>()->numberofGroundSurfaceGroups(); |
| 350 | } | ||
| 351 | |||
| 352 | 2 | boost::optional<unsigned> SurfacePropertyGroundSurfaces::groundSurfaceGroupIndex(const GroundSurfaceGroup& groundSurfaceGroup) const { | |
| 353 |
1/1✓ Branch 3 taken 2 times.
|
2 | return getImpl<detail::SurfacePropertyGroundSurfaces_Impl>()->groundSurfaceGroupIndex(groundSurfaceGroup); |
| 354 | } | ||
| 355 | 1 | boost::optional<unsigned> SurfacePropertyGroundSurfaces::groundSurfaceGroupIndex(const std::string& groundSurfaceName) const { | |
| 356 |
1/1✓ Branch 3 taken 1 time.
|
1 | return getImpl<detail::SurfacePropertyGroundSurfaces_Impl>()->groundSurfaceGroupIndex(groundSurfaceName); |
| 357 | } | ||
| 358 | |||
| 359 | 4 | boost::optional<GroundSurfaceGroup> SurfacePropertyGroundSurfaces::getGroundSurfaceGroup(unsigned groupIndex) const { | |
| 360 |
1/1✓ Branch 3 taken 4 times.
|
4 | return getImpl<detail::SurfacePropertyGroundSurfaces_Impl>()->getGroundSurfaceGroup(groupIndex); |
| 361 | } | ||
| 362 | |||
| 363 | 6 | bool SurfacePropertyGroundSurfaces::addGroundSurfaceGroup(const GroundSurfaceGroup& groundSurfaceGroup) { | |
| 364 |
1/1✓ Branch 3 taken 6 times.
|
6 | return getImpl<detail::SurfacePropertyGroundSurfaces_Impl>()->addGroundSurfaceGroup(groundSurfaceGroup); |
| 365 | } | ||
| 366 | |||
| 367 | // Overloads, it creates a GroundSurfaceGroup wrapper, then call `addGroundSurfaceGroup(const GroundSurfaceGroup& groundSurfaceGroup)` | ||
| 368 | 9 | bool SurfacePropertyGroundSurfaces::addGroundSurfaceGroup(const std::string& groundSurfaceName, double viewFactor, | |
| 369 | boost::optional<Schedule> temperatureSchedule, | ||
| 370 | boost::optional<Schedule> reflectanceSchedule) { | ||
| 371 |
1/1✓ Branch 6 taken 9 times.
|
27 | return getImpl<detail::SurfacePropertyGroundSurfaces_Impl>()->addGroundSurfaceGroup(groundSurfaceName, viewFactor, std::move(temperatureSchedule), |
| 372 | 27 | std::move(reflectanceSchedule)); | |
| 373 | } | ||
| 374 | |||
| 375 | 1 | bool SurfacePropertyGroundSurfaces::addGroundSurfaceGroups(const std::vector<GroundSurfaceGroup>& groundSurfaceGroups) { | |
| 376 |
1/1✓ Branch 3 taken 1 time.
|
1 | return getImpl<detail::SurfacePropertyGroundSurfaces_Impl>()->addGroundSurfaceGroups(groundSurfaceGroups); |
| 377 | } | ||
| 378 | |||
| 379 | 3 | bool SurfacePropertyGroundSurfaces::removeGroundSurfaceGroup(unsigned groupIndex) { | |
| 380 |
1/1✓ Branch 3 taken 3 times.
|
3 | return getImpl<detail::SurfacePropertyGroundSurfaces_Impl>()->removeGroundSurfaceGroup(groupIndex); |
| 381 | } | ||
| 382 | |||
| 383 | 1 | void SurfacePropertyGroundSurfaces::removeAllGroundSurfaceGroups() { | |
| 384 |
1/1✓ Branch 3 taken 1 time.
|
1 | getImpl<detail::SurfacePropertyGroundSurfaces_Impl>()->removeAllGroundSurfaceGroups(); |
| 385 | 1 | } | |
| 386 | |||
| 387 | 3 | boost::optional<SurfacePropertyLocalEnvironment> SurfacePropertyGroundSurfaces::surfacePropertyLocalEnvironment() const { | |
| 388 |
1/1✓ Branch 3 taken 3 times.
|
3 | return getImpl<detail::SurfacePropertyGroundSurfaces_Impl>()->surfacePropertyLocalEnvironment(); |
| 389 | } | ||
| 390 | |||
| 391 | /// @cond | ||
| 392 | 7 | SurfacePropertyGroundSurfaces::SurfacePropertyGroundSurfaces(std::shared_ptr<detail::SurfacePropertyGroundSurfaces_Impl> impl) | |
| 393 |
1/1✓ Branch 3 taken 7 times.
|
7 | : ModelObject(std::move(impl)) {} |
| 394 | /// @endcond | ||
| 395 | |||
| 396 | } // namespace model | ||
| 397 | } // namespace openstudio | ||
| 398 |