Initial Commit
[HECS.git] / HeatLosses.cpp
blob66b89509b1af8df07d3a5ff5920485706a93f0e9
1 /***************************************************************************
2 * *
3 * HeatLosses.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 "HeatLosses.h"
24 // Constructors/Destructors
27 HeatLosses::HeatLosses(const ConfigParser& config,
28 DwellingDimensions *dims,
29 Ventilation *ventilation)
31 ptrDims = dims;
32 ptrVentilation = ventilation;
33 cf = config;
34 initVars();
37 HeatLosses::~HeatLosses ( )
39 //TODO
43 // Methods
46 // Calculate U-Value For Windows
48 double HeatLosses::calcUValueWindow (double uW )
50 double uWeffec = 1 / ((1/uW)+ 0.04);
51 return uWeffec;
54 void HeatLosses::buildLT()
56 int regionSel = ptrDims->get_region();
58 TableReader tr ("uValsEnglandWales");
60 switch (regionSel)
63 //England & Wales U-Values
64 case 1:
66 uValuesMap = tr.getTableMap();
67 break;
69 //Scotland U-Values
70 case 2:
71 tr.readFile("uValsScotland");
72 uValuesMap = tr.getTableMap();
73 break;
75 //Northern Ireland U-Values
76 case 3:
77 tr.readFile("uValsNorthernIreland");
78 uValuesMap = tr.getTableMap();
79 break;
81 //England & Wales by default....
82 default:
83 tr.readFile("uValsEnglandWales");
84 uValuesMap = tr.getTableMap();
85 break;
86 } /* ----- end switch ----- */
89 // Accessor methods
91 void HeatLosses::setTotalAreaElems ( double val_in ) {
92 m_totalAreaElems = val_in;
96 double HeatLosses::getTotalAreaElems ( ) {
97 return m_totalAreaElems;
101 void HeatLosses::setFabricHeatLoss ( double val_in ) {
102 m_fabricHeatLoss = val_in;
106 double HeatLosses::getFabricHeatLoss ( ) {
107 return m_fabricHeatLoss;
111 void HeatLosses::setThermalBridges ( double val_in ) {
112 m_thermalBridges = val_in;
116 double HeatLosses::getThermalBridges ( ) {
117 return m_thermalBridges;
121 void HeatLosses::setTotalFabricHeatLoss ( double val_in ) {
122 m_totalFabricHeatLoss = val_in;
126 double HeatLosses::getTotalFabricHeatLoss ( ) const {
127 return m_totalFabricHeatLoss;
131 void HeatLosses::setVentilationHeatLoss ( double val_in ) {
132 m_ventilationHeatLoss = val_in;
136 double HeatLosses::getVentilationHeatLoss ( ) {
137 return m_ventilationHeatLoss;
141 void HeatLosses::setHeatLossCoeff ( double val_in ) {
142 m_heatLossCoeff = val_in;
146 double HeatLosses::getHeatLossCoeff ( ) {
147 return m_heatLossCoeff;
151 void HeatLosses::setHeatLossParam ( double val_in ) {
152 m_heatLossParam = val_in;
156 double HeatLosses::getHeatLossParam ( ) {
157 return m_heatLossParam;
160 void HeatLosses::createHeatLossElement(const QString& elemNameIn)
162 if(!elementMap.contains(elemNameIn))
164 HeatLossElement heatLoss;
165 elementMap.insert(elemNameIn,heatLoss);
169 void HeatLosses::addHeatLoss(const QString& elemName,
170 const QString& lossName,
171 double area,
172 double uValue)
175 QMapIterator <QString,HeatLossElement> i (elementMap);
177 while (i.hasNext())
179 i.next();
180 if (i.key() == elemName)
181 break;
184 HeatLossElement temp =i.value();
186 temp.insertLoss(lossName,area,uValue);
187 elementMap.insert(elemName,temp);
190 void HeatLosses::calcTotalAreaElems()
192 QMapIterator <QString,HeatLossElement> i(elementMap);
194 m_totalAreaElems = 0.00, m_fabricHeatLoss = 0.00;
195 while (i.hasNext())
197 i.next();
198 HeatLossElement temp = i.value();
199 temp.calcElementTotal();
200 m_totalAreaElems += temp.getElementAreaTotal();
201 m_fabricHeatLoss += temp.getElementLossTotal();
206 void HeatLosses::calcHeatLossParam ()
210 m_thermalBridges = 0.15 * m_totalAreaElems;
211 m_totalFabricHeatLoss = m_fabricHeatLoss + m_thermalBridges;
212 m_ventilationHeatLoss = ptrVentilation->get_effecAirChangeRate() *
213 0.33 *
214 ptrDims->get_dwellingVolume();
216 m_heatLossCoeff = m_totalFabricHeatLoss + m_ventilationHeatLoss;
218 m_heatLossParam = m_heatLossCoeff /
219 ptrDims->get_totalFloorArea();
223 void HeatLosses::calcAll()
225 //Calculate Element Area + Fabric Heatloss W/K totals
226 calcTotalAreaElems();
227 calcHeatLossParam();
230 void HeatLosses::initVars()
233 fetchHeatLosses();
234 buildLT();
236 m_totalAreaElems = cf.getValueDouble("HeatLosses:totalAreaElems");
237 m_fabricHeatLoss = cf.getValueDouble("HeatLosses:fabricHeatLoss");
238 m_thermalBridges = cf.getValueDouble("HeatLosses:thermalBridges");
239 m_totalFabricHeatLoss = cf.getValueDouble("HeatLosses:totalFabricHeatLoss");
240 m_ventilationHeatLoss = cf.getValueDouble("HeatLosses:ventilationHeatLoss");
241 m_heatLossCoeff = cf.getValueDouble("HeatLosses:heatLossCoeff");
242 m_heatLossParam = cf.getValueDouble("HeatLosses:heatLossParam");
247 void HeatLosses::fetchHeatLosses()
250 QStringList names, allElements, subList;
251 QString elemName, lossName, currItem;
252 //entries = cf.findHleEntries();
253 double areaOut = 0.00, uValueOut = 0.00;
254 allElements = cf.getElementKeyNames();
255 names = cf.findHleEntries();
256 //QMap <QString, QString> hleMap = cf.getInputData();
258 //Search For elements
259 for (int i=0; i < names.size(); ++i)
261 subList = allElements.filter(names.at(i));
262 elemName = names.at(i);
264 //Create Our Element
265 createHeatLossElement(elemName);
267 //Search For individual Losees - IMPORTANT Relies on ini file order
268 //wont work otherwise !!
269 for (int j=0; j < subList.size(); ++j)
271 currItem = subList.at(j);
273 if (currItem.contains("name"))
274 lossName = cf.getValueString(currItem);
275 if (currItem.contains("area"))
276 areaOut = cf.getValueDouble(currItem);
277 if (currItem.contains("uValue"))
279 uValueOut = cf.getValueDouble(currItem);
280 addHeatLoss(elemName,lossName,areaOut,uValueOut);
285 //Add Found Losses
288 //addHeatLoss(elemName,lossName,areaOut,uValueOut);