src/energyplus/ReverseTranslator/ReverseTranslateFanSystemModel.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 "../ReverseTranslator.hpp" | ||
| 7 | |||
| 8 | #include "../../model/FanSystemModel.hpp" | ||
| 9 | |||
| 10 | #include "../../model/Schedule.hpp" | ||
| 11 | #include "../../model/Schedule_Impl.hpp" | ||
| 12 | #include "../../model/Node.hpp" | ||
| 13 | #include "../../model/Node_Impl.hpp" | ||
| 14 | #include "../../model/Curve.hpp" | ||
| 15 | #include "../../model/Curve_Impl.hpp" | ||
| 16 | #include "../../model/ThermalZone.hpp" | ||
| 17 | #include "../../model/ThermalZone_Impl.hpp" | ||
| 18 | #include "../../model/Space.hpp" | ||
| 19 | #include "../../model/Space_Impl.hpp" | ||
| 20 | |||
| 21 | #include "../../utilities/idf/IdfExtensibleGroup.hpp" | ||
| 22 | |||
| 23 | #include <utilities/idd/Fan_SystemModel_FieldEnums.hxx> | ||
| 24 | #include <utilities/idd/IddEnums.hxx> | ||
| 25 | |||
| 26 | using namespace openstudio::model; | ||
| 27 | |||
| 28 | namespace openstudio { | ||
| 29 | |||
| 30 | namespace energyplus { | ||
| 31 | |||
| 32 | 6 | boost::optional<ModelObject> ReverseTranslator::translateFanSystemModel(const WorkspaceObject& workspaceObject) { | |
| 33 | 6 | boost::optional<ModelObject> result; | |
| 34 | 6 | boost::optional<WorkspaceObject> _wo; | |
| 35 | 6 | boost::optional<ModelObject> _mo; | |
| 36 | |||
| 37 | // Instantiate an object of the class to store the values, | ||
| 38 | // but we don't return it until we know it's ok | ||
| 39 |
1/1✓ Branch 1 taken 6 times.
|
6 | openstudio::model::FanSystemModel modelObject(m_model); |
| 40 | |||
| 41 | // Name | ||
| 42 |
2/3✓ Branch 1 taken 6 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
|
12 | if (boost::optional<std::string> _name = workspaceObject.name()) { |
| 43 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | modelObject.setName(_name.get()); |
| 44 | 6 | } | |
| 45 | |||
| 46 | // Availability Schedule Name: Optional Object | ||
| 47 |
2/3✓ Branch 1 taken 6 times.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
|
12 | if ((_wo = workspaceObject.getTarget(Fan_SystemModelFields::AvailabilityScheduleName))) { |
| 48 |
3/4✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
|
12 | if ((_mo = translateAndMapWorkspaceObject(_wo.get()))) { |
| 49 |
3/4✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
|
12 | if (boost::optional<Schedule> _availabilitySchedule = _mo->optionalCast<Schedule>()) { |
| 50 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | modelObject.setAvailabilitySchedule(_availabilitySchedule.get()); |
| 51 | } else { | ||
| 52 | ✗ | LOG(Warn, workspaceObject.briefDescription() << " has a wrong type for 'Availability Schedule Name'"); | |
| 53 | 6 | } | |
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | // Air Inlet Node Name: Required Node | ||
| 58 | |||
| 59 | // Air Outlet Node Name: Required Node | ||
| 60 | |||
| 61 | // Design Maximum Air Flow Rate: Required Double | ||
| 62 |
2/3✓ Branch 1 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
|
12 | if (boost::optional<double> _designMaximumAirFlowRate = workspaceObject.getDouble(Fan_SystemModelFields::DesignMaximumAirFlowRate)) { |
| 63 | ✗ | modelObject.setDesignMaximumAirFlowRate(_designMaximumAirFlowRate.get()); | |
| 64 | } else { | ||
| 65 |
1/1✓ Branch 1 taken 6 times.
|
6 | modelObject.autosizeDesignMaximumAirFlowRate(); |
| 66 | } | ||
| 67 | |||
| 68 | // Speed Control Method: Optional String | ||
| 69 |
2/3✓ Branch 1 taken 6 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
|
12 | if (boost::optional<std::string> _speedControlMethod = workspaceObject.getString(Fan_SystemModelFields::SpeedControlMethod)) { |
| 70 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | modelObject.setSpeedControlMethod(_speedControlMethod.get()); |
| 71 | 6 | } | |
| 72 | |||
| 73 | // Electric Power Minimum Flow Rate Fraction: Optional Double | ||
| 74 | 6 | if (boost::optional<double> _electricPowerMinimumFlowRateFraction = | |
| 75 |
2/3✓ Branch 1 taken 6 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
|
12 | workspaceObject.getDouble(Fan_SystemModelFields::ElectricPowerMinimumFlowRateFraction)) { |
| 76 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | modelObject.setElectricPowerMinimumFlowRateFraction(_electricPowerMinimumFlowRateFraction.get()); |
| 77 | } | ||
| 78 | |||
| 79 | // Design Pressure Rise: Required Double | ||
| 80 |
2/3✓ Branch 1 taken 6 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
|
12 | if (boost::optional<double> _designPressureRise = workspaceObject.getDouble(Fan_SystemModelFields::DesignPressureRise)) { |
| 81 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | modelObject.setDesignPressureRise(_designPressureRise.get()); |
| 82 | } else { | ||
| 83 | // required, without a sensible default... so throw | ||
| 84 | ✗ | LOG(Error, "For " << workspaceObject.briefDescription() << ", cannot find required property 'Design Pressure Rise'"); | |
| 85 | ✗ | return result; | |
| 86 | } | ||
| 87 | |||
| 88 | // Motor Efficiency: Optional Double | ||
| 89 |
2/3✓ Branch 1 taken 6 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
|
12 | if (boost::optional<double> _motorEfficiency = workspaceObject.getDouble(Fan_SystemModelFields::MotorEfficiency)) { |
| 90 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | modelObject.setMotorEfficiency(_motorEfficiency.get()); |
| 91 | } | ||
| 92 | |||
| 93 | // Motor In Air Stream Fraction: Optional Double | ||
| 94 |
2/3✓ Branch 1 taken 6 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
|
12 | if (boost::optional<double> _motorInAirStreamFraction = workspaceObject.getDouble(Fan_SystemModelFields::MotorInAirStreamFraction)) { |
| 95 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | modelObject.setMotorInAirStreamFraction(_motorInAirStreamFraction.get()); |
| 96 | } | ||
| 97 | |||
| 98 | // Design Electric Power Consumption: Optional Double | ||
| 99 |
2/3✓ Branch 1 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
|
12 | if (boost::optional<double> _designElectricPowerConsumption = workspaceObject.getDouble(Fan_SystemModelFields::DesignElectricPowerConsumption)) { |
| 100 | ✗ | modelObject.setDesignElectricPowerConsumption(_designElectricPowerConsumption.get()); | |
| 101 | } else { | ||
| 102 |
1/1✓ Branch 1 taken 6 times.
|
6 | modelObject.autosizeDesignElectricPowerConsumption(); |
| 103 | } | ||
| 104 | |||
| 105 | // Design Power Sizing Method: Optional String | ||
| 106 |
2/3✓ Branch 1 taken 6 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
|
12 | if (boost::optional<std::string> _designPowerSizingMethod = workspaceObject.getString(Fan_SystemModelFields::DesignPowerSizingMethod)) { |
| 107 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | modelObject.setDesignPowerSizingMethod(_designPowerSizingMethod.get()); |
| 108 | 6 | } | |
| 109 | |||
| 110 | // Electric Power Per Unit Flow Rate: Optional Double | ||
| 111 |
2/3✓ Branch 1 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
|
12 | if (boost::optional<double> _electricPowerPerUnitFlowRate = workspaceObject.getDouble(Fan_SystemModelFields::ElectricPowerPerUnitFlowRate)) { |
| 112 | ✗ | modelObject.setElectricPowerPerUnitFlowRate(_electricPowerPerUnitFlowRate.get()); | |
| 113 | } | ||
| 114 | |||
| 115 | // Electric Power Per Unit Flow Rate Per Unit Pressure: Optional Double | ||
| 116 | 6 | if (boost::optional<double> _electricPowerPerUnitFlowRatePerUnitPressure = | |
| 117 |
2/3✓ Branch 1 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
|
12 | workspaceObject.getDouble(Fan_SystemModelFields::ElectricPowerPerUnitFlowRatePerUnitPressure)) { |
| 118 | ✗ | modelObject.setElectricPowerPerUnitFlowRatePerUnitPressure(_electricPowerPerUnitFlowRatePerUnitPressure.get()); | |
| 119 | } | ||
| 120 | |||
| 121 | // Fan Total Efficiency: Optional Double | ||
| 122 |
2/3✓ Branch 1 taken 6 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
|
12 | if (boost::optional<double> _fanTotalEfficiency = workspaceObject.getDouble(Fan_SystemModelFields::FanTotalEfficiency)) { |
| 123 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | modelObject.setFanTotalEfficiency(_fanTotalEfficiency.get()); |
| 124 | } | ||
| 125 | |||
| 126 | // Electric Power Function of Flow Fraction Curve Name: Optional Object | ||
| 127 |
2/3✓ Branch 1 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
|
12 | if ((_wo = workspaceObject.getTarget(Fan_SystemModelFields::ElectricPowerFunctionofFlowFractionCurveName))) { |
| 128 | ✗ | if ((_mo = translateAndMapWorkspaceObject(_wo.get()))) { | |
| 129 | ✗ | if (boost::optional<Curve> _electricPowerFunctionofFlowFractionCurve = _mo->optionalCast<Curve>()) { | |
| 130 | ✗ | modelObject.setElectricPowerFunctionofFlowFractionCurve(_electricPowerFunctionofFlowFractionCurve.get()); | |
| 131 | } else { | ||
| 132 | ✗ | LOG(Warn, workspaceObject.briefDescription() << " has a wrong type for 'Electric Power Function of Flow Fraction Curve Name'"); | |
| 133 | ✗ | } | |
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | // Night Ventilation Mode Pressure Rise: Optional Double | ||
| 138 | 6 | if (boost::optional<double> _nightVentilationModePressureRise = | |
| 139 |
2/3✓ Branch 1 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
|
12 | workspaceObject.getDouble(Fan_SystemModelFields::NightVentilationModePressureRise)) { |
| 140 | ✗ | modelObject.setNightVentilationModePressureRise(_nightVentilationModePressureRise.get()); | |
| 141 | } | ||
| 142 | |||
| 143 | // Night Ventilation Mode Flow Fraction: Optional Double | ||
| 144 | 6 | if (boost::optional<double> _nightVentilationModeFlowFraction = | |
| 145 |
2/3✓ Branch 1 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
|
12 | workspaceObject.getDouble(Fan_SystemModelFields::NightVentilationModeFlowFraction)) { |
| 146 | ✗ | modelObject.setNightVentilationModeFlowFraction(_nightVentilationModeFlowFraction.get()); | |
| 147 | } | ||
| 148 | |||
| 149 | // Motor Loss Zone Name: Optional Object | ||
| 150 |
2/3✓ Branch 1 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
|
12 | if ((_wo = workspaceObject.getTarget(Fan_SystemModelFields::MotorLossZoneName))) { |
| 151 | ✗ | if ((_mo = translateAndMapWorkspaceObject(_wo.get()))) { | |
| 152 | // Zone is translated, and a Space is returned instead | ||
| 153 | ✗ | if (boost::optional<Space> space_ = _mo->optionalCast<Space>()) { | |
| 154 | ✗ | if (auto z_ = space_->thermalZone()) { | |
| 155 | ✗ | modelObject.setMotorLossZone(z_.get()); | |
| 156 | ✗ | } | |
| 157 | } else { | ||
| 158 | ✗ | LOG(Warn, workspaceObject.briefDescription() << " has a wrong type for 'Motor Loss Zone Name'"); | |
| 159 | ✗ | } | |
| 160 | } | ||
| 161 | } | ||
| 162 | |||
| 163 | // Motor Loss Radiative Fraction: Optional Double | ||
| 164 |
2/3✓ Branch 1 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
|
12 | if (boost::optional<double> _motorLossRadiativeFraction = workspaceObject.getDouble(Fan_SystemModelFields::MotorLossRadiativeFraction)) { |
| 165 | ✗ | modelObject.setMotorLossRadiativeFraction(_motorLossRadiativeFraction.get()); | |
| 166 | } | ||
| 167 | |||
| 168 | // End-Use Subcategory: Optional String | ||
| 169 |
2/3✓ Branch 1 taken 6 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
|
12 | if (boost::optional<std::string> _endUseSubcategory = workspaceObject.getString(Fan_SystemModelFields::EndUseSubcategory)) { |
| 170 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | modelObject.setEndUseSubcategory(_endUseSubcategory.get()); |
| 171 | 6 | } | |
| 172 | |||
| 173 | // Number of Speeds: Optional Integer | ||
| 174 |
1/1✓ Branch 1 taken 6 times.
|
6 | std::vector<IdfExtensibleGroup> extensibleGroups = workspaceObject.extensibleGroups(); |
| 175 | |||
| 176 |
1/1✓ Branch 1 taken 6 times.
|
6 | boost::optional<int> _numberofSpeeds = workspaceObject.getInt(Fan_SystemModelFields::NumberofSpeeds); |
| 177 | 6 | int nExts = extensibleGroups.size(); | |
| 178 | 6 | int nspeeds = 0; | |
| 179 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (_numberofSpeeds) { |
| 180 |
1/1✓ Branch 1 taken 6 times.
|
6 | nspeeds = _numberofSpeeds.get(); |
| 181 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (nExts < nspeeds) { |
| 182 | ✗ | LOG(Warn, workspaceObject.briefDescription() << " lists " << nspeeds << " Speeds, but has only " << nExts << " extensibleGroups."); | |
| 183 | ✗ | nspeeds = nExts; | |
| 184 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
|
6 | } else if (nExts > nspeeds) { |
| 185 |
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, workspaceObject.briefDescription() << " lists " << nspeeds << " Speeds, but has more with " << nExts |
| 186 | << " extensibleGroups. Only the " << nspeeds << " first ones will be used."); | ||
| 187 | } | ||
| 188 | } | ||
| 189 | |||
| 190 | 6 | std::vector<FanSystemModelSpeed> speeds; | |
| 191 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 6 times.
|
26 | for (auto i = 0; i < nspeeds; ++i) { |
| 192 |
1/1✓ Branch 2 taken 20 times.
|
20 | boost::optional<double> _flowFraction = extensibleGroups[i].getDouble(Fan_SystemModelExtensibleFields::SpeedFlowFraction); |
| 193 |
1/1✓ Branch 2 taken 20 times.
|
20 | boost::optional<double> _electricPowerFraction = extensibleGroups[i].getDouble(Fan_SystemModelExtensibleFields::SpeedElectricPowerFraction); |
| 194 |
3/6✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 20 times.
✗ Branch 7 not taken.
|
20 | if (_flowFraction.has_value() && _electricPowerFraction.has_value()) { |
| 195 | |||
| 196 | // try to create a Speed, which will throw in case wrong type, or wrong double value. Here we let it slide though | ||
| 197 | try { | ||
| 198 |
4/4✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
✓ Branch 7 taken 18 times.
✓ Branch 10 taken 18 times.
|
20 | speeds.push_back(FanSystemModelSpeed(_flowFraction.get(), _electricPowerFraction.get())); |
| 199 | 2 | } catch (...) { | |
| 200 | // The Speed Ctor threw, so there's a wrong type, or a wrong double | ||
| 201 |
9/9✓ 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 20 taken 2 times.
✓ Branch 23 taken 2 times.
✓ Branch 26 taken 2 times.
|
2 | LOG(Error, "Could not create Speed " << i << " in FanSystemModel " << modelObject.nameString()); |
| 202 | 2 | } | |
| 203 | |||
| 204 | } else { | ||
| 205 | ✗ | LOG(Error, "Speed " << i << " is invalid, both flow Fraction and Electric Power Fraction are required. Ignoring."); | |
| 206 | } | ||
| 207 | } | ||
| 208 |
1/1✓ Branch 1 taken 6 times.
|
6 | modelObject.setSpeeds(speeds); |
| 209 | |||
| 210 |
1/1✓ Branch 1 taken 6 times.
|
6 | result = modelObject; |
| 211 | 6 | return result; | |
| 212 | 6 | } // End of translate function | |
| 213 | |||
| 214 | } // end namespace energyplus | ||
| 215 | |||
| 216 | } // end namespace openstudio | ||
| 217 |