Initial Commit
[HECS.git] / Gains.cpp
blob0a51301a79d5abb101c5ce0345152ffbcbe1e1f3
1 /***************************************************************************
2 * *
3 * Gains.cpp Copyright (C) 2008 by Jon Rumble *
4 * j.w.rumble@reading.ac.uk *
5 * *
6 * This file is part of HECS, *
7 * *
8 * HECS is free software: you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation, either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * HECS is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * You should have received a copy of the GNU General Public License *
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
21 ***************************************************************************/
23 #include "Gains.h"
24 #include <iostream>
25 // Constructors/Destructors
28 Gains::Gains (const ConfigParser& config, WaterHeating *waterheat,
29 HeatLosses *heatingLosses,DwellingDimensions *dims)
31 cf = config;
32 ptrWaterHeat = waterheat;
33 ptrHeatLosses = heatingLosses;
34 ptrDims = dims;
35 initVars();
38 Gains::~Gains ( )
40 //TODO
44 // Methods
48 // Accessor methods
51 void Gains::setLightAppCookMetabolicGains ( double val_in ) {
52 m_lightAppCookMetabolicGains = val_in;
55 double Gains::getLightAppCookMetabolicGains ( ) {
56 return m_lightAppCookMetabolicGains;
59 void Gains::setLowEnergyLightRed ( double val_in ) {
60 m_lowEnergyLightRed = val_in;
63 double Gains::getLowEnergyLightRed ( ) {
64 return m_lowEnergyLightRed;
67 void Gains::setAddtnGains ( double val_in ) {
68 m_addtnGains = val_in;
71 double Gains::getAddtnGains ( ) {
72 return m_addtnGains;
75 void Gains::setWaterHeating ( double val_in ) {
76 m_waterHeating = val_in;
79 double Gains::getWaterHeating ( ) {
80 return m_waterHeating;
83 void Gains::setTotalIntGains ( double val_in ) {
84 m_totalIntGains = val_in;
87 double Gains::getTotalIntGains ( ) {
88 return m_totalIntGains;
91 void Gains::setTotalGains ( double val_in ) {
92 m_totalGains = val_in;
95 double Gains::getTotalGains ( ) {
96 return m_totalGains;
99 void Gains::setSolarGLR ( double val_in ) {
100 m_solarGLR = val_in;
103 double Gains::getSolarGLR ( ) {
104 return m_solarGLR;
107 void Gains::setSolarUtilFactor ( double val_in ) {
108 m_solarUtilFactor = val_in;
111 double Gains::getSolarUtilFactor ( ) {
112 return m_solarUtilFactor;
115 void Gains::setTotalSolarGains ( double val_in ) {
116 m_totalSolarGains = val_in;
119 double Gains::getTotalSolarGains ( ) {
120 return m_totalSolarGains;
123 void Gains::setMeanTempLivingArea ( double val_in ) {
124 m_meanTempLivingArea = val_in;
127 double Gains::getMeanTempLivingArea ( ) {
128 return m_meanTempLivingArea;
131 void Gains::setTempAdjustment ( double val_in ) {
132 m_tempAdjustment = val_in;
135 double Gains::getTempAdjustment ( ) {
136 return m_tempAdjustment;
139 void Gains::setAdjustForGains ( double val_in ) {
140 m_adjustForGains = val_in;
143 double Gains::getAdjustForGains ( ) {
144 return m_adjustForGains;
147 void Gains::setAdjustLivingTemp ( double val_in ) {
148 m_adjustLivingTemp = val_in;
151 double Gains::getAdjustLivingTemp ( ) {
152 return m_adjustLivingTemp;
155 void Gains::setTempDiffZones ( double val_in ) {
156 m_tempDiffZones = val_in;
159 double Gains::getTempDiffZones ( ) {
160 return m_tempDiffZones;
163 void Gains::setLivingAreaFrac ( double val_in ) {
164 m_livingAreaFrac = val_in;
167 double Gains::getLivingAreaFrac ( ) {
168 return m_livingAreaFrac;
171 void Gains::setRestOfHouseFrac ( double val_in ) {
172 m_restOfHouseFrac = val_in;
175 double Gains::getRestOfHouseFrac ( ) {
176 return m_restOfHouseFrac;
179 void Gains::setMeanIntTemp ( double val_in ) {
180 m_meanIntTemp = val_in;
183 double Gains::getMeanIntTemp ( ) {
184 return m_meanIntTemp;
187 void Gains::setTempRiseFromGains ( double val_in ) {
188 m_tempRiseFromGains = val_in;
191 double Gains::getTempRiseFromGains ( ) {
192 return m_tempRiseFromGains;
195 void Gains::setBaseTemp ( double val_in ) {
196 m_baseTemp = val_in;
199 double Gains::getBaseTemp ( ) {
200 return m_baseTemp;
203 void Gains::setDegreeDays ( double val_in ) {
204 m_degreeDays = val_in;
207 double Gains::getDegreeDays ( ) {
208 return m_degreeDays;
211 void Gains::setSpaceHeatingReq ( double val_in ) {
212 m_spaceHeatingReq = val_in;
215 double Gains::getSpaceHeatingReq ( ) {
216 return m_spaceHeatingReq;
219 double Gains::getGainLossRatio ( ) {
220 return m_gainLossRatio;
223 void Gains::setGainLossRatio (double val_in ) {
224 m_gainLossRatio = val_in;
227 double Gains::getUtilisationFactor ( ) {
228 return m_utilisationFactor;
231 void Gains::setUtilisationFactor (double val_in ) {
232 m_utilisationFactor = val_in;
235 double Gains::getUsefulGains ( ) {
236 return m_usefulGains;
239 void Gains::setUsefulGains (double val_in ) {
240 m_usefulGains = val_in;
243 double Gains::getAnnualLightEnergy(){
244 return m_annualLightEnergy;
247 void Gains::setAnnualLightEnergy(double val_in){
248 m_annualLightEnergy = val_in;
251 // Other methods
254 void Gains::calcLightingEnergy()
256 //Fixed Low Energy Lightbulbs
259 //Ratio of Enegry saving to standard lights
260 double C_1 = 0.00, C_2 = 0.00, GL = 0.00;
261 C_1 = 1 - 0.50 * m_lightRatio;
265 //Daylighting Calc
266 GL = m_totalSolarGains / ptrDims->get_totalFloorArea();
268 if (GL <= 0.095)
269 C_2 = (52.2 * (GL * GL)) - 9.94 * GL + 1.433;
270 else //GL > 0.095
271 C_2 = 0.96;
273 m_annualLightEnergy = 9.3 *
274 ptrDims->get_totalFloorArea() *
275 C_1 *
276 C_2;
279 //Gains From Lighting
280 m_lowEnergyLightRed = m_annualLightEnergy * 0.15;
283 void Gains::calcMeanIntTempLiving ()
285 double HLP = ptrHeatLosses->getHeatLossParam();
286 double x1 = 0.00;
287 double x3 = 0.00;
288 double y1 = 0.00;
289 double y3 = 0.00;
290 QList <double> tmpList;
292 QMap<double,QList <double> >::const_iterator i;
294 if (HLP <= 1.00)
296 m_meanTempLivingArea= table8.value(1.00).at(m_heatingTypeControl);
298 else if (HLP >= 6.00)
301 m_meanTempLivingArea = table8.value(6.00).at(m_heatingTypeControl);
304 //Find Upper Bound
305 else
307 i = table8.upperBound(HLP);
308 x3 = i.key();
309 tmpList = i.value();
310 y3 = tmpList.at(m_heatingTypeControl);
311 //Decrement by 1 for lower bound
312 --i;
313 x1 = i.key();
314 tmpList = i.value();
315 y1 = tmpList.at(m_heatingTypeControl);
317 m_meanTempLivingArea = lerp(x1,HLP,x3,y1,y3);
323 void Gains::calctempDiffBetweenZones()
325 double HLP = ptrHeatLosses->getHeatLossParam();
326 double x1 = 0.00;
327 double x3 = 0.00;
328 double y1 = 0.00;
329 double y3 = 0.00;
330 QList <double> tmpList;
332 QMap<double,QList <double> >::const_iterator i;
334 if (HLP <= 1.00)
336 m_tempDiffZones = table9.value(1.00).at(m_controlType);
338 else if (HLP >= 6.00)
341 m_tempDiffZones = table9.value(6.00).at(m_controlType);
344 //Find Upper Bound
345 else
347 i = table9.upperBound(HLP);
348 x3 = i.key();
349 tmpList = i.value();
350 y3 = tmpList.at(m_controlType);
351 //Decrement by 1 for lower bound
352 --i;
353 x1 = i.key();
354 tmpList = i.value();
355 y1 = tmpList.at(m_controlType);
357 m_tempDiffZones = lerp(x1,HLP,x3,y1,y3);
361 void Gains::calcDegreeDays()
363 double x1 = 0.00;
364 double x3 = 0.00;
365 double y1 = 0.00;
366 double y3 = 0.00;
367 QList <double> tmpList;
368 m_tempRiseFromGains = m_usefulGains /
369 ptrHeatLosses->getHeatLossCoeff();
371 m_baseTemp = m_meanIntTemp - m_tempRiseFromGains;
373 if (m_baseTemp < 1.00)
374 m_degreeDays = 0.00;
375 else if(m_baseTemp > 20.50)
376 m_degreeDays = 3330.00;
378 else
381 QMap<double,QList <double> >::const_iterator i;
384 i = table10.upperBound(m_baseTemp);
385 x3 = i.key();
386 tmpList = i.value();
387 y3 = tmpList.at(0);
388 //Decrement by 1 for lower bound
389 --i;
390 x1 = i.key();
391 tmpList = i.value();
392 y1 = tmpList.at(0);
394 m_degreeDays = lerp(x1,m_baseTemp,x3,y1,y3);
398 void Gains::calcTotalInternalGains()
401 double N = 0.00, W = 0.00, SFP=0.00;
402 double TFA = ptrDims->get_totalFloorArea();
404 //Calculate N
406 if (TFA <= 420.00)
407 N = 0.035 * TFA - 0.000038 * (TFA * TFA);
408 else
409 N = 8.00;
411 //Calculate Gains W
413 if (TFA <= 282.00)
414 W = 74.00 + 2.66 * TFA + 75.5 * N;
415 else
416 W = 824.00 + 75.5 * N;
418 m_lightAppCookMetabolicGains = W;
420 if(m_specificFanPower == 1)
421 SFP = 2.0;
422 else
423 SFP = 0.8;
426 switch (m_addtnGainsTableVal)
428 case 1: //Central Heating Pump
429 m_addtnGains = 10.00;
430 break;
431 case 2: //Oil Boiler Pump, inside dwelling
432 m_addtnGains = 10.00;
433 break;
435 case 3://Warm air heating system fans
436 m_addtnGains = 0.06 * ptrDims->get_dwellingVolume();
437 break;
438 case 4:
439 m_addtnGains = SFP * 0.06 * ptrDims->get_dwellingVolume();
440 break;
441 default:
442 break;
443 } /* ----- end switch ----- */
446 m_waterHeating = ptrWaterHeat->getHotWaterHeatGains() / 8.76 ;
447 m_totalIntGains = m_lightAppCookMetabolicGains +
448 m_addtnGains +
449 m_waterHeating -
450 m_lowEnergyLightRed;
453 void Gains::calcUsefulSolarGains()
455 QMapIterator <QString, SolarGains> i(gainsList);
457 while (i.hasNext())
459 i.next();
460 SolarGains temp = i.value();
461 m_totalSolarGains += temp.getSolarGains();
465 m_totalGains = m_totalIntGains + m_totalSolarGains;
467 m_gainLossRatio = m_totalGains / ptrHeatLosses->getHeatLossCoeff();
469 //Calculate Utilisation Factor
470 m_utilisationFactor = 1 - exp(-18/m_gainLossRatio);
472 m_usefulGains = m_totalSolarGains * m_utilisationFactor;
476 void Gains::calcSpaceHeatReq()
478 m_spaceHeatingReq = 0.024 *
479 m_degreeDays *
480 ptrHeatLosses->getHeatLossCoeff();
483 void Gains::calcMeanInternalTemp()
485 //Needs work to Fix !!!!
487 double R = 1.00;
489 //Calc Mean Internal Living Room Temperature
490 calcMeanIntTempLiving();
492 //TODO - adjust from table 4e
494 //TODO - responsiveness, defaulting to 1.00 for now !!
496 m_adjustForGains = (m_usefulGains /
497 ptrHeatLosses->getHeatLossCoeff() - 4.0) *
498 0.2 *
501 m_adjustLivingTemp = m_meanTempLivingArea +
502 m_tempAdjustment +
503 m_adjustForGains;
505 calctempDiffBetweenZones();
507 m_livingAreaFrac = ptrDims->get_livingRoomArea() /
508 ptrDims->get_totalFloorArea();
510 m_restOfHouseFrac = 1.00 - m_livingAreaFrac;
511 m_meanIntTemp = m_adjustLivingTemp -
512 (m_tempDiffZones * m_restOfHouseFrac);
516 void Gains::initVars()
519 buildLT();
521 m_lightAppCookMetabolicGains = cf.getValueDouble("Gains:lightAppCookMetabolicGains");
522 m_lowEnergyLightRed = cf.getValueDouble("Gains:lowEnergyLightRed");
523 m_addtnGains = cf.getValueDouble("Gains:addtnGains");
524 m_waterHeating = cf.getValueDouble("Gains:waterHeating");
525 m_totalIntGains = cf.getValueDouble("Gains:totalIntGains");
526 m_totalGains = cf.getValueDouble("Gains:totalGains");
527 m_solarGLR = cf.getValueDouble("Gains:solarGLR");
528 m_solarUtilFactor = cf.getValueDouble("Gains:solarUtilFactor");
529 m_totalSolarGains = cf.getValueDouble("Gains:totalSolarGains");
530 m_meanTempLivingArea = cf.getValueDouble("Gains:meanTempLivingArea");
531 m_tempAdjustment = cf.getValueDouble("Gains:tempAdjustment");
532 m_adjustForGains = cf.getValueDouble("Gains:adjustForGains");
533 m_adjustLivingTemp = cf.getValueDouble("Gains:adjustLivingTemp");
534 m_tempDiffZones = cf.getValueDouble("Gains:tempDiffZones");
535 m_livingAreaFrac = cf.getValueDouble("Gains:livingAreaFrac");
536 m_restOfHouseFrac = cf.getValueDouble("Gains:restOfHouseFrac");
537 m_meanIntTemp = cf.getValueDouble("Gains:meantIntTemp");
538 m_tempRiseFromGains = cf.getValueDouble("Gains:tempRiseFromGains");
539 m_baseTemp = cf.getValueDouble("Gains:baseTemp");
540 m_degreeDays = cf.getValueDouble("Gains:degreeDays");
541 m_spaceHeatingReq = cf.getValueDouble("Gains:spaceHeatingReq");
542 m_usefulGains = cf.getValueDouble("Gains:usefulGains");
543 m_gainLossRatio = cf.getValueDouble("Gains:gainLossRatio");
544 m_utilisationFactor = cf.getValueDouble("Gains:utilisationFactor");
545 m_lightRatio = cf.getValueDouble("Gains:lightRatio");
546 m_addtnGainsTableVal = cf.getValueInt("Gains:addtnGainsTableVal");
547 m_specificFanPower = cf.getValueInt("Gains:specificFanPower");
548 m_heatingTypeControl = cf.getValueInt("Gains:heatingTypeControl");
549 m_controlType = cf.getValueInt("Gains:controlType");
550 m_annualLightEnergy= cf.getValueInt("Gains:annualLightEnergy");
552 loadSolarGain("North");
553 loadSolarGain("South");
554 loadSolarGain("East");
555 loadSolarGain("West");
556 loadSolarGain("NorthEast");
557 loadSolarGain("SouthEast");
558 loadSolarGain("NorthWest");
559 loadSolarGain("SouthWest");
560 loadSolarGain("Rooflights");
564 void Gains::loadSolarGain(const QString& gainName)
566 int overshadow = 0,orientation =0;
567 int frameType, glazingType = 0;
568 double area = 0.00;
570 QString searchStr = "SG" + gainName + ":";
571 overshadow = cf.getValueInt(searchStr+"overshadow");
572 orientation = cf.getValueInt(searchStr+"orientation");
573 area = cf.getValueDouble(searchStr+"area");
574 frameType = cf.getValueInt(searchStr+"frameType");
575 glazingType = cf.getValueInt(searchStr+"glazingType");
577 createSolarGain(gainName,
578 overshadow,
579 orientation,
580 area,
581 frameType,
582 glazingType,'w');
586 void Gains::buildLT()
588 //TEST BEFORE REMOVAL
589 DoubleReader t1 ("table9");
590 table9 = t1.getDoubleMap();
591 DoubleReader t2 ("table8");
592 table8 = t2.getDoubleMap();
593 DoubleReader t3 ("table10");
594 table10 = t3.getDoubleMap();
596 /* //dr.readFile("table8");
597 DoubleReader table8r ("table8");
598 table8 = table8r.getDoubleMap();
600 DoubleReader table9r ("table9");
601 table9 = table9r.getDoubleMap();
604 //dr.readFile("table10");
605 DoubleReader table10r ("table10");
606 table10 = table10r.getDoubleMap();*/
609 void Gains::createSolarGain(QString gainName,
610 int overshadow,
611 int orientation,
612 double area,
613 int frameType,
614 int glazingType,
615 char season)
617 SolarGains gain(overshadow,orientation,area,
618 frameType,glazingType,season);
619 gainsList[gainName] = gain;
622 void Gains::calcAll()
624 calcTotalInternalGains();
625 calcUsefulSolarGains();
626 calcLightingEnergy();
627 calcMeanInternalTemp();
628 calcDegreeDays();
629 calcSpaceHeatReq();