GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 88.5% 69 / 0 / 78
Functions: 100.0% 2 / 0 / 2
Branches: 77.8% 119 / 0 / 153

src/energyplus/ForwardTranslator/ForwardTranslateLifeCycleCostParameters.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 #include "../../model/Model.hpp"
8 #include "../../model/LifeCycleCostParameters.hpp"
9
10 #include "../../utilities/idf/IdfFile.hpp"
11 #include "../../utilities/idf/IdfExtensibleGroup.hpp"
12 #include "../../utilities/time/Date.hpp"
13
14 #include <utilities/idd/LifeCycleCost_Parameters_FieldEnums.hxx>
15 #include <utilities/idd/LifeCycleCost_UsePriceEscalation_FieldEnums.hxx>
16 #include "../../utilities/idd/IddEnums.hpp"
17 #include <utilities/idd/IddEnums.hxx>
18
19 #include "../../utilities/core/Assert.hpp"
20
21 using namespace openstudio::model;
22
23 using namespace std;
24
25 namespace openstudio {
26
27 namespace energyplus {
28
29 24 void makeUsePriceEscalation(boost::optional<double> rate, const std::string& fuelName, const std::string& baseDateMonth, int baseDateYear,
30 int lengthOfStudyPeriodInYears, std::vector<IdfObject>& idfObjects) {
31
6/7
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 23 times.
✓ Branch 4 taken 1 time.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 23 times.
✓ Branch 9 taken 1 time.
24 if (!rate || rate.get() == 0) {
32 23 return;
33 }
34
35
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 IdfObject idfObject(IddObjectType::LifeCycleCost_UsePriceEscalation);
36
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 idfObject.setName(fuelName + " Use Price Escalation");
37
1/1
✓ Branch 1 taken 1 time.
1 idfObject.setString(LifeCycleCost_UsePriceEscalationFields::Resource, fuelName);
38
1/1
✓ Branch 1 taken 1 time.
1 idfObject.setInt(LifeCycleCost_UsePriceEscalationFields::EscalationStartYear, baseDateYear);
39
1/1
✓ Branch 1 taken 1 time.
1 idfObject.setString(LifeCycleCost_UsePriceEscalationFields::EscalationStartMonth, baseDateMonth);
40
41
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 1 time.
26 for (int i = 0; i < lengthOfStudyPeriodInYears; ++i) {
42
1/1
✓ Branch 1 taken 25 times.
25 IdfExtensibleGroup group = idfObject.pushExtensibleGroup();
43
1/1
✓ Branch 1 taken 25 times.
25 double value = std::pow(1.0 + rate.get(), i);
44
1/1
✓ Branch 1 taken 25 times.
25 group.setDouble(LifeCycleCost_UsePriceEscalationExtensibleFields::YearEscalation, value);
45 25 }
46
47
1/1
✓ Branch 1 taken 1 time.
1 idfObjects.push_back(idfObject);
48 1 }
49
50 869 boost::optional<IdfObject> ForwardTranslator::translateLifeCycleCostParameters(model::LifeCycleCostParameters& modelObject) {
51 // create, register, and name object
52
2/2
✓ Branch 1 taken 869 times.
✓ Branch 4 taken 869 times.
869 IdfObject idfObject = createRegisterAndNameIdfObject(openstudio::IddObjectType::LifeCycleCost_Parameters, modelObject);
53 // This is a unique model object
54
2/2
✓ Branch 1 taken 869 times.
✓ Branch 4 taken 869 times.
869 idfObject.setName("Life Cycle Cost Parameters");
55
56
2/2
✓ Branch 1 taken 869 times.
✓ Branch 4 taken 869 times.
869 idfObject.setString(LifeCycleCost_ParametersFields::DiscountingConvention, modelObject.discountingConvention());
57
58
2/2
✓ Branch 1 taken 869 times.
✓ Branch 4 taken 869 times.
869 idfObject.setString(LifeCycleCost_ParametersFields::InflationApproach, modelObject.inflationApproach());
59
60
1/1
✓ Branch 1 taken 869 times.
869 boost::optional<double> d = modelObject.realDiscountRate();
61
1/2
✓ Branch 0 taken 869 times.
✗ Branch 1 not taken.
869 if (d) {
62
2/2
✓ Branch 1 taken 869 times.
✓ Branch 4 taken 869 times.
869 idfObject.setDouble(LifeCycleCost_ParametersFields::RealDiscountRate, *d);
63 }
64
65
1/1
✓ Branch 1 taken 869 times.
869 d = modelObject.nominalDiscountRate();
66
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 869 times.
869 if (d) {
67 ✗ idfObject.setDouble(LifeCycleCost_ParametersFields::NominalDiscountRate, *d);
68 }
69
70
1/1
✓ Branch 1 taken 869 times.
869 d = modelObject.inflation();
71
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 869 times.
869 if (d) {
72 ✗ idfObject.setDouble(LifeCycleCost_ParametersFields::Inflation, *d);
73 }
74
75
2/3
✓ Branch 1 taken 869 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 869 times.
869 if (!modelObject.isBaseDateMonthDefaulted()) {
76 ✗ idfObject.setString(LifeCycleCost_ParametersFields::BaseDateMonth, modelObject.baseDateMonth().valueDescription());
77 }
78
79
2/2
✓ Branch 1 taken 869 times.
✓ Branch 4 taken 869 times.
869 idfObject.setInt(LifeCycleCost_ParametersFields::BaseDateYear, modelObject.baseDateYear());
80
81
2/3
✓ Branch 1 taken 869 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 869 times.
869 if (!modelObject.isServiceDateMonthDefaulted()) {
82 ✗ idfObject.setString(LifeCycleCost_ParametersFields::ServiceDateMonth, modelObject.serviceDateMonth().valueDescription());
83 }
84
85
2/2
✓ Branch 1 taken 869 times.
✓ Branch 4 taken 869 times.
869 idfObject.setInt(LifeCycleCost_ParametersFields::ServiceDateYear, modelObject.serviceDateYear());
86
87
2/2
✓ Branch 1 taken 869 times.
✓ Branch 4 taken 869 times.
869 idfObject.setInt(LifeCycleCost_ParametersFields::LengthofStudyPeriodinYears, modelObject.lengthOfStudyPeriodInYears());
88
89
1/1
✓ Branch 1 taken 869 times.
869 d = modelObject.taxRate();
90
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 869 times.
869 if (d) {
91 ✗ idfObject.setDouble(LifeCycleCost_ParametersFields::Taxrate, *d);
92 }
93
94
2/3
✓ Branch 1 taken 869 times.
✓ Branch 3 taken 869 times.
✗ Branch 4 not taken.
869 if (modelObject.isDepreciationMethodDefaulted()) {
95
2/2
✓ Branch 1 taken 869 times.
✓ Branch 4 taken 869 times.
1738 idfObject.setString(LifeCycleCost_ParametersFields::DepreciationMethod, "None");
96 } else {
97 ✗ idfObject.setString(LifeCycleCost_ParametersFields::DepreciationMethod, modelObject.depreciationMethod());
98 }
99
100 // if useNISTFuelEscalationRates then load idf obbjects from file in resources
101
3/3
✓ Branch 1 taken 869 times.
✓ Branch 3 taken 867 times.
✓ Branch 4 taken 2 times.
869 if (modelObject.useNISTFuelEscalationRates()) {
102
103
1/1
✓ Branch 1 taken 867 times.
867 boost::optional<std::string> region = modelObject.nistRegion();
104
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 867 times.
867 if (!region) {
105 ✗ region = "U.S. Avg";
106 }
107
1/1
✓ Branch 1 taken 867 times.
867 boost::optional<std::string> sector = modelObject.nistSector();
108
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 867 times.
867 if (!sector) {
109 ✗ sector = "Commercial";
110 }
111
112
5/8
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 329 times.
✓ Branch 3 taken 538 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 538 times.
✓ Branch 9 taken 538 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
1943 static const boost::optional<IdfFile> usePriceEscalationFile = findIdfFile(":/Resources/LCCusePriceEscalationDataSet2011.idf");
113
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 867 times.
✗ Branch 4 not taken.
867 OS_ASSERT(usePriceEscalationFile);
114
115
4/4
✓ Branch 1 taken 867 times.
✓ Branch 4 taken 867 times.
✓ Branch 11 taken 60690 times.
✓ Branch 12 taken 867 times.
61557 for (const IdfObject& object : usePriceEscalationFile->objects()) {
116
1/1
✓ Branch 1 taken 60690 times.
60690 std::string name = object.nameString();
117
8/8
✓ Branch 1 taken 60690 times.
✓ Branch 4 taken 12138 times.
✓ Branch 5 taken 48552 times.
✓ Branch 7 taken 12138 times.
✓ Branch 10 taken 4330 times.
✓ Branch 11 taken 7808 times.
✓ Branch 12 taken 4330 times.
✓ Branch 13 taken 56360 times.
60690 if ((name.find(*region) == 0) && (name.find(*sector) != string::npos)) {
118
1/1
✓ Branch 1 taken 4330 times.
4330 m_idfObjects.push_back(object);
119 }
120 61557 }
121 867 } else {
122
123 2 std::string baseDateMonth;
124
2/3
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
2 if (!modelObject.isBaseDateMonthDefaulted()) {
125 ✗ baseDateMonth = modelObject.baseDateMonth().valueDescription();
126 }
127
1/1
✓ Branch 1 taken 2 times.
2 int baseDateYear = modelObject.baseDateYear();
128
1/1
✓ Branch 1 taken 2 times.
2 int lengthOfStudyPeriodInYears = modelObject.lengthOfStudyPeriodInYears();
129
130 // make a use price escalation for each fuel type we have inflation for
131
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 makeUsePriceEscalation(modelObject.electricityInflation(), "Electricity", baseDateMonth, baseDateYear, lengthOfStudyPeriodInYears,
132 2 m_idfObjects);
133
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
4 makeUsePriceEscalation(modelObject.naturalGasInflation(), "NaturalGas", baseDateMonth, baseDateYear, lengthOfStudyPeriodInYears, m_idfObjects);
134
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
4 makeUsePriceEscalation(modelObject.steamInflation(), "Steam", baseDateMonth, baseDateYear, lengthOfStudyPeriodInYears, m_idfObjects);
135
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
4 makeUsePriceEscalation(modelObject.gasolineInflation(), "Gasoline", baseDateMonth, baseDateYear, lengthOfStudyPeriodInYears, m_idfObjects);
136
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
4 makeUsePriceEscalation(modelObject.dieselInflation(), "Diesel", baseDateMonth, baseDateYear, lengthOfStudyPeriodInYears, m_idfObjects);
137
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
4 makeUsePriceEscalation(modelObject.coalInflation(), "Coal", baseDateMonth, baseDateYear, lengthOfStudyPeriodInYears, m_idfObjects);
138
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
4 makeUsePriceEscalation(modelObject.fuelOil1Inflation(), "FuelOilNo1", baseDateMonth, baseDateYear, lengthOfStudyPeriodInYears, m_idfObjects);
139
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
4 makeUsePriceEscalation(modelObject.fuelOil2Inflation(), "FuelOilNo2", baseDateMonth, baseDateYear, lengthOfStudyPeriodInYears, m_idfObjects);
140
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
4 makeUsePriceEscalation(modelObject.propaneInflation(), "Propane", baseDateMonth, baseDateYear, lengthOfStudyPeriodInYears, m_idfObjects);
141
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
4 makeUsePriceEscalation(modelObject.waterInflation(), "Water", baseDateMonth, baseDateYear, lengthOfStudyPeriodInYears, m_idfObjects);
142
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
4 makeUsePriceEscalation(modelObject.otherFuel1Inflation(), "OtherFuel1", baseDateMonth, baseDateYear, lengthOfStudyPeriodInYears, m_idfObjects);
143
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
4 makeUsePriceEscalation(modelObject.otherFuel2Inflation(), "OtherFuel2", baseDateMonth, baseDateYear, lengthOfStudyPeriodInYears, m_idfObjects);
144 2 }
145
146
1/1
✓ Branch 1 taken 869 times.
1738 return idfObject;
147 869 }
148
149 } // namespace energyplus
150
151 } // namespace openstudio
152