#include "Temparray.h" Temparray::Temparray(float initialtemp, int x0, int y0, int z0){ temparraynew = new float[x0*y0*z0*6*4]; temparrayold = new float[x0*y0*z0*6*4]; cubearray = new Cubehole[x0*y0*z0*6]; sx = x0; sy = y0; sz = z0; tempInit(initialtemp, x0, y0, z0); // static const float pos[5] = {-2.0, -1.0, 0.0, 1.0, 2.0}; for(int i = 0; i < x0; ++i) { for(int j = 0; j < y0; ++j) { for(int k = 0; k < z0; ++k) { for(int l = 0; l < 6; ++l) { cubehole(i, j, k, l).setSize((6-l)/6.0*0.9, 0.9, (6-l)/6.0*0.9, (5-l)/6.0*0.9, (5-l)/6.0*0.9); float x, y, z; if(x0 % 2 == 0) x = -(x0/2)+i+0.5; else if(x0 % 2 == 1) x = -(x0-1)/2+i; if(y0 % 2 == 0) y = -(y0/2)+j+0.5; else if(y0 % 2 == 1) y = -(y0-1)/2+j; if(z0 % 2 == 0) z = -(z0/2)+k+0.5; else if(z0 % 2 == 1) z = -(z0-1)/2+k; cubehole(i, j, k, l).setPos(x, y, z); cubehole(i, j, k, l).setColor(vmml::vec4f(1.0, 0.5, 1.0, 1.0), vmml::vec4f(0.5, 0.5, 1.0, 1.0), vmml::vec4f(1.0, 0.5, 0.0, 1.0), vmml::vec4f(0.0, 0.5, 0.0, 1.0)); } } } } } void Temparray::calcTemp(){ float specificconductivity = 0.7; float areasmall, area, areabig, distance, capacity, capacity2, capacity3, volume, thermalresistance, thermalresistance2, tau12, tau21, tau13, tau31; float meterperunit = 3.0; float width, height, depth, innerwidth, innerdepth; float width2, height2, depth2, innerwidth2, innerdepth2; float width3, height3, depth3, innerwidth3, innerdepth3; for(int i = 0; i < sx; ++i) { for(int j = 0; j < sy; ++j) { for(int k = 0; k < sz; ++k) { for(int l = 5; l > 0; --l) { for(int m = 0; m < 4; m++) { width = cubehole(i, j, k, l).getWidth(); width2 = cubehole(i, j, k, l-1).getWidth(); if(l!=5)width3 = cubehole(i, j, k, l+1).getWidth(); height = cubehole(i, j, k, l).getHeight(); height2 = cubehole(i, j, k, l-1).getHeight(); if(l!=5)height3 = cubehole(i, j, k, l+1).getHeight(); depth = cubehole(i, j, k, l).getDepth(); depth2 = cubehole(i, j, k, l-1).getDepth(); if(l!=5)depth3 = cubehole(i, j, k, l+1).getDepth(); innerwidth = cubehole(i, j, k, l).getInnerWidth(); innerwidth2 = cubehole(i, j, k, l-1).getInnerWidth(); if(l!=5)innerwidth3 = cubehole(i, j, k, l+1).getInnerWidth(); innerdepth = cubehole(i, j, k, l).getInnerDepth(); innerdepth2 = cubehole(i, j, k, l-1).getInnerDepth(); if(l!=5)innerdepth3 = cubehole(i, j, k, l+1).getInnerDepth(); if(m % 2 == 0) { if(l!=5)areasmall = (((width3 + innerwidth3)/2)*height3) / 0.9 * meterperunit; area = (((width + innerwidth)/2)*height) / 0.9 * meterperunit; areabig = (((width2 + innerwidth2)/2)*height2) / 0.9 * meterperunit; thermalresistance = ((depth2 / 2 - (depth2 - innerdepth2)/4) - (depth / 2 - (depth - innerdepth)/4)) / 0.9 * meterperunit / (specificconductivity * ((area + areabig) / 2)); if(l!=5)thermalresistance2 = ((depth / 2 - (depth - innerdepth)/4)- (depth3 / 2 - (depth3 - innerdepth3)/4)) / 0.9 * meterperunit / (specificconductivity * ((area + areasmall) / 2)); capacity = specificconductivity *((((depth + innerdepth)/2)*((width + innerwidth)/2)* height)/0.9*meterperunit); capacity2 = specificconductivity *((((depth2 + innerdepth2)/2)*((width2 + innerwidth2)/2)* height2)/0.9*meterperunit); if(l!=5)capacity3 = specificconductivity *((((depth3 + innerdepth3)/2)*((width3 + innerwidth3)/2)* height3)/0.9*meterperunit); } else if(m % 2 == 1) { if(l!=5)areasmall = (((depth3 + innerdepth3)/2)*height3) / 0.9 * meterperunit; area = (((depth + innerdepth)/2)*height) / 0.9 * meterperunit; areabig = (((depth2 + innerdepth2)/2)*height2) / 0.9 * meterperunit; thermalresistance = ((width2 / 2 - (width2 - innerwidth2)/4) - (width / 2 - (width - innerwidth)/4)) / 0.9 * meterperunit / (specificconductivity * ((area + areabig) / 2)); if(l!=5)thermalresistance2 = (width3 / 2 - (width3 - innerwidth3)/4) - (width / 2 - (width - innerwidth)/4) / 0.9 * meterperunit / (specificconductivity * ((area + areasmall) / 2)); capacity = specificconductivity *((((depth + innerdepth)/2)*((width + innerwidth)/2)* height)/0.9*meterperunit); capacity2 = specificconductivity *((((depth2 + innerdepth2)/2)*((width2 + innerwidth2)/2)* height2)/0.9*meterperunit); if(l!=5) capacity3 = specificconductivity *((((depth3 + innerdepth3)/2)*((width3 + innerwidth3)/2)* height3)/0.9*meterperunit); } tau12 = capacity * thermalresistance; tau21 = capacity2 * thermalresistance; if(l!=5)tau13 = capacity * thermalresistance; if(l!=5)tau31 = capacity3 * thermalresistance2; temperatureold(i, j, k, l, m) = temperatureold(i, j, k, l, m) + ((temperatureold(i, j, k, l, m) - temperatureold(i, j, k, l-1, m))*-exp(-(1/tau12))); temperatureold(i, j, k, l-1, m) = temperatureold(i, j, k, l-1, m) - ((temperatureold(i, j, k, l, m) - temperatureold(i, j, k, l-1, m))*-exp(-(1/tau21))); if(l!=5)temperatureold(i, j, k, l, m) = temperatureold(i, j, k, l, m) + ((temperatureold(i, j, k, l, m) - temperatureold(i, j, k, l+1, m))*-exp(-(1/tau13))); if(l!=5)temperatureold(i, j, k, l+1, m) = temperatureold(i, j, k, l+1, m) - ((temperatureold(i, j, k, l, m) - temperatureold(i, j, k, l+1, m))*-exp(-(1/tau31))); } } } } } /*for(int i = 0; i < sx; ++i) { for(int j = 0; j < sy; ++j) { for(int k = 0; k < sz; ++k) { for(int l = 0; l < 6; ++l) { for(int m = 0; m < 4; m++) {temperatureold(i, j, k, l, m)=temperaturenew(i, j, k, l, m);}}}}}*/ std::cerr << temperatureold(2, 2, 2, 1, 2) << std::endl; std::cerr << temperatureold(2, 2, 2, 2, 2) << std::endl; std::cerr << temperatureold(2, 2, 2, 3, 2) << std::endl; } std::list Temparray::getTriangles(){ std::list triangles; for(int i = 0; i < sx; ++i) { for(int j = 0; j < sy; ++j) { for(int k = 0; k < sz; ++k) { for(int l = 0; l < 6; ++l) { std::list t = cubehole(i, j, k, l).getTriangles(); triangles.splice(triangles.end(), t); } } } } return triangles; }