GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 68.9% 268 / 0 / 389
Functions: 75.5% 74 / 0 / 98
Branches: 41.8% 202 / 0 / 483

src/model/GeneratorFuelSupply.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 "Model.hpp"
7 #include "Model_Impl.hpp"
8
9 #include "GeneratorFuelCell.hpp"
10 #include "GeneratorFuelCell_Impl.hpp"
11 #include "GeneratorFuelSupply.hpp"
12 #include "GeneratorFuelSupply_Impl.hpp"
13
14 #include "Node.hpp"
15 #include "Node_Impl.hpp"
16 #include "Schedule.hpp"
17 #include "Schedule_Impl.hpp"
18 #include "ScheduleConstant.hpp"
19 #include "ScheduleConstant_Impl.hpp"
20 #include "CurveCubic.hpp"
21 #include "CurveCubic_Impl.hpp"
22 #include "ScheduleTypeLimits.hpp"
23 #include "ScheduleTypeLimits_Impl.hpp"
24 #include "ScheduleTypeRegistry.hpp"
25
26 #include "../utilities/idf/WorkspaceExtensibleGroup.hpp"
27
28 #include <utilities/idd/IddFactory.hxx>
29 #include <utilities/idd/IddEnums.hxx>
30 #include <utilities/idd/OS_Generator_FuelSupply_FieldEnums.hxx>
31
32 #include "../utilities/units/Unit.hpp"
33
34 #include "../utilities/core/Assert.hpp"
35
36 namespace openstudio {
37 namespace model {
38
39 136 FuelSupplyConstituent::FuelSupplyConstituent(const std::string& constituentName, double molarFraction)
40 136 : m_name(constituentName), m_molarFraction(molarFraction) {
41
42
2/4
✓ Branch 0 taken 136 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 136 times.
136 if ((m_molarFraction < 0) || (m_molarFraction > 1)) {
43 ✗ LOG_AND_THROW("Unable to create constituent '" << m_name << "', molar fraction of " << m_molarFraction << " is outside the range [0, 1]");
44 }
45
3/3
✓ Branch 1 taken 136 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 135 times.
136 if (!isValid(m_name)) {
46
17/17
✓ 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 25 taken 1 time.
✓ Branch 28 taken 1 time.
✓ Branch 31 taken 1 time.
✓ Branch 34 taken 1 time.
✓ Branch 37 taken 1 time.
✓ Branch 40 taken 1 time.
✓ Branch 43 taken 1 time.
✓ Branch 46 taken 1 time.
✓ Branch 50 taken 1 time.
✓ Branch 53 taken 1 time.
1 LOG_AND_THROW("ConstituentName '" << m_name << " is not valid. Check FuelSupplyConstituent::constituentNameValues() to see possible names.");
47 }
48 136 }
49
50 102 std::string FuelSupplyConstituent::constituentName() const {
51 102 return m_name;
52 }
53
54 134 double FuelSupplyConstituent::molarFraction() const {
55 134 return m_molarFraction;
56 }
57
58 136 bool FuelSupplyConstituent::isValid(const std::string& constituentName) {
59
1/1
✓ Branch 1 taken 136 times.
136 std::vector<std::string> validConstituentNames = constituentNameValues();
60
1/1
✓ Branch 3 taken 136 times.
136 return std::find_if(validConstituentNames.begin(), validConstituentNames.end(),
61 897 [&constituentName](const auto& s) { return istringEqual(s, constituentName); })
62 408 != validConstituentNames.end();
63 136 }
64
65 136 std::vector<std::string> FuelSupplyConstituent::constituentNameValues() {
66
5/5
✓ Branch 1 taken 136 times.
✓ Branch 4 taken 136 times.
✓ Branch 7 taken 136 times.
✓ Branch 10 taken 136 times.
✓ Branch 13 taken 136 times.
136 IddObject obj = IddFactory::instance().getObject(GeneratorFuelSupply::iddObjectType()).get();
67 // Return IddKeyNames in extensible portion
68
2/2
✓ Branch 1 taken 136 times.
✓ Branch 4 taken 136 times.
272 return getIddKeyNames(obj, obj.numFields() + OS_Generator_FuelSupplyExtensibleFields::ConstituentName);
69 136 }
70
71 ✗ std::vector<std::string> FuelSupplyConstituent::validConstituentNameValues() {
72 ✗ return constituentNameValues();
73 }
74
75 ✗ std::ostream& operator<<(std::ostream& out, const openstudio::model::FuelSupplyConstituent& constituent) {
76 ✗ out << "name=" << constituent.constituentName() << ", molar fraction=" << constituent.molarFraction();
77 ✗ return out;
78 }
79
80 namespace detail {
81
82 8 GeneratorFuelSupply_Impl::GeneratorFuelSupply_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle)
83 8 : ModelObject_Impl(idfObject, model, keepHandle) {
84
4/6
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 7 taken 8 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 8 times.
✗ Branch 13 not taken.
8 OS_ASSERT(idfObject.iddObject().type() == GeneratorFuelSupply::iddObjectType());
85 8 }
86
87 ✗ GeneratorFuelSupply_Impl::GeneratorFuelSupply_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle)
88 ✗ : ModelObject_Impl(other, model, keepHandle) {
89 ✗ OS_ASSERT(other.iddObject().type() == GeneratorFuelSupply::iddObjectType());
90 ✗ }
91
92 6 GeneratorFuelSupply_Impl::GeneratorFuelSupply_Impl(const GeneratorFuelSupply_Impl& other, Model_Impl* model, bool keepHandle)
93 6 : ModelObject_Impl(other, model, keepHandle) {}
94
95 ✗ const std::vector<std::string>& GeneratorFuelSupply_Impl::outputVariableNames() const {
96 ✗ static const std::vector<std::string> result;
97 ✗ return result;
98 }
99
100 ✗ IddObjectType GeneratorFuelSupply_Impl::iddObjectType() const {
101 ✗ return GeneratorFuelSupply::iddObjectType();
102 }
103
104 ✗ std::vector<IddObjectType> GeneratorFuelSupply_Impl::allowableChildTypes() const {
105 ✗ std::vector<IddObjectType> result;
106 ✗ result.push_back(IddObjectType::OS_Curve_Cubic);
107 ✗ return result;
108 ✗ }
109
110 // Returns the children object
111 ✗ std::vector<ModelObject> GeneratorFuelSupply_Impl::children() const {
112 ✗ std::vector<ModelObject> result;
113 ✗ boost::optional<CurveCubic> curveC;
114
115 ✗ if ((curveC = compressorPowerMultiplierFunctionofFuelRateCurve())) {
116 ✗ result.push_back(curveC.get());
117 }
118
119 ✗ return result;
120 ✗ }
121
122 // Get the parent GeneratorFuelCell
123 ✗ boost::optional<GeneratorFuelCell> GeneratorFuelSupply_Impl::fuelCell() const {
124
125 ✗ boost::optional<GeneratorFuelCell> fc;
126 // We use getModelObjectSources to check if more than one
127 ✗ std::vector<GeneratorFuelCell> fcs = getObject<ModelObject>().getModelObjectSources<GeneratorFuelCell>(GeneratorFuelCell::iddObjectType());
128
129 ✗ if (!fcs.empty()) {
130 ✗ if (fcs.size() > 1u) {
131 ✗ LOG(Error, briefDescription() << " is referenced by more than one GeneratorFuelCell, returning the first");
132 }
133 ✗ fc = fcs[0];
134 }
135 ✗ return fc;
136 ✗ }
137
138 ✗ std::vector<ScheduleTypeKey> GeneratorFuelSupply_Impl::getScheduleTypeKeys(const Schedule& schedule) const {
139 ✗ std::vector<ScheduleTypeKey> result;
140 ✗ UnsignedVector fieldIndices = getSourceIndices(schedule.handle());
141 ✗ UnsignedVector::const_iterator b(fieldIndices.begin());
142 ✗ UnsignedVector::const_iterator e(fieldIndices.end());
143 ✗ if (std::find(b, e, OS_Generator_FuelSupplyFields::FuelTemperatureScheduleName) != e) {
144 ✗ result.push_back(ScheduleTypeKey("GeneratorFuelSupply", "Fuel Temperature"));
145 }
146 ✗ return result;
147 ✗ }
148
149 4 std::string GeneratorFuelSupply_Impl::fuelTemperatureModelingMode() const {
150
1/1
✓ Branch 1 taken 4 times.
4 boost::optional<std::string> value = getString(OS_Generator_FuelSupplyFields::FuelTemperatureModelingMode, true);
151
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if (!value) {
152 ✗ LOG_AND_THROW(" does not have fuelTemperatureModelingMode");
153 }
154
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
8 return value.get();
155 4 }
156
157 3 boost::optional<Node> GeneratorFuelSupply_Impl::fuelTemperatureReferenceNode() const {
158
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 return getObject<ModelObject>().getModelObjectTarget<Node>(OS_Generator_FuelSupplyFields::FuelTemperatureReferenceNodeName);
159 }
160
161 4 boost::optional<Schedule> GeneratorFuelSupply_Impl::fuelTemperatureSchedule() const {
162
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
4 return getObject<ModelObject>().getModelObjectTarget<Schedule>(OS_Generator_FuelSupplyFields::FuelTemperatureScheduleName);
163 }
164
165 10 CurveCubic GeneratorFuelSupply_Impl::compressorPowerMultiplierFunctionofFuelRateCurve() const {
166
1/1
✓ Branch 1 taken 10 times.
20 boost::optional<CurveCubic> value = getObject<ModelObject>().getModelObjectTarget<CurveCubic>(
167
1/1
✓ Branch 1 taken 10 times.
10 OS_Generator_FuelSupplyFields::CompressorPowerMultiplierFunctionofFuelRateCurveName);
168
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
10 if (!value) {
169 ✗ LOG_AND_THROW(" does not have compressorPowerMultiplierFunctionofFuelRateCurve");
170 }
171
2/2
✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
20 return value.get();
172 10 }
173
174 4 double GeneratorFuelSupply_Impl::compressorHeatLossFactor() const {
175
1/1
✓ Branch 1 taken 4 times.
4 boost::optional<double> value = getDouble(OS_Generator_FuelSupplyFields::CompressorHeatLossFactor, true);
176
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if (!value) {
177 ✗ LOG_AND_THROW(" does not have compressorHeatLossFactor");
178 }
179
1/1
✓ Branch 1 taken 4 times.
8 return value.get();
180 }
181
182 6 std::string GeneratorFuelSupply_Impl::fuelType() const {
183
1/1
✓ Branch 1 taken 6 times.
6 boost::optional<std::string> value = getString(OS_Generator_FuelSupplyFields::FuelType, true);
184
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 if (!value) {
185 ✗ LOG_AND_THROW(" does not have fuelType");
186 }
187
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
12 return value.get();
188 6 }
189
190 7 boost::optional<double> GeneratorFuelSupply_Impl::liquidGenericFuelLowerHeatingValue() const {
191
1/1
✓ Branch 1 taken 7 times.
7 boost::optional<double> value = getDouble(OS_Generator_FuelSupplyFields::LiquidGenericFuelLowerHeatingValue, true);
192 7 return value;
193 }
194
195 7 boost::optional<double> GeneratorFuelSupply_Impl::liquidGenericFuelHigherHeatingValue() const {
196
1/1
✓ Branch 1 taken 7 times.
7 boost::optional<double> value = getDouble(OS_Generator_FuelSupplyFields::LiquidGenericFuelHigherHeatingValue, true);
197 7 return value;
198 }
199
200 7 boost::optional<double> GeneratorFuelSupply_Impl::liquidGenericFuelMolecularWeight() const {
201
1/1
✓ Branch 1 taken 7 times.
7 boost::optional<double> value = getDouble(OS_Generator_FuelSupplyFields::LiquidGenericFuelMolecularWeight, true);
202 7 return value;
203 }
204
205 7 boost::optional<double> GeneratorFuelSupply_Impl::liquidGenericFuelCO2EmissionFactor() const {
206
1/1
✓ Branch 1 taken 7 times.
7 boost::optional<double> value = getDouble(OS_Generator_FuelSupplyFields::LiquidGenericFuelCO2EmissionFactor, true);
207 7 return value;
208 }
209
210 8 bool GeneratorFuelSupply_Impl::setFuelTemperatureModelingMode(const std::string& fuelTemperatureModelingMode) {
211 8 bool result = setString(OS_Generator_FuelSupplyFields::FuelTemperatureModelingMode, fuelTemperatureModelingMode);
212 8 return result;
213 }
214
215 ✗ void GeneratorFuelSupply_Impl::resetFuelTemperatureModelingMode() {
216 ✗ bool result = setString(OS_Generator_FuelSupplyFields::FuelTemperatureModelingMode, "Scheduled");
217 ✗ OS_ASSERT(result);
218 ✗ ScheduleConstant schedule(this->model());
219 ✗ schedule.setValue(20);
220 ✗ result = setFuelTemperatureSchedule(schedule);
221 ✗ OS_ASSERT(result);
222 ✗ }
223
224 ✗ bool GeneratorFuelSupply_Impl::setFuelTemperatureReferenceNode(const Node& connection) {
225 ✗ bool result = setPointer(OS_Generator_FuelSupplyFields::FuelTemperatureReferenceNodeName, connection.handle());
226 ✗ return result;
227 }
228
229 ✗ void GeneratorFuelSupply_Impl::resetFuelTemperatureReferenceNode() {
230 ✗ bool result = setString(OS_Generator_FuelSupplyFields::FuelTemperatureReferenceNodeName, "");
231 ✗ OS_ASSERT(result);
232 ✗ }
233
234 8 bool GeneratorFuelSupply_Impl::setFuelTemperatureSchedule(Schedule& schedule) {
235
3/3
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 7 taken 8 times.
32 bool result = setSchedule(OS_Generator_FuelSupplyFields::FuelTemperatureScheduleName, "GeneratorFuelSupply", "Fuel Temperature", schedule);
236 8 return result;
237 }
238
239 ✗ void GeneratorFuelSupply_Impl::resetFuelTemperatureSchedule() {
240 ✗ bool result = setString(OS_Generator_FuelSupplyFields::FuelTemperatureScheduleName, "");
241 ✗ OS_ASSERT(result);
242 ✗ }
243
244 9 bool GeneratorFuelSupply_Impl::setCompressorPowerMultiplierFunctionofFuelRateCurve(const CurveCubic& cubicCurves) {
245
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 bool result = setPointer(OS_Generator_FuelSupplyFields::CompressorPowerMultiplierFunctionofFuelRateCurveName, cubicCurves.handle());
246 9 return result;
247 }
248
249 8 bool GeneratorFuelSupply_Impl::setCompressorHeatLossFactor(double compressorHeatLossFactor) {
250 8 bool result = setDouble(OS_Generator_FuelSupplyFields::CompressorHeatLossFactor, compressorHeatLossFactor);
251 8 return result;
252 }
253
254 ✗ void GeneratorFuelSupply_Impl::resetCompressorHeatLossFactor() {
255 ✗ bool result = setDouble(OS_Generator_FuelSupplyFields::CompressorHeatLossFactor, 0);
256 ✗ OS_ASSERT(result);
257 ✗ }
258
259 9 bool GeneratorFuelSupply_Impl::setFuelType(const std::string& fuelType) {
260 9 bool result = setString(OS_Generator_FuelSupplyFields::FuelType, fuelType);
261 9 return result;
262 }
263
264 1 void GeneratorFuelSupply_Impl::resetFuelType() {
265 // TODO A bit unusual to set a default that doesn't exist in IDD
266
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 bool result = setString(OS_Generator_FuelSupplyFields::FuelType, "GaseousConstituents");
267
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 OS_ASSERT(result);
268 1 }
269
270 1 bool GeneratorFuelSupply_Impl::setLiquidGenericFuelLowerHeatingValue(double liquidGenericFuelLowerHeatingValue) {
271 1 bool result = setDouble(OS_Generator_FuelSupplyFields::LiquidGenericFuelLowerHeatingValue, liquidGenericFuelLowerHeatingValue);
272
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 OS_ASSERT(result);
273 1 return result;
274 }
275
276 1 void GeneratorFuelSupply_Impl::resetLiquidGenericFuelLowerHeatingValue() {
277
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 bool result = setString(OS_Generator_FuelSupplyFields::LiquidGenericFuelLowerHeatingValue, "");
278
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 OS_ASSERT(result);
279 1 }
280
281 1 bool GeneratorFuelSupply_Impl::setLiquidGenericFuelHigherHeatingValue(double liquidGenericFuelHigherHeatingValue) {
282 1 bool result = setDouble(OS_Generator_FuelSupplyFields::LiquidGenericFuelHigherHeatingValue, liquidGenericFuelHigherHeatingValue);
283
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 OS_ASSERT(result);
284 1 return result;
285 }
286
287 1 void GeneratorFuelSupply_Impl::resetLiquidGenericFuelHigherHeatingValue() {
288
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 bool result = setString(OS_Generator_FuelSupplyFields::LiquidGenericFuelHigherHeatingValue, "");
289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 OS_ASSERT(result);
290 1 }
291
292 1 bool GeneratorFuelSupply_Impl::setLiquidGenericFuelMolecularWeight(double liquidGenericFuelMolecularWeight) {
293 1 bool result = setDouble(OS_Generator_FuelSupplyFields::LiquidGenericFuelMolecularWeight, liquidGenericFuelMolecularWeight);
294
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 OS_ASSERT(result);
295 1 return result;
296 }
297
298 1 void GeneratorFuelSupply_Impl::resetLiquidGenericFuelMolecularWeight() {
299
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 bool result = setString(OS_Generator_FuelSupplyFields::LiquidGenericFuelMolecularWeight, "");
300
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 OS_ASSERT(result);
301 1 }
302
303 1 bool GeneratorFuelSupply_Impl::setLiquidGenericFuelCO2EmissionFactor(double liquidGenericFuelCO2EmissionFactor) {
304 1 bool result = setDouble(OS_Generator_FuelSupplyFields::LiquidGenericFuelCO2EmissionFactor, liquidGenericFuelCO2EmissionFactor);
305
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 OS_ASSERT(result);
306 1 return result;
307 }
308
309 2 void GeneratorFuelSupply_Impl::resetLiquidGenericFuelCO2EmissionFactor() {
310
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
4 bool result = setString(OS_Generator_FuelSupplyFields::LiquidGenericFuelCO2EmissionFactor, "");
311
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 OS_ASSERT(result);
312 2 }
313
314 // TODO: this field shouldn't even exist in the IDD
315 107 unsigned int GeneratorFuelSupply_Impl::numberofConstituentsinGaseousConstituentFuelSupply() const {
316 107 return numExtensibleGroups();
317 }
318
319 // TODO: this field shouldn't even exist in the IDD
320 80 bool GeneratorFuelSupply_Impl::setNumberofConstituentsinGaseousConstituentFuelSupply(
321 unsigned int numberofConstituentsinGaseousConstituentFuelSupply) {
322 bool result =
323 80 setInt(OS_Generator_FuelSupplyFields::NumberofConstituentsinGaseousConstituentFuelSupply, numberofConstituentsinGaseousConstituentFuelSupply);
324 80 return result;
325 }
326
327 // TODO: this field shouldn't even exist in the IDD
328 2 void GeneratorFuelSupply_Impl::resetNumberofConstituentsinGaseousConstituentFuelSupply() {
329 2 bool result = setInt(OS_Generator_FuelSupplyFields::NumberofConstituentsinGaseousConstituentFuelSupply, 0);
330
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 OS_ASSERT(result);
331 2 }
332
333 4 double GeneratorFuelSupply_Impl::sumofConstituentsMolarFractions() const {
334 4 double result = 0;
335
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if (numberofConstituentsinGaseousConstituentFuelSupply() == 0) {
336 ✗ LOG(Warn, briefDescription() << " does not have any constituents");
337 } else {
338
3/3
✓ Branch 1 taken 4 times.
✓ Branch 7 taken 32 times.
✓ Branch 8 taken 4 times.
36 for (const FuelSupplyConstituent& constituent : constituents()) {
339
1/1
✓ Branch 1 taken 32 times.
32 result += constituent.molarFraction();
340 4 }
341 }
342
343 4 return result;
344 }
345
346 79 bool GeneratorFuelSupply_Impl::addConstituent(const FuelSupplyConstituent& constituent) {
347 bool result;
348
349 79 unsigned int num = numberofConstituentsinGaseousConstituentFuelSupply();
350 // Max number of constituents is 12
351
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 78 times.
79 if (num >= 12) {
352
7/7
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 14 taken 1 time.
✓ Branch 17 taken 1 time.
✓ Branch 20 taken 1 time.
1 LOG(Warn, briefDescription() << " already has 12 constituents which is the limit");
353 1 result = false;
354 } else {
355 // Push an extensible group
356
3/3
✓ Branch 1 taken 78 times.
✓ Branch 4 taken 78 times.
✓ Branch 7 taken 78 times.
78 auto eg = getObject<ModelObject>().pushExtensibleGroup().cast<WorkspaceExtensibleGroup>();
357
2/2
✓ Branch 1 taken 78 times.
✓ Branch 4 taken 78 times.
78 bool temp = eg.setString(OS_Generator_FuelSupplyExtensibleFields::ConstituentName, constituent.constituentName());
358
2/2
✓ Branch 1 taken 78 times.
✓ Branch 4 taken 78 times.
78 bool ok = eg.setDouble(OS_Generator_FuelSupplyExtensibleFields::ConstituentMolarFraction, constituent.molarFraction());
359
2/4
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 78 times.
✗ Branch 3 not taken.
78 if (temp && ok) {
360
1/1
✓ Branch 1 taken 78 times.
78 setNumberofConstituentsinGaseousConstituentFuelSupply(num + 1);
361 78 result = true;
362 } else {
363 // Something went wrong, probably the constituent name isn't in the list of possible choices
364 // So erase the new extensible group
365 ✗ getObject<ModelObject>().eraseExtensibleGroup(eg.groupIndex());
366 ✗ result = false;
367 }
368 78 }
369 79 return result;
370 }
371
372 80 bool GeneratorFuelSupply_Impl::addConstituent(const std::string& name, double molarFraction) {
373 // Make a constituent (which will check for validity), and then call the above function
374
1/1
✓ Branch 1 taken 79 times.
80 FuelSupplyConstituent constituent(name, molarFraction);
375
1/1
✓ Branch 1 taken 79 times.
158 return addConstituent(constituent);
376 79 }
377
378 3 bool GeneratorFuelSupply_Impl::removeConstituent(unsigned groupIndex) {
379 bool result;
380
381 3 unsigned int num = numberofConstituentsinGaseousConstituentFuelSupply();
382
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
3 if (groupIndex < num) {
383
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 getObject<ModelObject>().eraseExtensibleGroup(groupIndex);
384 2 setNumberofConstituentsinGaseousConstituentFuelSupply(num - 1);
385 2 result = true;
386 } else {
387 1 result = false;
388 }
389 3 return result;
390 }
391
392 2 void GeneratorFuelSupply_Impl::removeAllConstituents() {
393
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 getObject<ModelObject>().clearExtensibleGroups();
394 2 resetNumberofConstituentsinGaseousConstituentFuelSupply();
395 2 }
396
397 7 std::vector<FuelSupplyConstituent> GeneratorFuelSupply_Impl::constituents() const {
398 7 std::vector<FuelSupplyConstituent> result;
399
400
1/1
✓ Branch 1 taken 7 times.
7 std::vector<IdfExtensibleGroup> groups = extensibleGroups();
401
402
2/2
✓ Branch 5 taken 56 times.
✓ Branch 6 taken 7 times.
63 for (const auto& group : groups) {
403 boost::optional<std::string> name =
404
2/2
✓ Branch 1 taken 56 times.
✓ Branch 4 taken 56 times.
56 group.cast<WorkspaceExtensibleGroup>().getString(OS_Generator_FuelSupplyExtensibleFields::ConstituentName);
405 boost::optional<double> molarFraction =
406
2/2
✓ Branch 1 taken 56 times.
✓ Branch 4 taken 56 times.
56 group.cast<WorkspaceExtensibleGroup>().getDouble(OS_Generator_FuelSupplyExtensibleFields::ConstituentMolarFraction);
407
408
3/6
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 56 times.
✗ Branch 5 not taken.
112 if (name && molarFraction) {
409
3/3
✓ Branch 1 taken 56 times.
✓ Branch 4 taken 56 times.
✓ Branch 7 taken 56 times.
56 FuelSupplyConstituent constituent(name.get(), molarFraction.get());
410
1/1
✓ Branch 1 taken 56 times.
56 result.push_back(constituent);
411 56 }
412 56 }
413
414 14 return result;
415 7 }
416
417 } // namespace detail
418
419 ✗ GeneratorFuelSupply::GeneratorFuelSupply(const Model& model, Schedule& tempSchedule, const CurveCubic& powerCurve)
420 ✗ : ModelObject(GeneratorFuelSupply::iddObjectType(), model) {
421 ✗ OS_ASSERT(getImpl<detail::GeneratorFuelSupply_Impl>());
422
423 ✗ setFuelTemperatureModelingMode("Scheduled");
424 ✗ bool ok = setFuelTemperatureSchedule(tempSchedule);
425 ✗ if (!ok) {
426 ✗ remove();
427 ✗ LOG_AND_THROW("Unable to set " << briefDescription() << "'s temp schedule to " << tempSchedule.briefDescription() << ".");
428 }
429
430 ✗ ok = setCompressorPowerMultiplierFunctionofFuelRateCurve(powerCurve);
431 ✗ if (!ok) {
432 ✗ remove();
433 ✗ LOG_AND_THROW("Unable to set " << briefDescription() << "'s power curve to " << powerCurve.briefDescription() << ".");
434 }
435 ✗ setCompressorHeatLossFactor(1);
436
437 // From E+ 9.0.0, Microcogeneration.idf
438 // LiquidGeneric is broken, see https://github.com/NREL/EnergyPlus/issues/6998
439 ✗ setName("NATURALGAS");
440 ✗ setFuelType("GaseousConstituents");
441 ✗ addConstituent("METHANE", 0.9490);
442 ✗ addConstituent("CarbonDioxide", 0.0070);
443 ✗ addConstituent("NITROGEN", 0.0160);
444 ✗ addConstituent("ETHANE", 0.0250);
445 ✗ addConstituent("PROPANE", 0.0020);
446 ✗ addConstituent("BUTANE", 0.0006);
447 ✗ addConstituent("PENTANE", 0.0002);
448 ✗ addConstituent("OXYGEN", 0.0002);
449 ✗ }
450
451 8 GeneratorFuelSupply::GeneratorFuelSupply(const Model& model) : ModelObject(GeneratorFuelSupply::iddObjectType(), model) {
452
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
✗ Branch 5 not taken.
8 OS_ASSERT(getImpl<detail::GeneratorFuelSupply_Impl>());
453
454
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 setFuelTemperatureModelingMode("Scheduled");
455
1/1
✓ Branch 1 taken 8 times.
8 ScheduleConstant schedule(model);
456
1/1
✓ Branch 1 taken 8 times.
8 schedule.setValue(20);
457
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 schedule.setName("Fuel Temperature");
458
1/1
✓ Branch 1 taken 8 times.
8 setFuelTemperatureSchedule(schedule);
459
460
1/1
✓ Branch 1 taken 8 times.
8 CurveCubic curveCubic(model);
461
1/1
✓ Branch 1 taken 8 times.
8 curveCubic.setCoefficient1Constant(0);
462
1/1
✓ Branch 1 taken 8 times.
8 curveCubic.setCoefficient2x(0);
463
1/1
✓ Branch 1 taken 8 times.
8 curveCubic.setCoefficient3xPOW2(0);
464
1/1
✓ Branch 1 taken 8 times.
8 curveCubic.setCoefficient4xPOW3(0);
465
1/1
✓ Branch 1 taken 8 times.
8 curveCubic.setMinimumValueofx(-1.0e10);
466
1/1
✓ Branch 1 taken 8 times.
8 curveCubic.setMaximumValueofx(1.0e10);
467
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 curveCubic.setName("Compressor Power Multiplier Function of FuelRate Curve");
468
1/1
✓ Branch 1 taken 8 times.
8 setCompressorPowerMultiplierFunctionofFuelRateCurve(curveCubic);
469
1/1
✓ Branch 1 taken 8 times.
8 setCompressorHeatLossFactor(1);
470
471 // From E+ 9.0.0, Microcogeneration.idf
472 // LiquidGeneric is broken, see https://github.com/NREL/EnergyPlus/issues/6998
473
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
24 setName("NATURALGAS");
474
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
16 setFuelType("GaseousConstituents");
475
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
16 addConstituent("METHANE", 0.9490);
476
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
16 addConstituent("CarbonDioxide", 0.0070);
477
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
16 addConstituent("NITROGEN", 0.0160);
478
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
16 addConstituent("ETHANE", 0.0250);
479
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
16 addConstituent("PROPANE", 0.0020);
480
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
16 addConstituent("BUTANE", 0.0006);
481
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
16 addConstituent("PENTANE", 0.0002);
482
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 addConstituent("OXYGEN", 0.0002);
483 8 }
484
485 7880 IddObjectType GeneratorFuelSupply::iddObjectType() {
486
1/1
✓ Branch 1 taken 7880 times.
7880 return {IddObjectType::OS_Generator_FuelSupply};
487 }
488
489 4 double GeneratorFuelSupply::sumofConstituentsMolarFractions() const {
490
1/1
✓ Branch 3 taken 4 times.
4 return getImpl<detail::GeneratorFuelSupply_Impl>()->sumofConstituentsMolarFractions();
491 }
492
493 ✗ bool GeneratorFuelSupply::addConstituent(const FuelSupplyConstituent& constituent) {
494 ✗ return getImpl<detail::GeneratorFuelSupply_Impl>()->addConstituent(constituent);
495 }
496
497 80 bool GeneratorFuelSupply::addConstituent(const std::string& name, double molarFraction) {
498
1/1
✓ Branch 3 taken 79 times.
80 return getImpl<detail::GeneratorFuelSupply_Impl>()->addConstituent(name, molarFraction);
499 }
500
501 // TODO: change to bool
502 3 void GeneratorFuelSupply::removeConstituent(int groupIndex) {
503
1/1
✓ Branch 3 taken 3 times.
3 getImpl<detail::GeneratorFuelSupply_Impl>()->removeConstituent(groupIndex);
504 3 }
505
506 2 void GeneratorFuelSupply::removeAllConstituents() {
507
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::GeneratorFuelSupply_Impl>()->removeAllConstituents();
508 }
509
510 3 std::vector<FuelSupplyConstituent> GeneratorFuelSupply::constituents() const {
511
1/1
✓ Branch 3 taken 3 times.
3 return getImpl<detail::GeneratorFuelSupply_Impl>()->constituents();
512 }
513
514 ✗ std::vector<std::string> GeneratorFuelSupply::fuelTemperatureModelingModeValues() {
515 ✗ return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_Generator_FuelSupplyFields::FuelTemperatureModelingMode);
516 }
517
518 ✗ std::vector<std::string> GeneratorFuelSupply::fuelTypeValues() {
519 ✗ return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_Generator_FuelSupplyFields::FuelType);
520 }
521
522 4 std::string GeneratorFuelSupply::fuelTemperatureModelingMode() const {
523
1/1
✓ Branch 3 taken 4 times.
4 return getImpl<detail::GeneratorFuelSupply_Impl>()->fuelTemperatureModelingMode();
524 }
525
526 3 boost::optional<Node> GeneratorFuelSupply::fuelTemperatureReferenceNode() const {
527
1/1
✓ Branch 3 taken 3 times.
3 return getImpl<detail::GeneratorFuelSupply_Impl>()->fuelTemperatureReferenceNode();
528 }
529
530 4 boost::optional<Schedule> GeneratorFuelSupply::fuelTemperatureSchedule() const {
531
1/1
✓ Branch 3 taken 4 times.
4 return getImpl<detail::GeneratorFuelSupply_Impl>()->fuelTemperatureSchedule();
532 }
533
534 10 CurveCubic GeneratorFuelSupply::compressorPowerMultiplierFunctionofFuelRateCurve() const {
535
1/1
✓ Branch 3 taken 10 times.
10 return getImpl<detail::GeneratorFuelSupply_Impl>()->compressorPowerMultiplierFunctionofFuelRateCurve();
536 }
537
538 4 double GeneratorFuelSupply::compressorHeatLossFactor() const {
539
1/1
✓ Branch 3 taken 4 times.
4 return getImpl<detail::GeneratorFuelSupply_Impl>()->compressorHeatLossFactor();
540 }
541
542 6 std::string GeneratorFuelSupply::fuelType() const {
543
1/1
✓ Branch 3 taken 6 times.
6 return getImpl<detail::GeneratorFuelSupply_Impl>()->fuelType();
544 }
545
546 7 boost::optional<double> GeneratorFuelSupply::liquidGenericFuelLowerHeatingValue() const {
547
1/1
✓ Branch 3 taken 7 times.
7 return getImpl<detail::GeneratorFuelSupply_Impl>()->liquidGenericFuelLowerHeatingValue();
548 }
549
550 7 boost::optional<double> GeneratorFuelSupply::liquidGenericFuelHigherHeatingValue() const {
551
1/1
✓ Branch 3 taken 7 times.
7 return getImpl<detail::GeneratorFuelSupply_Impl>()->liquidGenericFuelHigherHeatingValue();
552 }
553
554 7 boost::optional<double> GeneratorFuelSupply::liquidGenericFuelMolecularWeight() const {
555
1/1
✓ Branch 3 taken 7 times.
7 return getImpl<detail::GeneratorFuelSupply_Impl>()->liquidGenericFuelMolecularWeight();
556 }
557
558 7 boost::optional<double> GeneratorFuelSupply::liquidGenericFuelCO2EmissionFactor() const {
559
1/1
✓ Branch 3 taken 7 times.
7 return getImpl<detail::GeneratorFuelSupply_Impl>()->liquidGenericFuelCO2EmissionFactor();
560 }
561
562 21 boost::optional<unsigned int> GeneratorFuelSupply::numberofConstituentsinGaseousConstituentFuelSupply() const {
563
2/2
✓ Branch 3 taken 21 times.
✓ Branch 6 taken 21 times.
21 return getImpl<detail::GeneratorFuelSupply_Impl>()->numberofConstituentsinGaseousConstituentFuelSupply();
564 }
565
566 8 bool GeneratorFuelSupply::setFuelTemperatureModelingMode(const std::string& fuelTemperatureModelingMode) {
567
1/1
✓ Branch 3 taken 8 times.
8 return getImpl<detail::GeneratorFuelSupply_Impl>()->setFuelTemperatureModelingMode(fuelTemperatureModelingMode);
568 }
569
570 ✗ void GeneratorFuelSupply::resetFuelTemperatureModelingMode() {
571 ✗ getImpl<detail::GeneratorFuelSupply_Impl>()->resetFuelTemperatureModelingMode();
572 ✗ }
573
574 ✗ bool GeneratorFuelSupply::setFuelTemperatureReferenceNode(const Node& connection) {
575 ✗ return getImpl<detail::GeneratorFuelSupply_Impl>()->setFuelTemperatureReferenceNode(connection);
576 }
577
578 ✗ void GeneratorFuelSupply::resetFuelTemperatureReferenceNode() {
579 ✗ getImpl<detail::GeneratorFuelSupply_Impl>()->resetFuelTemperatureReferenceNode();
580 ✗ }
581
582 8 bool GeneratorFuelSupply::setFuelTemperatureSchedule(Schedule& schedule) {
583
1/1
✓ Branch 3 taken 8 times.
8 return getImpl<detail::GeneratorFuelSupply_Impl>()->setFuelTemperatureSchedule(schedule);
584 }
585
586 ✗ void GeneratorFuelSupply::resetFuelTemperatureSchedule() {
587 ✗ getImpl<detail::GeneratorFuelSupply_Impl>()->resetFuelTemperatureSchedule();
588 ✗ }
589
590 9 bool GeneratorFuelSupply::setCompressorPowerMultiplierFunctionofFuelRateCurve(const CurveCubic& cubicCurves) {
591
1/1
✓ Branch 3 taken 9 times.
9 return getImpl<detail::GeneratorFuelSupply_Impl>()->setCompressorPowerMultiplierFunctionofFuelRateCurve(cubicCurves);
592 }
593
594 8 bool GeneratorFuelSupply::setCompressorHeatLossFactor(double compressorHeatLossFactor) {
595
1/1
✓ Branch 3 taken 8 times.
8 return getImpl<detail::GeneratorFuelSupply_Impl>()->setCompressorHeatLossFactor(compressorHeatLossFactor);
596 }
597
598 ✗ void GeneratorFuelSupply::resetCompressorHeatLossFactor() {
599 ✗ getImpl<detail::GeneratorFuelSupply_Impl>()->resetCompressorHeatLossFactor();
600 ✗ }
601
602 9 bool GeneratorFuelSupply::setFuelType(const std::string& fuelType) {
603
1/1
✓ Branch 3 taken 9 times.
9 return getImpl<detail::GeneratorFuelSupply_Impl>()->setFuelType(fuelType);
604 }
605
606 1 void GeneratorFuelSupply::resetFuelType() {
607
1/1
✓ Branch 3 taken 1 time.
1 getImpl<detail::GeneratorFuelSupply_Impl>()->resetFuelType();
608 1 }
609
610 1 bool GeneratorFuelSupply::setLiquidGenericFuelLowerHeatingValue(double liquidGenericFuelLowerHeatingValue) {
611
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::GeneratorFuelSupply_Impl>()->setLiquidGenericFuelLowerHeatingValue(liquidGenericFuelLowerHeatingValue);
612 }
613
614 1 void GeneratorFuelSupply::resetLiquidGenericFuelLowerHeatingValue() {
615
1/1
✓ Branch 3 taken 1 time.
1 getImpl<detail::GeneratorFuelSupply_Impl>()->resetLiquidGenericFuelLowerHeatingValue();
616 1 }
617
618 1 bool GeneratorFuelSupply::setLiquidGenericFuelHigherHeatingValue(double liquidGenericFuelHigherHeatingValue) {
619
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::GeneratorFuelSupply_Impl>()->setLiquidGenericFuelHigherHeatingValue(liquidGenericFuelHigherHeatingValue);
620 }
621
622 1 void GeneratorFuelSupply::resetLiquidGenericFuelHigherHeatingValue() {
623
1/1
✓ Branch 3 taken 1 time.
1 getImpl<detail::GeneratorFuelSupply_Impl>()->resetLiquidGenericFuelHigherHeatingValue();
624 1 }
625
626 1 bool GeneratorFuelSupply::setLiquidGenericFuelMolecularWeight(double liquidGenericFuelMolecularWeight) {
627
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::GeneratorFuelSupply_Impl>()->setLiquidGenericFuelMolecularWeight(liquidGenericFuelMolecularWeight);
628 }
629
630 1 void GeneratorFuelSupply::resetLiquidGenericFuelMolecularWeight() {
631
1/1
✓ Branch 3 taken 1 time.
1 getImpl<detail::GeneratorFuelSupply_Impl>()->resetLiquidGenericFuelMolecularWeight();
632 1 }
633
634 1 bool GeneratorFuelSupply::setLiquidGenericFuelCO2EmissionFactor(double liquidGenericFuelCO2EmissionFactor) {
635
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::GeneratorFuelSupply_Impl>()->setLiquidGenericFuelCO2EmissionFactor(liquidGenericFuelCO2EmissionFactor);
636 }
637
638 2 void GeneratorFuelSupply::resetLiquidGenericFuelCO2EmissionFactor() {
639
1/1
✓ Branch 3 taken 2 times.
2 getImpl<detail::GeneratorFuelSupply_Impl>()->resetLiquidGenericFuelCO2EmissionFactor();
640 2 }
641
642 ✗ boost::optional<GeneratorFuelCell> GeneratorFuelSupply::fuelCell() const {
643 ✗ return getImpl<detail::GeneratorFuelSupply_Impl>()->fuelCell();
644 }
645
646 /// @cond
647
1/1
✓ Branch 3 taken 21 times.
21 GeneratorFuelSupply::GeneratorFuelSupply(std::shared_ptr<detail::GeneratorFuelSupply_Impl> impl) : ModelObject(std::move(impl)) {}
648 /// @endcond
649
650 } // namespace model
651 } // namespace openstudio
652