#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)); } } } } /* cubehole(2, 2, 2, 1).setColor(vmml::vec4f(0.0, 0.0, 0.0, 1.0), vmml::vec4f(0.0, 0.0, 0.0, 1.0), vmml::vec4f(0.0, 0.0, 0.0, 1.0), vmml::vec4f(0.0, 0.0, 0.0, 1.0)); cubehole(2, 2, 2, 2).setColor(vmml::vec4f(1.0, 1.0, 1.0, 1.0), vmml::vec4f(1.0, 1.0, 1.0, 1.0), vmml::vec4f(1.0, 1.0, 1.0, 1.0), vmml::vec4f(1.0, 1.0, 1.0, 1.0)); cubehole(2, 2, 2, 3).setColor(vmml::vec4f(0.5, 0.5, 0.5, 1.0), vmml::vec4f(0.5, 0.5, 0.5, 1.0), vmml::vec4f(0.5, 0.5, 0.5, 1.0), vmml::vec4f(0.5, 0.5, 0.5, 1.0));*/ } void Temparray::calcTemp(){ float conductivity = 0.7, specificcapacity = 1513; float areasmall, area, areabig, distance, capacity, capacity2, volume, thermalresistance, tau12, tau21; float meterperunit = 3.0; float width, height, depth, innerwidth, innerdepth; float width2, height2, depth2, innerwidth2, innerdepth2; float loadableenergy, unloadableenergy; for(int i = 0; i < sx; ++i) { for(int j = 0; j < sy; ++j) { for(int k = 0; k < sz; ++k) { for(int l = 1; l < 6; ++l) { for(int m = 0; m < 4; ++m) { width = cubehole(i, j, k, l).getWidth(); width2 = cubehole(i, j, k, l-1).getWidth(); height = cubehole(i, j, k, l).getHeight(); height2 = cubehole(i, j, k, l-1).getHeight(); depth = cubehole(i, j, k, l).getDepth(); depth2 = cubehole(i, j, k, l-1).getDepth(); innerwidth = cubehole(i, j, k, l).getInnerWidth(); innerwidth2 = cubehole(i, j, k, l-1).getInnerWidth(); innerdepth = cubehole(i, j, k, l).getInnerDepth(); innerdepth2 = cubehole(i, j, k, l-1).getInnerDepth(); if(m % 2 == 0) { 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 / (conductivity * ((area + areabig) / 2)); capacity = specificcapacity *((((depth - innerdepth)/2)*((width + innerwidth)/2)* height)/0.9*meterperunit); capacity2 = specificcapacity *((((depth2 - innerdepth2)/2)*((width2 + innerwidth2)/2)* height2)/0.9*meterperunit); } else if(m % 2 == 1) { 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 / (conductivity * ((area + areabig) / 2)); capacity = specificcapacity *((((depth + innerdepth)/2)*((width - innerwidth)/2)* height)/0.9*meterperunit); capacity2 = specificcapacity *((((depth2 + innerdepth2)/2)*((width2 - innerwidth2)/2)* height2)/0.9*meterperunit); } tau12 = capacity * thermalresistance; tau21 = capacity2 * thermalresistance; temperaturenew(i, j, k, l, m) = temperaturenew(i, j, k, l, m) - ((temperatureold(i, j, k, l, m) - temperatureold(i, j, k, l-1, m))*(1-exp(-(1/tau12)))); temperaturenew(i, j, k, l-1, m) = temperaturenew(i, j, k, l-1, m) + ((temperatureold(i, j, k, l, m) - temperatureold(i, j, k, l-1, m))*(1-exp(-(1/tau21)))); } } } } } for(int h = 0; h < 10; ++h) { 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++) { width = cubehole(i, j, k, l).getWidth(); height = cubehole(i, j, k, l).getHeight(); depth = cubehole(i, j, k, l).getDepth(); innerwidth = cubehole(i, j, k, l).getInnerWidth(); innerdepth = cubehole(i, j, k, l).getInnerDepth(); if(m % 2 == 0)area = (((depth - innerdepth)/2)*((width + innerwidth)/2)) / 0.9 * meterperunit; if(m % 2 == 1)area = (((width - innerwidth)/2)*((depth + innerdepth)/2)) / 0.9 * meterperunit; if(m % 2 == 0)thermalresistance = ((depth - innerdepth)/2) /0.9 * meterperunit /(conductivity * area); if(m % 2 == 1)thermalresistance = ((width - innerwidth)/2) /0.9 * meterperunit /(conductivity * area); if(m % 2 == 0)capacity = specificcapacity *((((depth - innerdepth)/2)* ((width + innerwidth)/2)*height) / 0.9 * meterperunit); if(m % 2 == 1)capacity = specificcapacity *((((width - innerwidth)/2)* ((depth + innerdepth)/2)*height) / 0.9 * meterperunit); loadableenergy = (probetemp - temperatureold(i, j, k, l, m))/thermalresistance/10; unloadableenergy = (temperatureold(i, j, k, l, m)-21.5)/thermalresistance/10; tau12 = capacity * thermalresistance; if(input>=0){ if(loadableenergy <= 0) inputpower = 0; else if (input >= loadableenergy) { inputpower = loadableenergy; input -= loadableenergy; } else if (input < loadableenergy) { inputpower = input; input = 0; } if(inputpower > 0) { factor = inputpower/loadableenergy; temperaturenew(i, j, k, l, m) = temperaturenew(i, j, k, l, m) + (probetemp-temperatureold(i, j, k, l, m)) *thermalresistance*factor*(1-exp(-(1/tau12))); } } if (input < 0){ if(unloadableenergy <= 0) inputpower = 0; else if (input > unloadableenergy) { inputpower = unloadableenergy; input -= unloadableenergy; } else if (input <= unloadableenergy) { inputpower = input; input = 0; } if(inputpower > 0) { factor = inputpower/unloadableenergy; temperaturenew(i, j, k, l, m) = temperaturenew(i, j, k, l, m) + (21.5-temperatureold(i, j, k, l, m)) *thermalresistance*factor*(1-exp(-(1/tau12))); } } } } } } } } 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++) { width = cubehole(i, j, k, l).getWidth(); height = cubehole(i, j, k, l).getHeight(); depth = cubehole(i, j, k, l).getDepth(); innerwidth = cubehole(i, j, k, l).getInnerWidth(); innerdepth = cubehole(i, j, k, l).getInnerDepth(); if(j > 0) { width2 = cubehole(i, j-1, k, l).getWidth(); height2 = cubehole(i, j-1, k, l).getHeight(); depth2 = cubehole(i, j-1, k, l).getDepth(); innerwidth2 = cubehole(i, j-1, k, l).getInnerWidth(); innerdepth2 = cubehole(i, j-1, k, l).getInnerDepth(); if(m % 2 == 0) { area = (((width + innerwidth)/2) * ((depth-innerdepth)/2)) / 0.9 * meterperunit; areabig = (((width2 + innerwidth2)/2) * ((depth2-innerdepth2)/2)) / 0.9 * meterperunit; thermalresistance = (height/2+height2/2) / 0.9 * meterperunit / (conductivity * ((area + areabig) / 2)); capacity = specificcapacity *((((depth - innerdepth)/2)*((width + innerwidth)/2)* height)/0.9*meterperunit); capacity2 = specificcapacity *((((depth2 - innerdepth2)/2)*((width2 + innerwidth2)/2)* height2)/0.9*meterperunit); } else if(m % 2 == 1) { area = (((depth + innerdepth)/2) * ((width-innerwidth)/2)) / 0.9 * meterperunit; areabig = (((depth2 + innerdepth2)/2) * ((width2-innerwidth2)/2)) / 0.9 * meterperunit; thermalresistance = (height/2+height2/2) / 0.9 * meterperunit / (conductivity * ((area + areabig) / 2)); capacity = specificcapacity *((((depth + innerdepth)/2)*((width - innerwidth)/2)* height)/0.9*meterperunit); capacity2 = specificcapacity *((((depth2 + innerdepth2)/2)*((width2 - innerwidth2)/2)* height2)/0.9*meterperunit); } tau12 = capacity * thermalresistance; tau21 = capacity2 * thermalresistance; temperaturenew(i, j, k, l, m) = temperaturenew(i, j, k, l, m) - ((temperatureold(i, j, k, l, m) - temperatureold(i, j-1, k, l, m))*(1-exp(-(1/tau12)))); temperaturenew(i, j-1, k, l, m) = temperaturenew(i, j-1, k, l, m) + ((temperatureold(i, j, k, l, m) - temperatureold(i, j-1, k, l, m))*(1-exp(-(1/tau21)))); } if(m == 0) { area = (sqrt(pow((depth-innerdepth)/2, 2) + pow((width-innerwidth)/2, 2))* height) / 0.9 * meterperunit; thermalresistance = sqrt(pow((width/2 - (width-innerwidth)/4)/2, 2)+ pow((depth/2 - (depth-innerdepth)/4)/2, 2))/ 0.9 * meterperunit /(conductivity * area); capacity = specificcapacity *((((depth - innerdepth)/2)*((width + innerwidth)/2)* height)/0.9*meterperunit); capacity2 = specificcapacity *((((width - innerwidth)/2)*((depth + innerdepth)/2)* height)/0.9*meterperunit); tau12 = capacity * thermalresistance; tau21 = capacity2 * thermalresistance; temperaturenew(i, j, k, l, m) = temperaturenew(i, j, k, l, m) - ((temperatureold(i, j, k, l, m) - temperatureold(i, j, k, l, 1))*(1-exp(-(1/tau12)))); temperaturenew(i, j, k, l, 1) = temperaturenew(i, j, k, l, 1) + ((temperatureold(i, j, k, l, m) - temperatureold(i, j, k, l, 1))*(1-exp(-(1/tau21)))); } else if(m == 1) { area = (sqrt(pow((width-innerwidth)/2, 2) + pow((depth-innerdepth)/2, 2))* height) / 0.9 * meterperunit; thermalresistance = sqrt(pow((depth/2 - (depth-innerdepth)/4)/2, 2)+ pow((width/2 - (width-innerwidth)/4)/2, 2))/ 0.9 * meterperunit /(conductivity * area); capacity = specificcapacity *((((width - innerwidth)/2)*((depth + innerdepth)/2)* height)/0.9*meterperunit); capacity2 = specificcapacity *((((depth - innerdepth)/2)*((width + innerwidth)/2)* height)/0.9*meterperunit); tau12 = capacity * thermalresistance; tau21 = capacity2 * thermalresistance; temperaturenew(i, j, k, l, 1) = temperaturenew(i, j, k, l, 1) - ((temperatureold(i, j, k, l, 1) - temperatureold(i, j, k, l, 2))*(1-exp(-(1/tau12)))); temperaturenew(i, j, k, l, 2) = temperaturenew(i, j, k, l, 2) + ((temperatureold(i, j, k, l, 1) - temperatureold(i, j, k, l, 2))*(1-exp(-(1/tau21)))); } else if(m == 2) { area = (sqrt(pow((depth-innerdepth)/2, 2) + pow((width-innerwidth)/2, 2))* height) / 0.9 * meterperunit; thermalresistance = sqrt(pow((width/2 - (width-innerwidth)/4)/2, 2)+ pow((depth/2 - (depth-innerdepth)/4)/2, 2))/ 0.9 * meterperunit /(conductivity * area); capacity = specificcapacity *((((depth - innerdepth)/2)*((width + innerwidth)/2)* height)/0.9*meterperunit); capacity2 = specificcapacity *((((width - innerwidth)/2)*((depth + innerdepth)/2)* height)/0.9*meterperunit); tau12 = capacity * thermalresistance; tau21 = capacity2 * thermalresistance; temperaturenew(i, j, k, l, 2) = temperaturenew(i, j, k, l, 2) - ((temperatureold(i, j, k, l, 2) - temperatureold(i, j, k, l, 3))*(1-exp(-(1/tau12)))); temperaturenew(i, j, k, l, 3) = temperaturenew(i, j, k, l, 3) + ((temperatureold(i, j, k, l, 2) - temperatureold(i, j, k, l, 3))*(1-exp(-(1/tau21)))); } else if(m == 3) { area = (sqrt(pow((width-innerwidth)/2, 2) + pow((depth-innerdepth)/2, 2))* height) / 0.9 * meterperunit; thermalresistance = sqrt(pow((depth/2 - (depth-innerdepth)/4)/2, 2)+ pow((width/2 - (width-innerwidth)/4)/2, 2))/ 0.9 * meterperunit /(conductivity * area); capacity = specificcapacity *((((width - innerwidth)/2)*((depth + innerdepth)/2)* height)/0.9*meterperunit); capacity2 = specificcapacity *((((depth - innerdepth)/2)*((width + innerwidth)/2)* height)/0.9*meterperunit); tau12 = capacity * thermalresistance; tau21 = capacity2 * thermalresistance; temperaturenew(i, j, k, l, 3) = temperaturenew(i, j, k, l, 3) - ((temperatureold(i, j, k, l, 3) - temperatureold(i, j, k, l, 0))*(1-exp(-(1/tau12)))); temperaturenew(i, j, k, l, 0) = temperaturenew(i, j, k, l, 0) + ((temperatureold(i, j, k, l, 3) - temperatureold(i, j, k, l, 0))*(1-exp(-(1/tau21)))); } if(j == sy-1) { if(m % 2 == 0)area = (((depth - innerdepth)/2)*((width + innerwidth)/2)) / 0.9 * meterperunit; if(m % 2 == 1)area = (((width - innerwidth)/2)*((depth + innerdepth)/2)) / 0.9 * meterperunit; thermalresistance = (3 + height/2) / 0.9 * meterperunit /(conductivity * area); if(m % 2 == 0)capacity = specificcapacity *((((depth - innerdepth)/2)* ((width + innerwidth)/2)*height) / 0.9 * meterperunit); if(m % 2 == 1)capacity = specificcapacity *((((width - innerwidth)/2)* ((depth + innerdepth)/2)*height) / 0.9 * meterperunit); tau12 = capacity * thermalresistance; temperaturenew(i, j, k, 0, m) = temperaturenew(i, j, k, 0, m) - ((temperatureold(i, j, k, 0, m) - earthtemp) *(1-exp(-(1/tau12)))); } } } if(i > 0) { width = cubehole(i, j, k, 0).getWidth(); height = cubehole(i, j, k, 0).getHeight(); depth = cubehole(i, j, k, 0).getDepth(); innerwidth = cubehole(i, j, k, 0).getInnerWidth(); innerdepth = cubehole(i, j, k, 0).getInnerDepth(); area = (((depth + innerdepth)/2)*height) / 0.9 * meterperunit; thermalresistance = ((width - innerwidth)/2) / 0.9 * meterperunit / (conductivity * area); capacity = specificcapacity *((((depth + innerdepth)/2)*((width - innerwidth)/2)* height)/0.9*meterperunit); tau12 = capacity * thermalresistance; temperaturenew(i, j, k, 0, 3) = temperaturenew(i, j, k, 0, 3) - ((temperatureold(i, j, k, 0, 3) - temperatureold(i-1, j, k, 0, 1))*(1-exp(-(1/tau12)))); temperaturenew(i-1, j, k, 0, 1) = temperaturenew(i-1, j, k, 0, 1) + ((temperatureold(i, j, k, 0, 3) - temperatureold(i-1, j, k, 0, 1))*(1-exp(-(1/tau12)))); } if (i == 0 || i == sx-1) { int h=3; if(i == sx-1) h=1; width = cubehole(i, j, k, 0).getWidth(); height = cubehole(i, j, k, 0).getHeight(); depth = cubehole(i, j, k, 0).getDepth(); innerwidth = cubehole(i, j, k, 0).getInnerWidth(); innerdepth = cubehole(i, j, k, 0).getInnerDepth(); area = (((depth + innerdepth)/2)*height) / 0.9 * meterperunit; thermalresistance = (3 + (width - innerwidth)/4) / 0.9 * meterperunit / (conductivity * area); capacity = specificcapacity *((((depth + innerdepth)/2)*((width - innerwidth)/2)* height)/0.9*meterperunit); tau12 = capacity * thermalresistance; temperaturenew(i, j, k, 0, h) = temperaturenew(i, j, k, 0, h) - ((temperatureold(i, j, k, 0, h) - earthtemp) *(1-exp(-(1/tau12)))); } if(k > 0) { width = cubehole(i, j, k, 0).getWidth(); height = cubehole(i, j, k, 0).getHeight(); depth = cubehole(i, j, k, 0).getDepth(); innerwidth = cubehole(i, j, k, 0).getInnerWidth(); innerdepth = cubehole(i, j, k, 0).getInnerDepth(); area = (((width + innerwidth)/2)*height) / 0.9 * meterperunit; thermalresistance = ((depth - innerdepth)/2) / 0.9 * meterperunit / (conductivity * area); capacity = specificcapacity *((((depth - innerdepth)/2)*((width + innerwidth)/2)* height)/0.9*meterperunit); tau12 = capacity * thermalresistance; temperaturenew(i, j, k, 0, 0) = temperaturenew(i, j, k, 0, 0) - ((temperatureold(i, j, k, 0, 0) - temperatureold(i-1, j, k-1, 0, 2))*(1-exp(-(1/tau12)))); temperaturenew(i, j, k-1, 0, 2) = temperaturenew(i, j, k-1, 0, 2) + ((temperatureold(i, j, k, 0, 0) - temperatureold(i, j, k-1, 0, 2))*(1-exp(-(1/tau12)))); } if(k == 0 || k == sz-1) { int h=0; if(i == sz-1) h=2; width = cubehole(i, j, k, 0).getWidth(); height = cubehole(i, j, k, 0).getHeight(); depth = cubehole(i, j, k, 0).getDepth(); innerwidth = cubehole(i, j, k, 0).getInnerWidth(); innerdepth = cubehole(i, j, k, 0).getInnerDepth(); area = (((width + innerwidth)/2)*height) / 0.9 * meterperunit; thermalresistance = (3 + (depth - innerdepth)/4) / 0.9 * meterperunit / (conductivity * area); capacity = specificcapacity *((((width + innerwidth)/2)*((depth - innerdepth)/2)* height)/0.9*meterperunit); tau12 = capacity * thermalresistance; temperaturenew(i, j, k, 0, h) = temperaturenew(i, j, k, 0, h) - ((temperatureold(i, j, k, 0, h) - earthtemp) *(1-exp(-(1/tau12)))); } } } } mergetemperature(); coloring(); // std::cerr << temperaturenew(2, 2, 2, 1, 2) << std::endl; // std::cerr << temperaturenew(2, 2, 2, 2, 2) << std::endl; // std::cerr << temperaturenew(2, 2, 2, 3, 2) << "\n" << std::endl; // std::cerr << " " << temperatureold(2, 2, 2, 1, 2) << std::endl; // std::cerr << temperatureold(2, 2, 2, 2, 1) << " " << temperatureold(2, 2, 2, 2, 2) << " " << temperatureold(2, 2, 2, 2, 3) << std::endl; // std::cerr << " " << temperatureold(2, 2, 2, 3, 2) << "\n" << 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; } void Temparray::coloring() { calcAverage(); float r[4], g[4], b[4], percent, factor; for(int i=0; i b[m]){ factor = 1 + (1-g[m]) / g[m]; } else { factor = 1 + (1-b[m]) / b[m]; } g[m] *= factor; b[m] *= factor; } else if (percent == 0.5) { r[m] = 0; g[m] = 1; b[m] = 0; } else if (percent > 0.5) { r[m] = (percent-0.5)*2; g[m] = 1-(percent-0.5)*2; b[m] = 0; if(r[m] > g[m]){ factor = 1 + (1-r[m]) / r[m]; } else { factor = 1 + (1-g[m]) / g[m]; } r[m] *= factor; g[m] *= factor; } cubehole(i, j, k, l).setColor(vmml::vec4f(r[0], g[0], b[0], 1.0), vmml::vec4f(r[1], g[1], b[1], 1.0), vmml::vec4f(r[2], g[2], b[2], 1.0), vmml::vec4f(r[3], g[3], b[3], 1.0)); } } } } } }