src/model/ZoneMRTCalculation.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 "ZoneMRTCalculation.hpp" | ||
| 7 | #include "ZoneMRTCalculation_Impl.hpp" | ||
| 8 | #include "People.hpp" | ||
| 9 | #include "People_Impl.hpp" | ||
| 10 | #include "PeopleDefinition.hpp" | ||
| 11 | #include "PeopleDefinition_Impl.hpp" | ||
| 12 | #include "Space.hpp" | ||
| 13 | #include "Space_Impl.hpp" | ||
| 14 | #include "ThermalZone.hpp" | ||
| 15 | #include "ThermalZone_Impl.hpp" | ||
| 16 | |||
| 17 | #include "Model.hpp" | ||
| 18 | #include "Model_Impl.hpp" | ||
| 19 | |||
| 20 | #include "ModelExtensibleGroup.hpp" | ||
| 21 | |||
| 22 | #include <utilities/idd/IddEnums.hxx> | ||
| 23 | #include <utilities/idd/OS_ZoneMRTCalculation_FieldEnums.hxx> | ||
| 24 | |||
| 25 | #include "../utilities/core/Assert.hpp" | ||
| 26 | |||
| 27 | #include <algorithm> | ||
| 28 | |||
| 29 | namespace openstudio { | ||
| 30 | namespace model { | ||
| 31 | |||
| 32 | /***************************************************************************************************************************************************** | ||
| 33 | * M R T W E I G H T I N G F A C T O R * | ||
| 34 | *****************************************************************************************************************************************************/ | ||
| 35 | 37 | MRTWeightingFactor::MRTWeightingFactor(const People& people, double mRTWeightingFactor) | |
| 36 | 37 | : m_people(people), m_mRTWeightingFactor(mRTWeightingFactor) { | |
| 37 |
4/4✓ Branch 0 taken 34 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 31 times.
|
37 | if (!((m_mRTWeightingFactor >= 0.0) && (m_mRTWeightingFactor <= 1.0))) { |
| 38 |
17/17✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
✓ Branch 13 taken 6 times.
✓ Branch 16 taken 6 times.
✓ Branch 19 taken 6 times.
✓ Branch 25 taken 6 times.
✓ Branch 28 taken 6 times.
✓ Branch 31 taken 6 times.
✓ Branch 34 taken 6 times.
✓ Branch 37 taken 6 times.
✓ Branch 40 taken 6 times.
✓ Branch 43 taken 6 times.
✓ Branch 46 taken 6 times.
✓ Branch 50 taken 6 times.
✓ Branch 53 taken 6 times.
|
6 | LOG_AND_THROW("Unable to create MRT weighting factor, factor of " << m_mRTWeightingFactor << " is not between 0 and 1"); |
| 39 | } | ||
| 40 | 37 | } | |
| 41 | |||
| 42 | 29 | People MRTWeightingFactor::people() const { | |
| 43 | 29 | return m_people; | |
| 44 | } | ||
| 45 | |||
| 46 | 38 | double MRTWeightingFactor::mRTWeightingFactor() const { | |
| 47 | 38 | return m_mRTWeightingFactor; | |
| 48 | } | ||
| 49 | |||
| 50 | ✗ | bool MRTWeightingFactor::operator!=(const MRTWeightingFactor& other) const { | |
| 51 | ✗ | return !operator==(other); | |
| 52 | } | ||
| 53 | |||
| 54 | 5 | std::ostream& operator<<(std::ostream& out, const openstudio::model::MRTWeightingFactor& mRTWeightingFactor) { | |
| 55 |
7/7✓ Branch 2 taken 5 times.
✓ Branch 5 taken 5 times.
✓ Branch 8 taken 5 times.
✓ Branch 11 taken 5 times.
✓ Branch 14 taken 5 times.
✓ Branch 17 taken 5 times.
✓ Branch 20 taken 5 times.
|
5 | out << "(people='" << mRTWeightingFactor.people().nameString() << "', MRT weighting factor=" << mRTWeightingFactor.mRTWeightingFactor() << ")"; |
| 56 | 5 | return out; | |
| 57 | } | ||
| 58 | |||
| 59 | /***************************************************************************************************************************************************** | ||
| 60 | * Z O N E M R T C A L C U L A T I O N * | ||
| 61 | *****************************************************************************************************************************************************/ | ||
| 62 | |||
| 63 | namespace detail { | ||
| 64 | |||
| 65 | 9 | ZoneMRTCalculation_Impl::ZoneMRTCalculation_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) | |
| 66 | 9 | : ModelObject_Impl(idfObject, model, keepHandle) { | |
| 67 |
4/6✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 9 times.
✗ Branch 13 not taken.
|
9 | OS_ASSERT(idfObject.iddObject().type() == ZoneMRTCalculation::iddObjectType()); |
| 68 | 9 | } | |
| 69 | |||
| 70 | ✗ | ZoneMRTCalculation_Impl::ZoneMRTCalculation_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle) | |
| 71 | ✗ | : ModelObject_Impl(other, model, keepHandle) { | |
| 72 | ✗ | OS_ASSERT(other.iddObject().type() == ZoneMRTCalculation::iddObjectType()); | |
| 73 | ✗ | } | |
| 74 | |||
| 75 | 3 | ZoneMRTCalculation_Impl::ZoneMRTCalculation_Impl(const ZoneMRTCalculation_Impl& other, Model_Impl* model, bool keepHandle) | |
| 76 | 3 | : ModelObject_Impl(other, model, keepHandle) {} | |
| 77 | |||
| 78 | ✗ | const std::vector<std::string>& ZoneMRTCalculation_Impl::outputVariableNames() const { | |
| 79 | ✗ | static const std::vector<std::string> result; | |
| 80 | ✗ | return result; | |
| 81 | } | ||
| 82 | |||
| 83 | ✗ | IddObjectType ZoneMRTCalculation_Impl::iddObjectType() const { | |
| 84 | ✗ | return ZoneMRTCalculation::iddObjectType(); | |
| 85 | } | ||
| 86 | |||
| 87 | 2 | ModelObject ZoneMRTCalculation_Impl::clone(Model /*model*/) const { | |
| 88 |
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 19 taken 2 times.
✓ Branch 22 taken 2 times.
✓ Branch 25 taken 2 times.
✓ Branch 28 taken 2 times.
✓ Branch 31 taken 2 times.
✓ Branch 34 taken 2 times.
✓ Branch 38 taken 2 times.
✓ Branch 41 taken 2 times.
|
2 | LOG_AND_THROW("Cloning isn't allowed for ZoneMRTCalculation in order to guarantee that every ZoneMRTCalculation has a thermal zone, and " |
| 89 | "that a thermal zone must have only one ZoneMRTCalculation."); | ||
| 90 | } | ||
| 91 | |||
| 92 | 22 | ThermalZone ZoneMRTCalculation_Impl::thermalZone() const { | |
| 93 | boost::optional<ThermalZone> thermalZone = | ||
| 94 |
2/2✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
|
22 | getObject<ModelObject>().getModelObjectTarget<ThermalZone>(OS_ZoneMRTCalculationFields::ThermalZoneName); |
| 95 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 4 not taken.
|
22 | OS_ASSERT(thermalZone); |
| 96 |
2/2✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
|
44 | return thermalZone.get(); |
| 97 | 22 | } | |
| 98 | |||
| 99 | 83 | unsigned int ZoneMRTCalculation_Impl::numberofMRTWeightingFactors() const { | |
| 100 | 83 | return numExtensibleGroups(); | |
| 101 | } | ||
| 102 | |||
| 103 | 17 | boost::optional<unsigned> ZoneMRTCalculation_Impl::mRTWeightingFactorIndex(const People& people) const { | |
| 104 | 17 | boost::optional<unsigned> result; | |
| 105 | |||
| 106 |
2/2✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
|
17 | auto egs = castVector<WorkspaceExtensibleGroup>(extensibleGroups()); |
| 107 |
2/2✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
|
17 | auto peopleHandle = toString(people.handle()); |
| 108 |
1/1✓ Branch 3 taken 17 times.
|
17 | auto it = std::find_if(egs.begin(), egs.end(), [&](const WorkspaceExtensibleGroup& eg) { |
| 109 |
2/2✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
|
13 | return eg.getField(OS_ZoneMRTCalculationExtensibleFields::PeopleName).get() == peopleHandle; |
| 110 | }); | ||
| 111 | |||
| 112 |
2/2✓ Branch 2 taken 4 times.
✓ Branch 3 taken 13 times.
|
17 | if (it != egs.end()) { |
| 113 |
1/1✓ Branch 2 taken 4 times.
|
8 | result = std::distance(egs.begin(), it); |
| 114 | } | ||
| 115 | |||
| 116 | 17 | return result; | |
| 117 | 17 | } | |
| 118 | |||
| 119 | 11 | boost::optional<People> ZoneMRTCalculation_Impl::getPeople(unsigned groupIndex) const { | |
| 120 | 11 | boost::optional<People> result; | |
| 121 | |||
| 122 |
3/3✓ Branch 1 taken 11 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 10 times.
|
11 | if (groupIndex >= numberofMRTWeightingFactors()) { |
| 123 |
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 People with index " << groupIndex << ", but " << briefDescription() << " has just " << numberofMRTWeightingFactors() |
| 124 | << " MRT weighting factors."); | ||
| 125 | 1 | return result; | |
| 126 | } | ||
| 127 | |||
| 128 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
|
10 | auto group = getExtensibleGroup(groupIndex).cast<ModelExtensibleGroup>(); |
| 129 |
1/1✓ Branch 1 taken 10 times.
|
10 | result = group.getModelObjectTarget<People>(OS_ZoneMRTCalculationExtensibleFields::PeopleName); |
| 130 | |||
| 131 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | if (!result) { |
| 132 | ✗ | LOG(Error, "Could not retrieve People Name for extensible group " << group.groupIndex() << "."); | |
| 133 | } | ||
| 134 | |||
| 135 | 10 | return result; | |
| 136 | 10 | } | |
| 137 | |||
| 138 | 19 | boost::optional<double> ZoneMRTCalculation_Impl::getMRTWeightingFactorValue(unsigned groupIndex) const { | |
| 139 | 19 | boost::optional<double> result; | |
| 140 | |||
| 141 |
3/3✓ Branch 1 taken 19 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 18 times.
|
19 | if (groupIndex >= numberofMRTWeightingFactors()) { |
| 142 |
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 MRT Weighting Factor with index " << groupIndex << ", but " << briefDescription() << " has just " |
| 143 | << numberofMRTWeightingFactors() << " MRT weighting factors."); | ||
| 144 | 1 | return result; | |
| 145 | } | ||
| 146 | |||
| 147 |
2/2✓ Branch 1 taken 18 times.
✓ Branch 4 taken 18 times.
|
18 | auto group = getExtensibleGroup(groupIndex).cast<ModelExtensibleGroup>(); |
| 148 |
1/1✓ Branch 1 taken 18 times.
|
18 | result = group.getDouble(OS_ZoneMRTCalculationExtensibleFields::MRTWeightingFactor); |
| 149 | |||
| 150 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
|
18 | if (!result) { |
| 151 | ✗ | LOG(Error, "Could not retrieve MRT Weighting Factor for extensible group " << group.groupIndex() << "."); | |
| 152 | } | ||
| 153 | |||
| 154 | 18 | return result; | |
| 155 | 18 | } | |
| 156 | |||
| 157 | 11 | boost::optional<MRTWeightingFactor> ZoneMRTCalculation_Impl::getMRTWeightingFactor(unsigned groupIndex) const { | |
| 158 | 11 | boost::optional<MRTWeightingFactor> result; | |
| 159 | |||
| 160 |
1/1✓ Branch 1 taken 11 times.
|
11 | boost::optional<People> people = getPeople(groupIndex); |
| 161 |
1/1✓ Branch 1 taken 11 times.
|
11 | boost::optional<double> value = getMRTWeightingFactorValue(groupIndex); |
| 162 | |||
| 163 |
5/6✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 1 time.
|
21 | if (people && value) { |
| 164 |
4/4✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
✓ Branch 7 taken 10 times.
✓ Branch 10 taken 10 times.
|
10 | result = MRTWeightingFactor(people.get(), value.get()); |
| 165 | } | ||
| 166 | |||
| 167 | 22 | return result; | |
| 168 | 11 | } | |
| 169 | |||
| 170 | 4 | std::vector<MRTWeightingFactor> ZoneMRTCalculation_Impl::mRTWeightingFactors() const { | |
| 171 | 4 | std::vector<MRTWeightingFactor> result; | |
| 172 | |||
| 173 |
3/3✓ Branch 1 taken 9 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 4 times.
|
9 | for (unsigned i = 0; i < numberofMRTWeightingFactors(); ++i) { |
| 174 |
1/1✓ Branch 1 taken 5 times.
|
5 | boost::optional<MRTWeightingFactor> mRTWeightingFactor = getMRTWeightingFactor(i); |
| 175 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if (mRTWeightingFactor) { |
| 176 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
|
5 | result.push_back(mRTWeightingFactor.get()); |
| 177 | } else { | ||
| 178 | ✗ | LOG(Error, briefDescription() << " has an invalid MRTWeightingFactor group at index " << i); | |
| 179 | } | ||
| 180 | 5 | } | |
| 181 | |||
| 182 | 4 | return result; | |
| 183 | ✗ | } | |
| 184 | |||
| 185 | 18 | bool ZoneMRTCalculation_Impl::addMRTWeightingFactor(const MRTWeightingFactor& mRTWeightingFactor) { | |
| 186 | 18 | bool result = false; | |
| 187 | |||
| 188 |
1/1✓ Branch 1 taken 18 times.
|
18 | People people = mRTWeightingFactor.people(); |
| 189 | |||
| 190 |
4/5✓ Branch 1 taken 18 times.
✓ Branch 4 taken 18 times.
✓ Branch 7 taken 18 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 18 times.
|
18 | if (people.model() != model()) { |
| 191 | ✗ | LOG(Error, "Cannot add " << people.briefDescription() << " to " << briefDescription() << " because they are in different models."); | |
| 192 | ✗ | return result; | |
| 193 | } | ||
| 194 | |||
| 195 |
1/1✓ Branch 1 taken 18 times.
|
18 | boost::optional<Space> space = people.space(); |
| 196 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 17 times.
|
18 | if (!space) { |
| 197 |
11/11✓ 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 27 taken 1 time.
✓ Branch 30 taken 1 time.
✓ Branch 33 taken 1 time.
|
1 | LOG(Error, "Cannot add " << people.briefDescription() << " to " << briefDescription() << " because it is not directly assigned to a Space."); |
| 198 | 1 | return result; | |
| 199 | } | ||
| 200 | |||
| 201 |
2/2✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
|
17 | boost::optional<ThermalZone> thermalZone = space->thermalZone(); |
| 202 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
17 | if (!thermalZone) { |
| 203 | ✗ | LOG(Error, "Cannot add " << people.briefDescription() << " to " << briefDescription() << " because it is not assigned to any ThermalZone."); | |
| 204 |
7/7✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
✓ Branch 7 taken 17 times.
✓ Branch 10 taken 17 times.
✓ Branch 13 taken 17 times.
✓ Branch 16 taken 1 time.
✓ Branch 17 taken 16 times.
|
17 | } else if (thermalZone->handle() != this->thermalZone().handle()) { |
| 205 |
19/19✓ 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 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 54 taken 1 time.
✓ Branch 57 taken 1 time.
✓ Branch 60 taken 1 time.
|
1 | LOG(Error, "Cannot add " << people.briefDescription() << " to " << briefDescription() << " because it is assigned to ThermalZone '" |
| 206 | << thermalZone->nameString() << "' instead of '" << this->thermalZone().nameString() << "'."); | ||
| 207 | 1 | return result; | |
| 208 | } | ||
| 209 | |||
| 210 |
4/4✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 14 times.
|
16 | if (people.peopleDefinition().numThermalComfortModelTypes() == 0) { |
| 211 |
11/11✓ 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 27 taken 2 times.
✓ Branch 30 taken 2 times.
✓ Branch 33 taken 2 times.
|
2 | LOG(Error, "Cannot add " << people.briefDescription() << " to " << briefDescription() |
| 212 | << " because it does not select at least one Thermal Comfort Model Type."); | ||
| 213 | 2 | return result; | |
| 214 | } | ||
| 215 | |||
| 216 |
1/1✓ Branch 1 taken 14 times.
|
14 | boost::optional<unsigned> existingIndex = mRTWeightingFactorIndex(people); |
| 217 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 12 times.
|
14 | if (existingIndex) { |
| 218 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | boost::optional<MRTWeightingFactor> existingMRTWeightingFactor = getMRTWeightingFactor(existingIndex.get()); |
| 219 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
|
2 | OS_ASSERT(existingMRTWeightingFactor); |
| 220 |
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() << ", MRTWeightingFactor already exists, will be modified in place from " |
| 221 | << existingMRTWeightingFactor.get() << " to " << mRTWeightingFactor << "."); | ||
| 222 | 2 | } | |
| 223 | |||
| 224 |
1/1✓ Branch 1 taken 14 times.
|
14 | double sum = mRTWeightingFactor.mRTWeightingFactor(); |
| 225 |
3/3✓ Branch 1 taken 24 times.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 14 times.
|
24 | for (unsigned i = 0; i < numberofMRTWeightingFactors(); ++i) { |
| 226 |
7/7✓ Branch 0 taken 3 times.
✓ Branch 1 taken 7 times.
✓ Branch 3 taken 3 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 1 time.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 8 times.
|
10 | if (existingIndex && (i == existingIndex.get())) { |
| 227 | 2 | continue; | |
| 228 | } | ||
| 229 | |||
| 230 |
1/1✓ Branch 1 taken 8 times.
|
8 | boost::optional<double> existingValue = getMRTWeightingFactorValue(i); |
| 231 |
6/10✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 8 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 8 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 8 times.
|
8 | if (!existingValue || !((*existingValue >= 0.0) && (*existingValue <= 1.0))) { |
| 232 | ✗ | LOG(Error, | |
| 233 | "Cannot add " << people.briefDescription() << " to " << briefDescription() << " because an existing MRT Weighting Factor is invalid."); | ||
| 234 | ✗ | return result; | |
| 235 | } | ||
| 236 | |||
| 237 |
1/1✓ Branch 1 taken 8 times.
|
8 | sum += existingValue.get(); |
| 238 | } | ||
| 239 | |||
| 240 | 14 | constexpr double tolerance = 0.000001; | |
| 241 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 13 times.
|
14 | if (sum > 1.0 + tolerance) { |
| 242 |
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 33 taken 1 time.
✓ Branch 36 taken 1 time.
✓ Branch 39 taken 1 time.
|
1 | LOG(Error, "Cannot add " << people.briefDescription() << " to " << briefDescription() << " because the MRT Weighting Factors would sum to " |
| 243 | << sum << ", which is greater than 1."); | ||
| 244 | 1 | return result; | |
| 245 | } | ||
| 246 | |||
| 247 | 13 | std::vector<std::string> temp; | |
| 248 |
2/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
4 | ModelExtensibleGroup group = (existingIndex ? getExtensibleGroup(existingIndex.get()).cast<ModelExtensibleGroup>() |
| 249 |
9/11✓ Branch 0 taken 2 times.
✓ Branch 1 taken 11 times.
✓ Branch 3 taken 2 times.
✓ Branch 6 taken 11 times.
✓ Branch 9 taken 11 times.
✓ Branch 11 taken 11 times.
✓ Branch 12 taken 2 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 11 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
15 | : pushExtensibleGroup(temp, false).cast<ModelExtensibleGroup>()); |
| 250 | |||
| 251 |
2/2✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
|
13 | bool peopleSet = group.setPointer(OS_ZoneMRTCalculationExtensibleFields::PeopleName, people.handle(), false); |
| 252 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (!peopleSet) { |
| 253 | ✗ | LOG(Error, "Unable to add MRT Weighting Factor which has an incompatible People object to " << briefDescription()); | |
| 254 | ✗ | OS_ASSERT(false); | |
| 255 | } | ||
| 256 | |||
| 257 |
2/2✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
|
13 | bool factorSet = group.setDouble(OS_ZoneMRTCalculationExtensibleFields::MRTWeightingFactor, mRTWeightingFactor.mRTWeightingFactor()); |
| 258 | |||
| 259 |
2/4✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
|
13 | if (peopleSet && factorSet) { |
| 260 | 13 | result = true; | |
| 261 | } else { | ||
| 262 | ✗ | if (!existingIndex) { | |
| 263 | ✗ | getObject<ModelObject>().eraseExtensibleGroup(group.groupIndex()); | |
| 264 | } | ||
| 265 | } | ||
| 266 | |||
| 267 | 13 | return result; | |
| 268 | 18 | } | |
| 269 | |||
| 270 | 16 | bool ZoneMRTCalculation_Impl::addMRTWeightingFactor(const People& people, double mRTWeightingFactor) { | |
| 271 |
1/1✓ Branch 1 taken 14 times.
|
16 | MRTWeightingFactor weightingFactor(people, mRTWeightingFactor); |
| 272 |
1/1✓ Branch 1 taken 14 times.
|
28 | return addMRTWeightingFactor(weightingFactor); |
| 273 | 14 | } | |
| 274 | |||
| 275 | 2 | bool ZoneMRTCalculation_Impl::addMRTWeightingFactors(const std::vector<MRTWeightingFactor>& mRTWeightingFactors) { | |
| 276 | 2 | bool result = true; | |
| 277 | |||
| 278 |
2/2✓ Branch 5 taken 3 times.
✓ Branch 6 taken 2 times.
|
5 | for (const MRTWeightingFactor& mRTWeightingFactor : mRTWeightingFactors) { |
| 279 |
1/1✓ Branch 1 taken 3 times.
|
3 | bool thisResult = addMRTWeightingFactor(mRTWeightingFactor); |
| 280 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 2 times.
|
3 | if (!thisResult) { |
| 281 | 1 | result = false; | |
| 282 |
10/10✓ 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 23 taken 1 time.
✓ Branch 26 taken 1 time.
✓ Branch 29 taken 1 time.
|
1 | LOG(Error, "Could not add mRTWeightingFactor " << mRTWeightingFactor << " to " << briefDescription() << ". Continuing with others."); |
| 283 | } | ||
| 284 | } | ||
| 285 | |||
| 286 | 2 | return result; | |
| 287 | } | ||
| 288 | |||
| 289 | 2 | bool ZoneMRTCalculation_Impl::removeMRTWeightingFactor(unsigned groupIndex) { | |
| 290 | 2 | bool result = false; | |
| 291 | |||
| 292 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | if (groupIndex < numberofMRTWeightingFactors()) { |
| 293 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | getObject<ModelObject>().eraseExtensibleGroup(groupIndex); |
| 294 | 2 | result = true; | |
| 295 | } | ||
| 296 | |||
| 297 | 2 | return result; | |
| 298 | } | ||
| 299 | |||
| 300 | 2 | void ZoneMRTCalculation_Impl::removeAllMRTWeightingFactors() { | |
| 301 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | getObject<ModelObject>().clearExtensibleGroups(); |
| 302 | 2 | } | |
| 303 | |||
| 304 | } // namespace detail | ||
| 305 | |||
| 306 |
3/3✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
|
9 | ZoneMRTCalculation::ZoneMRTCalculation(const ThermalZone& thermalZone) : ModelObject(ZoneMRTCalculation::iddObjectType(), thermalZone.model()) { |
| 307 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
|
9 | std::vector<ZoneMRTCalculation> existingObjects = thermalZone.getModelObjectSources<ZoneMRTCalculation>(ZoneMRTCalculation::iddObjectType()); |
| 308 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
|
9 | if (!existingObjects.empty()) { |
| 309 | ✗ | remove(); | |
| 310 | ✗ | LOG_AND_THROW(thermalZone.briefDescription() << " already has a ZoneMRTCalculation, cannot create a new one."); | |
| 311 | } | ||
| 312 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
✗ Branch 5 not taken.
|
9 | OS_ASSERT(getImpl<detail::ZoneMRTCalculation_Impl>()); |
| 313 | |||
| 314 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
|
9 | bool ok = setPointer(OS_ZoneMRTCalculationFields::ThermalZoneName, thermalZone.handle()); |
| 315 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 3 not taken.
|
9 | OS_ASSERT(ok); |
| 316 | 9 | } | |
| 317 | |||
| 318 | 8240 | IddObjectType ZoneMRTCalculation::iddObjectType() { | |
| 319 |
1/1✓ Branch 1 taken 8240 times.
|
8240 | return {IddObjectType::OS_ZoneMRTCalculation}; |
| 320 | } | ||
| 321 | |||
| 322 | 4 | ThermalZone ZoneMRTCalculation::thermalZone() const { | |
| 323 |
1/1✓ Branch 3 taken 4 times.
|
4 | return getImpl<detail::ZoneMRTCalculation_Impl>()->thermalZone(); |
| 324 | } | ||
| 325 | |||
| 326 | 4 | std::vector<MRTWeightingFactor> ZoneMRTCalculation::mRTWeightingFactors() const { | |
| 327 |
1/1✓ Branch 3 taken 4 times.
|
4 | return getImpl<detail::ZoneMRTCalculation_Impl>()->mRTWeightingFactors(); |
| 328 | } | ||
| 329 | |||
| 330 | 16 | unsigned int ZoneMRTCalculation::numberofMRTWeightingFactors() const { | |
| 331 |
1/1✓ Branch 3 taken 16 times.
|
16 | return getImpl<detail::ZoneMRTCalculation_Impl>()->numberofMRTWeightingFactors(); |
| 332 | } | ||
| 333 | |||
| 334 | 3 | boost::optional<unsigned> ZoneMRTCalculation::mRTWeightingFactorIndex(const People& people) const { | |
| 335 |
1/1✓ Branch 3 taken 3 times.
|
3 | return getImpl<detail::ZoneMRTCalculation_Impl>()->mRTWeightingFactorIndex(people); |
| 336 | } | ||
| 337 | |||
| 338 | 4 | boost::optional<MRTWeightingFactor> ZoneMRTCalculation::getMRTWeightingFactor(unsigned groupIndex) const { | |
| 339 |
1/1✓ Branch 3 taken 4 times.
|
4 | return getImpl<detail::ZoneMRTCalculation_Impl>()->getMRTWeightingFactor(groupIndex); |
| 340 | } | ||
| 341 | |||
| 342 | 1 | bool ZoneMRTCalculation::addMRTWeightingFactor(const MRTWeightingFactor& mRTWeightingFactor) { | |
| 343 |
1/1✓ Branch 3 taken 1 time.
|
1 | return getImpl<detail::ZoneMRTCalculation_Impl>()->addMRTWeightingFactor(mRTWeightingFactor); |
| 344 | } | ||
| 345 | |||
| 346 | 16 | bool ZoneMRTCalculation::addMRTWeightingFactor(const People& people, double mRTWeightingFactor) { | |
| 347 |
1/1✓ Branch 3 taken 14 times.
|
16 | return getImpl<detail::ZoneMRTCalculation_Impl>()->addMRTWeightingFactor(people, mRTWeightingFactor); |
| 348 | } | ||
| 349 | |||
| 350 | 2 | bool ZoneMRTCalculation::addMRTWeightingFactors(const std::vector<MRTWeightingFactor>& mRTWeightingFactors) { | |
| 351 |
1/1✓ Branch 3 taken 2 times.
|
2 | return getImpl<detail::ZoneMRTCalculation_Impl>()->addMRTWeightingFactors(mRTWeightingFactors); |
| 352 | } | ||
| 353 | |||
| 354 | 2 | void ZoneMRTCalculation::removeMRTWeightingFactor(int groupIndex) { | |
| 355 |
1/1✓ Branch 3 taken 2 times.
|
2 | getImpl<detail::ZoneMRTCalculation_Impl>()->removeMRTWeightingFactor(groupIndex); |
| 356 | 2 | } | |
| 357 | |||
| 358 | 2 | void ZoneMRTCalculation::removeAllMRTWeightingFactors() { | |
| 359 |
1/1✓ Branch 3 taken 2 times.
|
2 | getImpl<detail::ZoneMRTCalculation_Impl>()->removeAllMRTWeightingFactors(); |
| 360 | 2 | } | |
| 361 | |||
| 362 | /// @cond | ||
| 363 |
1/1✓ Branch 3 taken 10 times.
|
10 | ZoneMRTCalculation::ZoneMRTCalculation(std::shared_ptr<detail::ZoneMRTCalculation_Impl> impl) : ModelObject(std::move(impl)) {} |
| 364 | /// @endcond | ||
| 365 | |||
| 366 | } // namespace model | ||
| 367 | } // namespace openstudio | ||
| 368 |