summaryrefslogtreecommitdiffstats
path: root/Temparray.cpp
blob: 798bbc5510af9a04bebed090056fc08aab554024 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#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, 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 = 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();
            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 /
                                   (conductivity * ((area + areabig) / 2));
              if(l!=5)thermalresistance2 = ((depth / 2 - (depth - innerdepth)/4)-
                                   (depth3 / 2 - (depth3 - innerdepth3)/4)) / 0.9 * meterperunit /
                                   (conductivity * ((area + areasmall) / 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);
              if(l!=5)capacity3 = specificcapacity *((((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 /
                                   (conductivity * ((area + areabig) / 2));
              if(l!=5)thermalresistance2 = (width3 / 2 - (width3 - innerwidth3)/4) -
                                   (width / 2 - (width - innerwidth)/4) / 0.9 * meterperunit /
                                   (conductivity * ((area + areasmall) / 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);
              if(l!=5)
              capacity3 = specificcapacity *((((depth3 - innerdepth3)/2)*((width3 + innerwidth3)/2)*
                                                    height3)/0.9*meterperunit);
            }
            tau12 = capacity * thermalresistance;
            tau21 = capacity2 * thermalresistance;
            if(l!=5)tau13 = capacity * thermalresistance2;
            if(l!=5)tau31 = capacity3 * thermalresistance2;
            
            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))));

            if(l!=5)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/tau13))));
            if(l!=5)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/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++) {
            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 == 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, 3))*(1-exp(-(1/tau12))));
              temperaturenew(i, j, k, l, 3) =
                temperaturenew(i, j, k, l, 3) + ((temperatureold(i, j, k, l, m) -
                  temperatureold(i, j, k, l, 3))*(1-exp(-(1/tau21))));
              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, 0))*(1-exp(-(1/tau12))));
              temperaturenew(i, j, k, l, 0) =
                temperaturenew(i, j, k, l, 0) + ((temperatureold(i, j, k, l, 1) -
                  temperatureold(i, j, k, l, 0))*(1-exp(-(1/tau21))));
              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, 1))*(1-exp(-(1/tau12))));
              temperaturenew(i, j, k, l, 1) =
                temperaturenew(i, j, k, l, 1) + ((temperatureold(i, j, k, l, 2) -
                  temperatureold(i, j, k, l, 1))*(1-exp(-(1/tau21))));
              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, 2))*(1-exp(-(1/tau12))));
              temperaturenew(i, j, k, l, 2) =
                temperaturenew(i, j, k, l, 2) + ((temperatureold(i, j, k, l, 3) -
                  temperatureold(i, j, k, l, 2))*(1-exp(-(1/tau21))));
              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))));
            }
          }
        }
      }
    }
  }
  mergetemperature();
//  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<Triangle> Temparray::getTriangles(){
  std::list<Triangle> 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<Triangle> t = cubehole(i, j, k, l).getTriangles();
          triangles.splice(triangles.end(), t);
        }
      }
    }
  }

  return triangles;
}