GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 91.9% 57 / 0 / 62
Functions: 100.0% 1 / 0 / 1
Branches: 76.0% 92 / 0 / 121

src/energyplus/ForwardTranslator/ForwardTranslateLifeCycleCost.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/LifeCycleCost.hpp"
10 #include "../../model/LifeCycleCostParameters.hpp"
11 #include "../../model/LifeCycleCostParameters_Impl.hpp"
12
13 #include <utilities/idd/LifeCycleCost_NonrecurringCost_FieldEnums.hxx>
14 #include <utilities/idd/LifeCycleCost_RecurringCosts_FieldEnums.hxx>
15 #include "../../utilities/idd/IddEnums.hpp"
16 #include <utilities/idd/IddEnums.hxx>
17
18 using namespace openstudio::model;
19
20 using namespace std;
21
22 namespace openstudio {
23
24 namespace energyplus {
25
26 16 boost::optional<IdfObject> ForwardTranslator::translateLifeCycleCost(LifeCycleCost& modelObject) {
27
2/2
✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
16 boost::optional<LifeCycleCostParameters> lifeCycleCostParameters = modelObject.model().lifeCycleCostParameters();
28
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
16 if (!lifeCycleCostParameters) {
29 ✗ lifeCycleCostParameters = modelObject.model().getUniqueModelObject<LifeCycleCostParameters>();
30 }
31
32
2/2
✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
16 int lengthOfStudyPeriodInMonths = 12 * lifeCycleCostParameters->lengthOfStudyPeriodInYears();
33
34 16 boost::optional<IdfObject> result;
35
36
1/1
✓ Branch 1 taken 16 times.
16 ModelObject item = modelObject.item();
37
6/6
✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
✓ Branch 7 taken 16 times.
✓ Branch 10 taken 16 times.
✓ Branch 13 taken 16 times.
✓ Branch 16 taken 16 times.
16 std::string comment = item.iddObject().name() + ", " + item.name().get();
38
39
3/3
✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
✓ Branch 7 taken 16 times.
16 std::string name = modelObject.name().get();
40
1/1
✓ Branch 1 taken 16 times.
16 std::string category = modelObject.category();
41
1/1
✓ Branch 1 taken 16 times.
16 std::string startOfCosts = modelObject.startOfCosts();
42
1/1
✓ Branch 1 taken 16 times.
16 double totalCost = modelObject.totalCost();
43
1/1
✓ Branch 1 taken 16 times.
16 int yearsFromStart = modelObject.yearsFromStart();
44
1/1
✓ Branch 1 taken 16 times.
16 int monthsFromStart = modelObject.monthsFromStart();
45
1/1
✓ Branch 1 taken 16 times.
16 int repeatPeriodYears = modelObject.repeatPeriodYears();
46
1/1
✓ Branch 1 taken 16 times.
16 int repeatPeriodMonths = modelObject.repeatPeriodMonths();
47
48
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (totalCost == 0) {
49 ✗ return boost::none;
50 }
51
52
3/4
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
16 bool hasRepeatingCosts = (repeatPeriodYears > 0 || repeatPeriodMonths > 0);
53
54 // check for field types of LifeCycleCost:NonrecurringCost {Construction, Salvage, OtherCapital}
55
23/38
✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
✓ Branch 6 taken 8 times.
✓ Branch 7 taken 8 times.
✓ Branch 9 taken 8 times.
✓ Branch 12 taken 8 times.
✓ Branch 14 taken 7 times.
✓ Branch 15 taken 1 time.
✓ Branch 17 taken 7 times.
✓ Branch 20 taken 7 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 7 times.
✓ Branch 24 taken 7 times.
✓ Branch 25 taken 9 times.
✓ Branch 27 taken 7 times.
✓ Branch 28 taken 9 times.
✓ Branch 29 taken 8 times.
✓ Branch 30 taken 8 times.
✓ Branch 32 taken 8 times.
✓ Branch 33 taken 8 times.
✓ Branch 34 taken 16 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 16 times.
✗ Branch 38 not taken.
✓ Branch 39 taken 9 times.
✓ Branch 40 taken 7 times.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
78 if (istringEqual("Construction", category) || istringEqual("Salvage", category) || istringEqual("OtherCapital", category)) {
56
57
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (lengthOfStudyPeriodInMonths >= 12 * yearsFromStart + monthsFromStart) {
58
59 // convert to LifeCycleCost::NonrecurringCosts
60
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 IdfObject idfObject(openstudio::IddObjectType::LifeCycleCost_NonrecurringCost);
61
1/1
✓ Branch 1 taken 9 times.
9 idfObject.setComment(comment);
62
1/1
✓ Branch 1 taken 9 times.
9 m_idfObjects.push_back(idfObject);
63
64
1/1
✓ Branch 1 taken 9 times.
9 idfObject.setString(LifeCycleCost_NonrecurringCostFields::Name, name);
65
1/1
✓ Branch 1 taken 9 times.
9 idfObject.setString(LifeCycleCost_NonrecurringCostFields::Category, category);
66
1/1
✓ Branch 1 taken 9 times.
9 idfObject.setDouble(LifeCycleCost_NonrecurringCostFields::Cost, totalCost);
67
1/1
✓ Branch 1 taken 9 times.
9 idfObject.setString(LifeCycleCost_NonrecurringCostFields::StartofCosts, startOfCosts);
68
69
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7 times.
9 if (yearsFromStart > 0) {
70
1/1
✓ Branch 1 taken 2 times.
2 idfObject.setInt(LifeCycleCost_NonrecurringCostFields::YearsfromStart, yearsFromStart);
71 }
72
73
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (monthsFromStart > 0) {
74 ✗ idfObject.setInt(LifeCycleCost_NonrecurringCostFields::MonthsfromStart, monthsFromStart);
75 }
76
77
1/1
✓ Branch 1 taken 9 times.
9 result = idfObject;
78
79 // may create a recurring cost object to handle replacement costs, shift first replacement costs back one period
80
4/4
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 8 times.
✓ Branch 8 taken 1 time.
18 if (istringEqual("Construction", category)) {
81
1/1
✓ Branch 1 taken 8 times.
8 name += " Replacement";
82 } else {
83
1/1
✓ Branch 1 taken 1 time.
1 name += " Recurring";
84 }
85
1/1
✓ Branch 1 taken 9 times.
9 category = "Replacement";
86 9 yearsFromStart += repeatPeriodYears;
87 9 monthsFromStart += repeatPeriodMonths;
88
89 9 } else {
90 //LOG(Warn, "LifeCycleCost '" << name << "' occurs outside the study period, will not be translated");
91 }
92 }
93
94
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 7 times.
16 if (hasRepeatingCosts) {
95
96
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 time.
9 if (lengthOfStudyPeriodInMonths >= 12 * yearsFromStart + monthsFromStart) {
97
98 // also create a LifeCycleCost::RecurringCosts to capture replacement costs
99
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 IdfObject idfObject(openstudio::IddObjectType::LifeCycleCost_RecurringCosts);
100
1/1
✓ Branch 1 taken 8 times.
8 idfObject.setComment(comment);
101
1/1
✓ Branch 1 taken 8 times.
8 m_idfObjects.push_back(idfObject);
102
103
1/1
✓ Branch 1 taken 8 times.
8 idfObject.setString(LifeCycleCost_RecurringCostsFields::Name, name);
104
1/1
✓ Branch 1 taken 8 times.
8 idfObject.setString(LifeCycleCost_RecurringCostsFields::Category, category);
105
1/1
✓ Branch 1 taken 8 times.
8 idfObject.setDouble(LifeCycleCost_RecurringCostsFields::Cost, totalCost);
106
1/1
✓ Branch 1 taken 8 times.
8 idfObject.setString(LifeCycleCost_RecurringCostsFields::StartofCosts, startOfCosts);
107
108
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (yearsFromStart > 0) {
109
1/1
✓ Branch 1 taken 2 times.
2 idfObject.setInt(LifeCycleCost_RecurringCostsFields::YearsfromStart, yearsFromStart);
110 }
111
112
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (monthsFromStart > 0) {
113 ✗ idfObject.setInt(LifeCycleCost_RecurringCostsFields::MonthsfromStart, monthsFromStart);
114 }
115
116
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (repeatPeriodYears > 0) {
117
1/1
✓ Branch 1 taken 8 times.
8 idfObject.setInt(LifeCycleCost_RecurringCostsFields::RepeatPeriodYears, repeatPeriodYears);
118 }
119
120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (repeatPeriodMonths > 0) {
121 ✗ idfObject.setInt(LifeCycleCost_RecurringCostsFields::RepeatPeriodMonths, repeatPeriodMonths);
122 }
123
124
2/2
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 1 time.
8 if (!result) {
125
1/1
✓ Branch 1 taken 7 times.
7 result = idfObject;
126 }
127 8 } else {
128 //LOG(Warn, "LifeCycleCost '" << name << "' occurs outside the study period, will not be translated");
129 }
130 }
131
132 16 return result;
133 16 }
134
135 } // namespace energyplus
136
137 } // namespace openstudio
138