#include "House.h" House::House(float inittemp0, int earthx0, int earthy0, int earthz0, float collectortemp0, float radiation0, float latitude0, float eta00, float k10, float k20, float collectorarea0, float roofangle0, float watthoursperhuman0, int humans0, int heaterenergy0): collectortemp(collectortemp0), latitude(latitude0), radiation(radiation0), eta0(eta00), k1(k10), k2(k20), watthoursperhuman(watthoursperhuman0), humans(humans0), collectorarea(collectorarea0), heaterenergy(heaterenergy0), roofangle(roofangle0){ Temparray temp0(inittemp0, earthx0, earthy0, earthz0); Sun sun0(latitude); sun = sun0; temp = temp0; calcefficiency(); calctemp(); calcneededenergy(); collectorstatus = TRANSVERSAL; } void House::calcefficiency() { int ioffset; float x[11], y[11], a, b, j; for(int i=0; i<11; ++i) x[i] = i*10; y[0] = 0.755; y[1] = 0.695; y[2] = 0.635; y[3] = 0.575; y[4] = 0.523; y[5] = 0.468; y[6] = 0.404; y[7] = 0.34; y[8] = 0.282; y[9] = 0.222; y[10] = 0.155; for(int i=0; i<100; ++i) { if(i >= x[0] && i < x[1]) { a = (y[1]-y[0])/10; b = y[0]; ioffset = 0; } if(i >= x[1] && i < x[2]) { a = (y[2]-y[1])/10; b = y[1]; ioffset = 10; } if(i >= x[2] && i < x[3]) { a = (y[3]-y[2])/10; b = y[2]; ioffset = 20; } if(i >= x[3] && i < x[4]) { a = (y[4]-y[3])/10; b = y[3]; ioffset = 30; } if(i >= x[4] && i < x[5]) { a = (y[5]-y[4])/10; b = y[4]; ioffset = 40; } if(i >= x[5] && i < x[6]) { a = (y[6]-y[5])/10; b = y[5]; ioffset = 50; } if(i >= x[6] && i < x[7]) { a = (y[7]-y[6])/10; b = y[6]; ioffset = 60; } if(i >= x[7] && i < x[8]) { a = (y[8]-y[7])/10; b = y[7]; ioffset = 70; } if(i >= x[8] && i < x[9]) { a = (y[9]-y[8])/10; b = y[8]; ioffset = 80; } if(i >= x[9] && i < x[10]) { a = (y[10]-y[9])/10; b = y[9]; ioffset = 90; } efficiencyflat[i] = fabs(a*(i-ioffset)+b); } for(int i=0; i<11; ++i){y[i] = eta0 - (k1/radiation)*i*10 - (k2/radiation)*i*i*100;} for(int i=0; i<100; ++i) { if(i >= x[0] && i < x[1]) { a = (y[1]-y[0])/10; b = y[0]; ioffset = 0; } if(i >= x[1] && i < x[2]) { a = (y[2]-y[1])/10; b = y[1]; ioffset = 10; } if(i >= x[2] && i < x[3]) { a = (y[3]-y[2])/10; b = y[2]; ioffset = 20; } if(i >= x[3] && i < x[4]) { a = (y[4]-y[3])/10; b = y[3]; ioffset = 30; } if(i >= x[4] && i < x[5]) { a = (y[5]-y[4])/10; b = y[4]; ioffset = 40; } if(i >= x[5] && i < x[6]) { a = (y[6]-y[5])/10; b = y[5]; ioffset = 50; } if(i >= x[6] && i < x[7]) { a = (y[7]-y[6])/10; b = y[6]; ioffset = 60; } if(i >= x[7] && i < x[8]) { a = (y[8]-y[7])/10; b = y[7]; ioffset = 70; } if(i >= x[8] && i < x[9]) { a = (y[9]-y[8])/10; b = y[8]; ioffset = 80; } if(i >= x[9] && i < x[10]) { a = (y[10]-y[9])/10; b = y[9]; ioffset = 90; } efficiencyvacuum[i] = fabs(a*(i-ioffset)+b); } anglecorrectiontransversal[0] = 1; anglecorrectiontransversal[1] = 0.998; anglecorrectiontransversal[2] = 0.996; anglecorrectiontransversal[3] = 0.994; anglecorrectiontransversal[4] = 0.992; anglecorrectiontransversal[5] = 0.99; anglecorrectiontransversal[6] = 0.988; anglecorrectiontransversal[7] = 0.986; anglecorrectiontransversal[8] = 0.984; anglecorrectiontransversal[9] = 0.982; anglecorrectiontransversal[10] = 0.98; anglecorrectiontransversal[11] = 0.98; anglecorrectiontransversal[12] = 0.98; anglecorrectiontransversal[13] = 0.98; anglecorrectiontransversal[14] = 0.98; anglecorrectiontransversal[15] = 0.98; anglecorrectiontransversal[16] = 0.982; anglecorrectiontransversal[17] = 0.984; anglecorrectiontransversal[18] = 0.986; anglecorrectiontransversal[19] = 0.988; anglecorrectiontransversal[20] = 0.99; anglecorrectiontransversal[21] = 0.992; anglecorrectiontransversal[22] = 0.994; anglecorrectiontransversal[23] = 0.996; anglecorrectiontransversal[24] = 0.998; for(int i=25; i<61; i++) anglecorrectiontransversal[i] = 1; anglecorrectiontransversal[61] = 1.003; anglecorrectiontransversal[62] = 1.006; anglecorrectiontransversal[63] = 1.009; anglecorrectiontransversal[64] = 1.012; anglecorrectiontransversal[65] = 1.015; anglecorrectiontransversal[66] = 1.022; anglecorrectiontransversal[67] = 1.029; anglecorrectiontransversal[68] = 1.036; anglecorrectiontransversal[69] = 1.043; anglecorrectiontransversal[70] = 1.05; anglecorrectiontransversal[71] = 1.07; anglecorrectiontransversal[72] = 1.09; anglecorrectiontransversal[73] = 1.11; anglecorrectiontransversal[74] = 1.13; anglecorrectiontransversal[75] = 1.15; anglecorrectiontransversal[76] = 1.175; anglecorrectiontransversal[77] = 1.205; anglecorrectiontransversal[78] = 1.240; anglecorrectiontransversal[79] = 1.280; anglecorrectiontransversal[80] = 1.285; anglecorrectiontransversal[81] = 1.265; anglecorrectiontransversal[82] = 1.20; anglecorrectiontransversal[83] = 1.07; anglecorrectiontransversal[84] = 0.95; anglecorrectiontransversal[85] = 0.8; anglecorrectiontransversal[86] = 0.64; anglecorrectiontransversal[87] = 0.48; anglecorrectiontransversal[88] = 0.32; anglecorrectiontransversal[89] = 0.16; anglecorrectiontransversal[90] = 0; for(int i=0; i<25; ++i) anglecorrectionlongitudinal[i] = 1; anglecorrectionlongitudinal[26] = 0.999; anglecorrectionlongitudinal[27] = 0.998; anglecorrectionlongitudinal[28] = 0.997; anglecorrectionlongitudinal[29] = 0.996; anglecorrectionlongitudinal[30] = 0.995; anglecorrectionlongitudinal[31] = 0.992; anglecorrectionlongitudinal[32] = 0.989; anglecorrectionlongitudinal[33] = 0.986; anglecorrectionlongitudinal[34] = 0.983; anglecorrectionlongitudinal[35] = 0.98; anglecorrectionlongitudinal[36] = 0.978; anglecorrectionlongitudinal[37] = 0.976; anglecorrectionlongitudinal[38] = 0.974; anglecorrectionlongitudinal[39] = 0.972; anglecorrectionlongitudinal[40] = 0.97; anglecorrectionlongitudinal[41] = 0.968; anglecorrectionlongitudinal[42] = 0.966; anglecorrectionlongitudinal[43] = 0.964; anglecorrectionlongitudinal[44] = 0.962; anglecorrectionlongitudinal[45] = 0.96; anglecorrectionlongitudinal[46] = 0.958; anglecorrectionlongitudinal[47] = 0.956; anglecorrectionlongitudinal[48] = 0.954; anglecorrectionlongitudinal[49] = 0.952; anglecorrectionlongitudinal[50] = 0.95; anglecorrectionlongitudinal[51] = 0.948; anglecorrectionlongitudinal[52] = 0.946; anglecorrectionlongitudinal[53] = 0.944; anglecorrectionlongitudinal[54] = 0.942; anglecorrectionlongitudinal[55] = 0.94; anglecorrectionlongitudinal[56] = 0.938; anglecorrectionlongitudinal[57] = 0.936; anglecorrectionlongitudinal[58] = 0.934; anglecorrectionlongitudinal[59] = 0.932; anglecorrectionlongitudinal[60] = 0.93; anglecorrectionlongitudinal[61] = 0.922; anglecorrectionlongitudinal[62] = 0.914; anglecorrectionlongitudinal[63] = 0.906; anglecorrectionlongitudinal[64] = 0.898; anglecorrectionlongitudinal[65] = 0.89; anglecorrectionlongitudinal[66] = 0.88; anglecorrectionlongitudinal[67] = 0.87; anglecorrectionlongitudinal[68] = 0.86; anglecorrectionlongitudinal[69] = 0.85; anglecorrectionlongitudinal[70] = 0.84; anglecorrectionlongitudinal[71] = 0.824; anglecorrectionlongitudinal[72] = 0.808; anglecorrectionlongitudinal[73] = 0.792; anglecorrectionlongitudinal[74] = 0.776; anglecorrectionlongitudinal[75] = 0.76; anglecorrectionlongitudinal[76] = 0.735; anglecorrectionlongitudinal[77] = 0.71; anglecorrectionlongitudinal[78] = 0.685; anglecorrectionlongitudinal[79] = 0.66; anglecorrectionlongitudinal[80] = 0.635; anglecorrectionlongitudinal[81] = 0.583; anglecorrectionlongitudinal[82] = 0.531; anglecorrectionlongitudinal[83] = 0.479; anglecorrectionlongitudinal[84] = 0.427; anglecorrectionlongitudinal[85] = 0.375; anglecorrectionlongitudinal[86] = 0.3; anglecorrectionlongitudinal[87] = 0.225; anglecorrectionlongitudinal[88] = 0.15; anglecorrectionlongitudinal[89] = 0.075; anglecorrectionlongitudinal[90] = 0; for(int i=0; i<25; ++i) anglecorrectionflat[i] = 1; anglecorrectionflat[26] = 0.999; anglecorrectionflat[27] = 0.998; anglecorrectionflat[28] = 0.997; anglecorrectionflat[29] = 0.996; anglecorrectionflat[30] = 0.995; anglecorrectionflat[31] = 0.992; anglecorrectionflat[32] = 0.989; anglecorrectionflat[33] = 0.986; anglecorrectionflat[34] = 0.983; anglecorrectionflat[35] = 0.98; anglecorrectionflat[36] = 0.982; anglecorrectionflat[37] = 0.974; anglecorrectionflat[38] = 0.966; anglecorrectionflat[39] = 0.958; anglecorrectionflat[40] = 0.95; anglecorrectionflat[41] = 0.946; anglecorrectionflat[42] = 0.942; anglecorrectionflat[43] = 0.938; anglecorrectionflat[44] = 0.934; anglecorrectionflat[45] = 0.93; anglecorrectionflat[46] = 0.924; anglecorrectionflat[47] = 0.918; anglecorrectionflat[48] = 0.912; anglecorrectionflat[49] = 0.906; anglecorrectionflat[50] = 0.90; anglecorrectionflat[51] = 0.89; anglecorrectionflat[52] = 0.88; anglecorrectionflat[53] = 0.87; anglecorrectionflat[54] = 0.86; anglecorrectionflat[55] = 0.85; anglecorrectionflat[56] = 0.837; anglecorrectionflat[57] = 0.824; anglecorrectionflat[58] = 0.811; anglecorrectionflat[59] = 0.798; anglecorrectionflat[60] = 0.785; anglecorrectionflat[61] = 0.77; anglecorrectionflat[62] = 0.755; anglecorrectionflat[63] = 0.74; anglecorrectionflat[64] = 0.725; anglecorrectionflat[65] = 0.71; anglecorrectionflat[66] = 0.693; anglecorrectionflat[67] = 0.676; anglecorrectionflat[68] = 0.659; anglecorrectionflat[69] = 0.642; anglecorrectionflat[70] = 0.625; anglecorrectionflat[71] = 0.605; anglecorrectionflat[72] = 0.585; anglecorrectionflat[73] = 0.565; anglecorrectionflat[74] = 0.545; anglecorrectionflat[75] = 0.525; anglecorrectionflat[76] = 0.501; anglecorrectionflat[77] = 0.477; anglecorrectionflat[78] = 0.453; anglecorrectionflat[79] = 0.429; anglecorrectionflat[80] = 0.405; anglecorrectionflat[81] = 0.371; anglecorrectionflat[82] = 0.337; anglecorrectionflat[83] = 0.303; anglecorrectionflat[84] = 0.269; anglecorrectionflat[85] = 0.235; anglecorrectionflat[86] = 0.188; anglecorrectionflat[87] = 0.141; anglecorrectionflat[88] = 0.094; anglecorrectionflat[89] = 0.047; anglecorrectionflat[90] = 0; } void House::calctemp() { float temperatureday[12], temperaturenight[12]; temperatureday[0] = 3; temperatureday[1] = 4; temperatureday[2] = 8; temperatureday[3] = 13; temperatureday[4] = 18; temperatureday[5] = 20; temperatureday[6] = 22; temperatureday[7] = 22; temperatureday[8] = 18; temperatureday[9] = 13; temperatureday[10] = 7; temperatureday[11] = 4; temperaturenight[0] = -1; temperaturenight[1] = -1; temperaturenight[2] = 2; temperaturenight[3] = 4; temperaturenight[4] = 8; temperaturenight[5] = 11; temperaturenight[6] = 13; temperaturenight[7] = 13; temperaturenight[8] = 10; temperaturenight[9] = 7; temperaturenight[10] = 3; temperaturenight[11] = 0; for(int i=0; i<12; ++i) { for(int j=0; j<24; ++j) { tempoutside[i][j] = ((temperatureday[i]-temperaturenight[i])/2)* (cos(((float)(j-12)/24)*2*M_PI)+1)+temperaturenight[i]; } } tempinside[0] = 18; tempinside[1] = 18; tempinside[2] = 18; tempinside[3] = 18; tempinside[4] = 18; tempinside[5] = 18; tempinside[6] = 18; tempinside[7] = 20; tempinside[8] = 20; tempinside[9] = 20; tempinside[10] = 20; tempinside[11] = 20; tempinside[12] = 20; tempinside[13] = 20; tempinside[14] = 20; tempinside[15] = 20; tempinside[16] = 20; tempinside[17] = 20; tempinside[18] = 20; tempinside[19] = 20; tempinside[20] = 20; tempinside[21] = 20; tempinside[22] = 20; tempinside[23] = 18; } void House::calcdiff() { for(int i=0; i < 12; ++i) { for(int j=0; j < 24; ++j) { tempdifference[i][j] = tempinside[j] - tempoutside[i][j]; } } } void House::calcneededenergy() { float x=0; calcdiff(); for (int i=0; i<12; ++i) { for (int j=0; j<24; ++j) { if (tempdifference>0) { switch (i) { case 0: x+= tempdifference[i][j]*31; break; case 1: x+= tempdifference[i][j]*28; break; case 2: x+= tempdifference[i][j]*31; break; case 3: x+= tempdifference[i][j]*30; break; case 4: x+= tempdifference[i][j]*31; break; case 5: x+= tempdifference[i][j]*30; break; case 6: x+= tempdifference[i][j]*31; break; case 7: x+= tempdifference[i][j]*31; break; case 8: x+= tempdifference[i][j]*30; break; case 9: x+= tempdifference[i][j]*31; break; case 10: x+= tempdifference[i][j]*30; break; case 11: x+= tempdifference[i][j]*31; break; } } } } for(int i=0; i<12; ++i) { for(int j=0; j<24; ++j) { neededenergy[i][j] = tempdifference[i][j]/x*1000*heaterenergy+(watthoursperhuman*humans/24); } } } // maxenergiebedarf := 0; // for i:= 1 to 365 do // begin // for j:=1 to 24 do // begin // if energiebedarf[i,j]>maxenergiebedarf then // maxenergiebedarf := energiebedarf[i,j]; // end; // end; void House::calccollectoroutput(int day, int time, int month) { if(sun.elevationangle(day, time) >= 0){ if(collectorstatus == TRANSVERSAL) collectoroutput = efficiencyvacuum[(int)(collectortemp-tempoutside[month][time]+0.5)] *anglecorrectiontransversal[(int)(fabs(sun.azimutangle(day, time)/2)+0.5)] *anglecorrectionlongitudinal[(int)(fabs(roofangle-sun.elevationangle(day, time))+0.5)] /**100*/; else if(collectorstatus == LONGITUDINAL) collectoroutput = efficiencyvacuum[(int)(collectortemp-tempoutside[month][time]+0.5)] *anglecorrectionlongitudinal[(int)(fabs(sun.azimutangle(day, time)/2)+0.5)] *anglecorrectiontransversal[(int)(fabs(roofangle-sun.elevationangle(day, time))+0.5)] /**100*/; else if(collectorstatus == FLAT) collectoroutput = efficiencyflat[(int)(collectortemp-tempoutside[month][time]+0.5)] *anglecorrectionflat[(int)(fabs(sun.azimutangle(day, time)/2)+0.5)] *anglecorrectionflat[(int)(fabs(roofangle-sun.elevationangle(day, time))+0.5)] /**100*/; collectoroutput = collectoroutput*collectorarea*radiation; } else collectoroutput = 0; } void House::calcprobeinput(int day, int time, int month) { calccollectoroutput(day, time, month); collectoroutput-=neededenergy[month][time]; // std::cerr << sun.azimutangle(day, time) << std::endl; } void House::controller(){ static int day=0, time=0, month=0; calcprobeinput(day, time, month); temp.setprobetemp(collectortemp); temp.setinput(collectoroutput); temp.calcTemp(); //std::cerr << day << " " << time << " " << temp.getaverage() << std::endl; std::cerr << "Time: " << time << " Day of Year: " << day+1 << " Month: " << month+1 << " Output: " << collectoroutput << " Watt" << std::endl; ++time; if(time > 23){ time = 0; ++day; } if(day > 364) day = 0; if (day>=0 && day<=30) month = 0; if (day>=31 && day<=58) month = 1; if (day>=59 && day<=89) month = 2; if (day>=90 && day<=119) month = 3; if (day>=120 && day<=150) month = 4; if (day>=151 && day<=180) month = 5; if (day>=181 && day<=211) month = 6; if (day>=212 && day<=242) month = 7; if (day>=243 && day<=272) month = 8; if (day>=273 && day<=303) month = 9; if (day>=304 && day<=333) month = 10; if (day>=334 && day<=364) month = 11; }