src/energyplus/ForwardTranslator/ForwardTranslateZoneMRTCalculation.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 "../ForwardTranslator.hpp" | ||
| 7 | |||
| 8 | #include "../../model/Model.hpp" | ||
| 9 | #include "../../model/People.hpp" | ||
| 10 | #include "../../model/People_Impl.hpp" | ||
| 11 | #include "../../model/PeopleDefinition.hpp" | ||
| 12 | #include "../../model/PeopleDefinition_Impl.hpp" | ||
| 13 | #include "../../model/Space.hpp" | ||
| 14 | #include "../../model/Space_Impl.hpp" | ||
| 15 | #include "../../model/ThermalZone.hpp" | ||
| 16 | #include "../../model/ThermalZone_Impl.hpp" | ||
| 17 | #include "../../model/ZoneMRTCalculation.hpp" | ||
| 18 | #include "../../model/ZoneMRTCalculation_Impl.hpp" | ||
| 19 | |||
| 20 | #include "../../utilities/idf/IdfExtensibleGroup.hpp" | ||
| 21 | |||
| 22 | #include <utilities/idd/IddEnums.hxx> | ||
| 23 | #include <utilities/idd/ZoneMRTCalculation_FieldEnums.hxx> | ||
| 24 | |||
| 25 | using namespace openstudio::model; | ||
| 26 | |||
| 27 | namespace openstudio { | ||
| 28 | |||
| 29 | namespace energyplus { | ||
| 30 | |||
| 31 | 2 | boost::optional<IdfObject> ForwardTranslator::translateZoneMRTCalculation(ZoneMRTCalculation& modelObject) { | |
| 32 |
1/1✓ Branch 1 taken 2 times.
|
2 | ThermalZone zone = modelObject.thermalZone(); |
| 33 | |||
| 34 |
1/1✓ Branch 1 taken 2 times.
|
2 | std::vector<MRTWeightingFactor> mRTWeightingFactors = modelObject.mRTWeightingFactors(); |
| 35 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (mRTWeightingFactors.empty()) { |
| 36 | ✗ | LOG(Warn, | |
| 37 | "ZoneMRTCalculation for zone '" << zone.nameString() << "' doesn't have at least one MRT weighting factor, it will not be translated."); | ||
| 38 | ✗ | return boost::none; | |
| 39 | } | ||
| 40 | |||
| 41 | 2 | std::vector<std::pair<std::string, double>> translatedMRTWeightingFactors; | |
| 42 | 2 | double sum = 0.0; | |
| 43 | 2 | constexpr double tolerance = 0.000001; | |
| 44 | |||
| 45 |
2/2✓ Branch 5 taken 4 times.
✓ Branch 6 taken 2 times.
|
6 | for (const MRTWeightingFactor& mRTWeightingFactor : mRTWeightingFactors) { |
| 46 |
1/1✓ Branch 1 taken 4 times.
|
4 | People people = mRTWeightingFactor.people(); |
| 47 | |||
| 48 |
1/1✓ Branch 1 taken 4 times.
|
4 | boost::optional<Space> space = people.space(); |
| 49 | |||
| 50 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | if (!space) { |
| 51 | ✗ | LOG(Error, "Could not translate an MRTWeightingFactor group for " << modelObject.briefDescription() << " because " | |
| 52 | << people.briefDescription() << " is not assigned to a Space."); | ||
| 53 | ✗ | continue; | |
| 54 | ✗ | } | |
| 55 | |||
| 56 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | boost::optional<ThermalZone> thermalZone = space->thermalZone(); |
| 57 | |||
| 58 |
9/10✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 13 taken 4 times.
✓ Branch 15 taken 1 time.
✓ Branch 16 taken 3 times.
✓ Branch 17 taken 1 time.
✓ Branch 18 taken 3 times.
|
4 | if (!thermalZone || (thermalZone->handle() != zone.handle())) { |
| 59 |
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, "Could not translate an MRTWeightingFactor group for " << modelObject.briefDescription() << " because " |
| 60 | << people.briefDescription() | ||
| 61 | << " is not assigned to the ZoneMRTCalculation ThermalZone."); | ||
| 62 | 1 | continue; | |
| 63 | 1 | } | |
| 64 | |||
| 65 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 2 times.
|
3 | if (people.peopleDefinition().numThermalComfortModelTypes() == 0) { |
| 66 |
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, "Could not translate an MRTWeightingFactor group for " << modelObject.briefDescription() << " because " |
| 67 | << people.briefDescription() | ||
| 68 | << " does not select at least one Thermal Comfort Model Type."); | ||
| 69 | 1 | continue; | |
| 70 | 1 | } | |
| 71 | |||
| 72 |
1/1✓ Branch 1 taken 2 times.
|
2 | boost::optional<IdfObject> _people = translateAndMapModelObject(people); |
| 73 | |||
| 74 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (_people) { |
| 75 |
1/1✓ Branch 1 taken 2 times.
|
2 | double value = mRTWeightingFactor.mRTWeightingFactor(); |
| 76 | 2 | sum += value; | |
| 77 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (sum > 1.0 + tolerance) { |
| 78 | ✗ | LOG(Error, "Could not translate an MRTWeightingFactor group for " << modelObject.briefDescription() | |
| 79 | << " because the MRT Weighting Factors would sum to " << sum | ||
| 80 | << ", which is greater than 1."); | ||
| 81 | ✗ | sum -= value; | |
| 82 | ✗ | continue; | |
| 83 | ✗ | } | |
| 84 | |||
| 85 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | translatedMRTWeightingFactors.emplace_back(_people->nameString(), value); |
| 86 | } else { | ||
| 87 | ✗ | LOG(Error, "Could not translate an MRTWeightingFactor group for " << modelObject.briefDescription() << ". Continuing with the rest."); | |
| 88 | } | ||
| 89 | 8 | } | |
| 90 | |||
| 91 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
|
2 | if (translatedMRTWeightingFactors.empty()) { |
| 92 |
8/8✓ 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 17 taken 1 time.
✓ Branch 20 taken 1 time.
✓ Branch 23 taken 1 time.
|
1 | LOG(Error, "ZoneMRTCalculation for zone '" << zone.nameString() |
| 93 | << "' doesn't have at least one valid MRT weighting factor, it will not be translated."); | ||
| 94 | 1 | return boost::none; | |
| 95 | } | ||
| 96 | |||
| 97 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | IdfObject idfObject(openstudio::IddObjectType::ZoneMRTCalculation); |
| 98 |
1/1✓ Branch 1 taken 1 time.
|
1 | m_idfObjects.push_back(idfObject); |
| 99 | |||
| 100 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | idfObject.setString(ZoneMRTCalculationFields::ZoneName, zone.nameString()); |
| 101 | |||
| 102 |
2/2✓ Branch 7 taken 2 times.
✓ Branch 8 taken 1 time.
|
3 | for (const auto& [name, weight] : translatedMRTWeightingFactors) { |
| 103 |
1/1✓ Branch 1 taken 2 times.
|
2 | auto eg = idfObject.pushExtensibleGroup(); |
| 104 |
1/1✓ Branch 1 taken 2 times.
|
2 | eg.setString(ZoneMRTCalculationExtensibleFields::PeopleName, name); |
| 105 |
1/1✓ Branch 1 taken 2 times.
|
2 | eg.setDouble(ZoneMRTCalculationExtensibleFields::MRTWeightingFactor, weight); |
| 106 | 2 | } | |
| 107 | |||
| 108 |
1/1✓ Branch 1 taken 1 time.
|
1 | return idfObject; |
| 109 | 2 | } | |
| 110 | |||
| 111 | } // namespace energyplus | ||
| 112 | |||
| 113 | } // namespace openstudio | ||
| 114 |