src/model/InternalMass.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 "InternalMass.hpp" | ||
| 7 | #include "InternalMass_Impl.hpp" | ||
| 8 | #include "ComfortViewFactorAngles.hpp" | ||
| 9 | #include "ComfortViewFactorAngles_Impl.hpp" | ||
| 10 | #include "InternalMassDefinition.hpp" | ||
| 11 | #include "InternalMassDefinition_Impl.hpp" | ||
| 12 | #include "Space.hpp" | ||
| 13 | #include "Space_Impl.hpp" | ||
| 14 | #include "LifeCycleCost.hpp" | ||
| 15 | #include "SurfacePropertyConvectionCoefficients.hpp" | ||
| 16 | #include "SurfacePropertyConvectionCoefficients_Impl.hpp" | ||
| 17 | #include "Model.hpp" | ||
| 18 | #include "Model_Impl.hpp" | ||
| 19 | |||
| 20 | #include <utilities/idd/OS_InternalMass_FieldEnums.hxx> | ||
| 21 | #include <utilities/idd/IddEnums.hxx> | ||
| 22 | |||
| 23 | #include "../utilities/core/Assert.hpp" | ||
| 24 | |||
| 25 | namespace openstudio { | ||
| 26 | namespace model { | ||
| 27 | |||
| 28 | namespace detail { | ||
| 29 | |||
| 30 | 99 | InternalMass_Impl::InternalMass_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) | |
| 31 | 99 | : SpaceLoadInstance_Impl(idfObject, model, keepHandle) { | |
| 32 |
4/6✓ Branch 1 taken 99 times.
✓ Branch 4 taken 99 times.
✓ Branch 7 taken 99 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 99 times.
✗ Branch 13 not taken.
|
99 | OS_ASSERT(idfObject.iddObject().type() == InternalMass::iddObjectType()); |
| 33 | 99 | } | |
| 34 | |||
| 35 | 58 | InternalMass_Impl::InternalMass_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle) | |
| 36 | 58 | : SpaceLoadInstance_Impl(other, model, keepHandle) { | |
| 37 |
4/6✓ Branch 1 taken 58 times.
✓ Branch 4 taken 58 times.
✓ Branch 7 taken 58 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 58 times.
✗ Branch 13 not taken.
|
58 | OS_ASSERT(other.iddObject().type() == InternalMass::iddObjectType()); |
| 38 | 58 | } | |
| 39 | |||
| 40 | 13 | InternalMass_Impl::InternalMass_Impl(const InternalMass_Impl& other, Model_Impl* model, bool keepHandle) | |
| 41 | 13 | : SpaceLoadInstance_Impl(other, model, keepHandle) {} | |
| 42 | |||
| 43 | ✗ | const std::vector<std::string>& InternalMass_Impl::outputVariableNames() const { | |
| 44 | ✗ | static const std::vector<std::string> result; | |
| 45 | // Not sure | ||
| 46 | ✗ | return result; | |
| 47 | } | ||
| 48 | |||
| 49 | 31 | IddObjectType InternalMass_Impl::iddObjectType() const { | |
| 50 | 31 | return InternalMass::iddObjectType(); | |
| 51 | } | ||
| 52 | |||
| 53 | 1 | std::vector<IdfObject> InternalMass_Impl::remove() { | |
| 54 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | InternalMass internalMass = getObject<ModelObject>().cast<InternalMass>(); |
| 55 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 9 taken 1 time.
|
2 | for (ComfortViewFactorAngles& comfortViewFactorAngles : internalMass.getModelObjectSources<ComfortViewFactorAngles>()) { |
| 56 |
2/3✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
|
2 | if (boost::optional<unsigned> index = comfortViewFactorAngles.angleFactorIndex(internalMass)) { |
| 57 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | comfortViewFactorAngles.removeAngleFactor(index.get()); |
| 58 | } | ||
| 59 | 1 | } | |
| 60 | |||
| 61 |
1/1✓ Branch 1 taken 1 time.
|
2 | return SpaceLoadInstance_Impl::remove(); |
| 62 | 1 | } | |
| 63 | |||
| 64 | ✗ | bool InternalMass_Impl::hardSize() { | |
| 65 | ✗ | boost::optional<Space> space = this->space(); | |
| 66 | ✗ | if (!space) { | |
| 67 | ✗ | return false; | |
| 68 | } | ||
| 69 | |||
| 70 | ✗ | this->makeUnique(); | |
| 71 | |||
| 72 | ✗ | InternalMassDefinition internalMassDefinition = this->internalMassDefinition(); | |
| 73 | ✗ | for (LifeCycleCost& cost : internalMassDefinition.lifeCycleCosts()) { | |
| 74 | ✗ | cost.convertToCostPerEach(); | |
| 75 | ✗ | } | |
| 76 | |||
| 77 | ✗ | boost::optional<double> surfaceArea = internalMassDefinition.surfaceArea(); | |
| 78 | ✗ | if (surfaceArea) { | |
| 79 | ✗ | return true; | |
| 80 | } | ||
| 81 | |||
| 82 | ✗ | boost::optional<double> surfaceAreaperSpaceFloorArea = internalMassDefinition.surfaceAreaperSpaceFloorArea(); | |
| 83 | ✗ | if (surfaceAreaperSpaceFloorArea) { | |
| 84 | ✗ | return internalMassDefinition.setSurfaceArea(*surfaceAreaperSpaceFloorArea * space->floorArea()); | |
| 85 | } | ||
| 86 | |||
| 87 | ✗ | boost::optional<double> surfaceAreaperPerson = internalMassDefinition.surfaceAreaperPerson(); | |
| 88 | ✗ | if (surfaceAreaperPerson) { | |
| 89 | ✗ | return internalMassDefinition.setSurfaceArea(*surfaceAreaperPerson * space->numberOfPeople()); | |
| 90 | } | ||
| 91 | |||
| 92 | ✗ | return false; | |
| 93 | ✗ | } | |
| 94 | |||
| 95 | ✗ | bool InternalMass_Impl::hardApplySchedules() { | |
| 96 | ✗ | return true; | |
| 97 | } | ||
| 98 | |||
| 99 | 12 | double InternalMass_Impl::multiplier() const { | |
| 100 |
1/1✓ Branch 1 taken 12 times.
|
12 | boost::optional<double> value = getDouble(OS_InternalMassFields::Multiplier, true); |
| 101 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 4 not taken.
|
12 | OS_ASSERT(value); |
| 102 |
1/1✓ Branch 1 taken 12 times.
|
24 | return value.get(); |
| 103 | } | ||
| 104 | |||
| 105 | ✗ | bool InternalMass_Impl::isMultiplierDefaulted() const { | |
| 106 | ✗ | return isEmpty(OS_InternalMassFields::Multiplier); | |
| 107 | } | ||
| 108 | |||
| 109 | ✗ | bool InternalMass_Impl::isAbsolute() const { | |
| 110 | ✗ | InternalMassDefinition definition = internalMassDefinition(); | |
| 111 | ✗ | if (definition.surfaceArea()) { | |
| 112 | ✗ | return true; | |
| 113 | } | ||
| 114 | ✗ | return false; | |
| 115 | ✗ | } | |
| 116 | |||
| 117 | 41 | bool InternalMass_Impl::setMultiplier(double multiplier) { | |
| 118 | 41 | bool result = setDouble(OS_InternalMassFields::Multiplier, multiplier); | |
| 119 | 41 | return result; | |
| 120 | } | ||
| 121 | |||
| 122 | ✗ | void InternalMass_Impl::resetMultiplier() { | |
| 123 | ✗ | bool result = setString(OS_InternalMassFields::Multiplier, ""); | |
| 124 | ✗ | OS_ASSERT(result); | |
| 125 | ✗ | } | |
| 126 | |||
| 127 | 91 | int InternalMass_Impl::spaceIndex() const { | |
| 128 | 91 | return OS_InternalMassFields::SpaceorSpaceTypeName; | |
| 129 | } | ||
| 130 | |||
| 131 | 53 | int InternalMass_Impl::definitionIndex() const { | |
| 132 | 53 | return OS_InternalMassFields::InternalMassDefinitionName; | |
| 133 | } | ||
| 134 | |||
| 135 | 12 | InternalMassDefinition InternalMass_Impl::internalMassDefinition() const { | |
| 136 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
|
12 | return this->definition().cast<InternalMassDefinition>(); |
| 137 | } | ||
| 138 | |||
| 139 | ✗ | bool InternalMass_Impl::setInternalMassDefinition(const InternalMassDefinition& definition) { | |
| 140 | ✗ | return this->setPointer(this->definitionIndex(), definition.handle()); | |
| 141 | } | ||
| 142 | |||
| 143 | ✗ | bool InternalMass_Impl::setDefinition(const SpaceLoadDefinition& definition) { | |
| 144 | ✗ | bool result = false; | |
| 145 | ✗ | boost::optional<InternalMassDefinition> internalMassDefinition = definition.optionalCast<InternalMassDefinition>(); | |
| 146 | ✗ | if (internalMassDefinition) { | |
| 147 | ✗ | result = setInternalMassDefinition(*internalMassDefinition); | |
| 148 | } | ||
| 149 | ✗ | return result; | |
| 150 | ✗ | } | |
| 151 | |||
| 152 | ✗ | boost::optional<double> InternalMass_Impl::surfaceArea() const { | |
| 153 | ✗ | OptionalDouble result = internalMassDefinition().surfaceArea(); | |
| 154 | ✗ | if (result) { | |
| 155 | ✗ | return result.get() * multiplier(); | |
| 156 | } | ||
| 157 | ✗ | return result; | |
| 158 | } | ||
| 159 | |||
| 160 | ✗ | boost::optional<double> InternalMass_Impl::surfaceAreaPerFloorArea() const { | |
| 161 | ✗ | OptionalDouble result = internalMassDefinition().surfaceAreaperSpaceFloorArea(); | |
| 162 | ✗ | if (result) { | |
| 163 | ✗ | return result.get() * multiplier(); | |
| 164 | } | ||
| 165 | ✗ | return result; | |
| 166 | } | ||
| 167 | |||
| 168 | ✗ | boost::optional<double> InternalMass_Impl::surfaceAreaPerPerson() const { | |
| 169 | ✗ | OptionalDouble result = internalMassDefinition().surfaceAreaperPerson(); | |
| 170 | ✗ | if (result) { | |
| 171 | ✗ | return result.get() * multiplier(); | |
| 172 | } | ||
| 173 | ✗ | return result; | |
| 174 | } | ||
| 175 | |||
| 176 | ✗ | double InternalMass_Impl::getSurfaceArea(double floorArea, double numPeople) const { | |
| 177 | ✗ | return internalMassDefinition().getSurfaceArea(floorArea, numPeople) * multiplier(); | |
| 178 | } | ||
| 179 | |||
| 180 | ✗ | double InternalMass_Impl::getSurfaceAreaPerFloorArea(double floorArea, double numPeople) const { | |
| 181 | ✗ | return internalMassDefinition().getSurfaceAreaPerFloorArea(floorArea, numPeople) * multiplier(); | |
| 182 | } | ||
| 183 | |||
| 184 | ✗ | double InternalMass_Impl::getSurfaceAreaPerPerson(double floorArea, double numPeople) const { | |
| 185 | ✗ | return internalMassDefinition().getSurfaceAreaPerPerson(floorArea, numPeople) * multiplier(); | |
| 186 | } | ||
| 187 | |||
| 188 | ✗ | boost::optional<ModelObject> InternalMass_Impl::internalMassDefinitionAsModelObject() const { | |
| 189 | ✗ | OptionalModelObject result = internalMassDefinition(); | |
| 190 | ✗ | return result; | |
| 191 | } | ||
| 192 | |||
| 193 | 19 | boost::optional<SurfacePropertyConvectionCoefficients> InternalMass_Impl::surfacePropertyConvectionCoefficients() const { | |
| 194 |
2/2✓ Branch 1 taken 19 times.
✓ Branch 4 taken 19 times.
|
19 | std::vector<SurfacePropertyConvectionCoefficients> allspccs(model().getConcreteModelObjects<SurfacePropertyConvectionCoefficients>()); |
| 195 | 19 | std::vector<SurfacePropertyConvectionCoefficients> spccs; | |
| 196 |
2/2✓ Branch 5 taken 11 times.
✓ Branch 6 taken 19 times.
|
30 | for (auto& spcc : allspccs) { |
| 197 |
1/1✓ Branch 1 taken 11 times.
|
11 | OptionalInternalMass surface = spcc.surfaceAsInternalMass(); |
| 198 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 4 times.
|
11 | if (surface) { |
| 199 |
6/6✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
✓ Branch 7 taken 7 times.
✓ Branch 10 taken 7 times.
✓ Branch 12 taken 5 times.
✓ Branch 13 taken 2 times.
|
7 | if (surface->handle() == handle()) { |
| 200 |
1/1✓ Branch 1 taken 5 times.
|
5 | spccs.push_back(spcc); |
| 201 | } | ||
| 202 | } | ||
| 203 | 11 | } | |
| 204 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 2 taken 5 times.
|
19 | if (spccs.empty()) { |
| 205 | 14 | return boost::none; | |
| 206 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | } else if (spccs.size() == 1) { |
| 207 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
|
5 | return spccs.at(0); |
| 208 | } else { | ||
| 209 | ✗ | LOG(Error, "More than one SurfacePropertyConvectionCoefficients points to this InternalMass"); | |
| 210 | ✗ | return boost::none; | |
| 211 | } | ||
| 212 | 19 | } | |
| 213 | |||
| 214 | ✗ | bool InternalMass_Impl::setInternalMassDefinitionAsModelObject(const boost::optional<ModelObject>& modelObject) { | |
| 215 | ✗ | if (modelObject) { | |
| 216 | ✗ | OptionalInternalMassDefinition intermediate = modelObject->optionalCast<InternalMassDefinition>(); | |
| 217 | ✗ | if (intermediate) { | |
| 218 | ✗ | return setInternalMassDefinition(*intermediate); | |
| 219 | } | ||
| 220 | ✗ | } | |
| 221 | ✗ | return false; | |
| 222 | } | ||
| 223 | |||
| 224 | 1 | ModelObject InternalMass_Impl::clone(Model model) const { | |
| 225 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
1 | auto clone = ModelObject_Impl::clone(model).cast<InternalMass>(); |
| 226 | |||
| 227 |
1/1✓ Branch 1 taken 1 time.
|
1 | auto coefficients = surfacePropertyConvectionCoefficients(); |
| 228 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1 | if (coefficients) { |
| 229 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
|
1 | auto coefficientsClone = coefficients->clone(model).cast<SurfacePropertyConvectionCoefficients>(); |
| 230 |
1/1✓ Branch 1 taken 1 time.
|
1 | coefficientsClone.setSurface(clone); |
| 231 | 1 | } | |
| 232 | |||
| 233 | 2 | return std::move(clone); | |
| 234 | 1 | } | |
| 235 | |||
| 236 | } // namespace detail | ||
| 237 | |||
| 238 | 41 | InternalMass::InternalMass(const InternalMassDefinition& internalMassDefinition) | |
| 239 | 41 | : SpaceLoadInstance(InternalMass::iddObjectType(), internalMassDefinition) { | |
| 240 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 41 times.
✗ Branch 5 not taken.
|
41 | OS_ASSERT(getImpl<detail::InternalMass_Impl>()); |
| 241 | |||
| 242 |
1/1✓ Branch 1 taken 41 times.
|
41 | bool test = this->setMultiplier(1.0); |
| 243 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
✗ Branch 3 not taken.
|
41 | OS_ASSERT(test); |
| 244 | 41 | } | |
| 245 | |||
| 246 | 10850 | IddObjectType InternalMass::iddObjectType() { | |
| 247 |
1/1✓ Branch 1 taken 10850 times.
|
10850 | IddObjectType result(IddObjectType::OS_InternalMass); |
| 248 | 10850 | return result; | |
| 249 | } | ||
| 250 | |||
| 251 | 41 | bool InternalMass::setMultiplier(double multiplier) { | |
| 252 |
1/1✓ Branch 3 taken 41 times.
|
41 | return getImpl<detail::InternalMass_Impl>()->setMultiplier(multiplier); |
| 253 | } | ||
| 254 | |||
| 255 | ✗ | void InternalMass::resetMultiplier() { | |
| 256 | ✗ | getImpl<detail::InternalMass_Impl>()->resetMultiplier(); | |
| 257 | ✗ | } | |
| 258 | |||
| 259 | 12 | InternalMassDefinition InternalMass::internalMassDefinition() const { | |
| 260 |
1/1✓ Branch 3 taken 12 times.
|
12 | return getImpl<detail::InternalMass_Impl>()->internalMassDefinition(); |
| 261 | } | ||
| 262 | |||
| 263 | ✗ | bool InternalMass::setInternalMassDefinition(const InternalMassDefinition& internalMassDefinition) { | |
| 264 | ✗ | return getImpl<detail::InternalMass_Impl>()->setInternalMassDefinition(internalMassDefinition); | |
| 265 | } | ||
| 266 | |||
| 267 | ✗ | boost::optional<double> InternalMass::surfaceArea() const { | |
| 268 | ✗ | return getImpl<detail::InternalMass_Impl>()->surfaceArea(); | |
| 269 | } | ||
| 270 | |||
| 271 | ✗ | boost::optional<double> InternalMass::surfaceAreaPerFloorArea() const { | |
| 272 | ✗ | return getImpl<detail::InternalMass_Impl>()->surfaceAreaPerFloorArea(); | |
| 273 | } | ||
| 274 | |||
| 275 | ✗ | boost::optional<double> InternalMass::surfaceAreaPerPerson() const { | |
| 276 | ✗ | return getImpl<detail::InternalMass_Impl>()->surfaceAreaPerPerson(); | |
| 277 | } | ||
| 278 | |||
| 279 | ✗ | double InternalMass::getSurfaceArea(double floorArea, double numPeople) const { | |
| 280 | ✗ | return getImpl<detail::InternalMass_Impl>()->getSurfaceArea(floorArea, numPeople); | |
| 281 | } | ||
| 282 | |||
| 283 | ✗ | double InternalMass::getSurfaceAreaPerFloorArea(double floorArea, double numPeople) const { | |
| 284 | ✗ | return getImpl<detail::InternalMass_Impl>()->getSurfaceAreaPerFloorArea(floorArea, numPeople); | |
| 285 | } | ||
| 286 | |||
| 287 | ✗ | double InternalMass::getSurfaceAreaPerPerson(double floorArea, double numPeople) const { | |
| 288 | ✗ | return getImpl<detail::InternalMass_Impl>()->getSurfaceAreaPerPerson(floorArea, numPeople); | |
| 289 | } | ||
| 290 | |||
| 291 | 18 | boost::optional<SurfacePropertyConvectionCoefficients> InternalMass::surfacePropertyConvectionCoefficients() const { | |
| 292 |
1/1✓ Branch 3 taken 18 times.
|
18 | return getImpl<detail::InternalMass_Impl>()->surfacePropertyConvectionCoefficients(); |
| 293 | } | ||
| 294 | |||
| 295 | /// @cond | ||
| 296 |
1/1✓ Branch 3 taken 71 times.
|
71 | InternalMass::InternalMass(std::shared_ptr<detail::InternalMass_Impl> impl) : SpaceLoadInstance(std::move(impl)) {} |
| 297 | /// @endcond | ||
| 298 | |||
| 299 | } // namespace model | ||
| 300 | } // namespace openstudio | ||
| 301 |