-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathground_only.m
380 lines (297 loc) · 8.92 KB
/
ground_only.m
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
clc;
%clear all;
load('for_ground_simulate.mat')
%% 253번이 T_out, 254번이 T_sky
%% inputs needed
mesh = 6;
meshsize = 2;
% mesh numbers, consider T_sky + T_out later
N_node_go = mesh * mesh * (mesh + 1);
N_node_all = N_node_go + 2;
N_weather = max(size(weather(:, 1)));
M = zeros(N_node_go + 2, N_node_go + 2);
S = zeros(N_node_go + 2 + 1, N_node_go + 2 + 1);
f = zeros(N_node_go + 2, 1);
%% Material properties
soil_conductivity = 0.44;
soil_specific_heat = 1175.56; %733; % J/kg*degC
soil_solar_absorptance = 0.6;
soil_h_rad = 5.5; % W/m²K
soil_h_conv = 2.5; % W/m²K
soil_density = 1; %1600; %kg/m^3
m = soil_density * soil_specific_heat * meshsize * meshsize; % * [1, 0; 0, 1];
S_cond = 1/4 * soil_conductivity * meshsize * [1, -1; -1, 1];
S_conv = soil_h_conv * meshsize * meshsize * [1, -1; -1, 1];
S_rad = soil_h_rad * meshsize * meshsize * [1, -1; -1, 1];
%% not for now
floor_node = 1000;
%% matching numbers with coordinates
Node_info = zeros(N_node_go, 10);
for i = 1 : N_node_go
for x = 0 : mesh - 1
for y = 0 : mesh - 1
for z = 0 : mesh
if x + mesh * y + mesh * mesh * z == i - 1
Node_info(i, 2) = x;
Node_info(i, 3) = y;
Node_info(i, 4) = z;
end
end
end
end
end
clearvars x;
clearvars y;
clearvars z;
%% give nodes status including BC
for i = 1 : N_node_go
if Node_info(i, 2) == 0 % x equals 0
Node_info(i, 1) = 1;
end
if Node_info(i, 2) == mesh - 1 % x equals end
Node_info(i, 1) = 1;
end
if Node_info(i, 3) == 0 % y값 0
Node_info(i, 1) = 1;
end
if Node_info(i, 3) == mesh - 1 % y equals end
Node_info(i, 1) = 1;
end
if Node_info(i, 4) == 0 % z equals 0
Node_info(i, 1) = 3;
end
if Node_info(i, 4) == mesh % z equals end
Node_info(i, 1) = 4;
end
end
%% Count node types
n_type_0 = 0; % normal
n_type_1 = 0; % BC
n_type_3 = 0; % BC (floor)
n_type_4 = 0; % surface
for i = 1 : N_node_go
if Node_info(i, 1) == 0
n_type_0 = n_type_0 + 1;
end
if Node_info(i, 1) == 1
n_type_1 = n_type_1 + 1;
end
if Node_info(i, 1) == 3
n_type_3 = n_type_3 + 1;
end
if Node_info(i, 1) == 4
n_type_4 = n_type_4 + 1;
end
end
%% Deciding adjacent nodes
for i = 1 : N_node_go
for j = 1 : N_node_go
% x axis direction adjacent (2 nodes)
if Node_info(j, 3) == Node_info(i, 3) % same x
if Node_info(j, 4) == Node_info(i, 4) % same z
if Node_info(j, 2) == Node_info(i, 2) - 1 % x direction -1
Node_info(i, 5) = j;
elseif Node_info(i, 2) - 1 < 0
Node_info(i, 5) = N_node_go + 2 + 1;
end
if Node_info(j, 2) == Node_info(i, 2) + 1 % x direction +1
Node_info(i, 6) = j;
elseif Node_info(i, 2) + 1 > mesh - 1
Node_info(i, 6) = N_node_go + 2 + 1;
end
end
end
% y axis direction adjacent (2 nodes)
if Node_info(j, 2) == Node_info(i, 2) % same x
if Node_info(j, 4) == Node_info(i, 4) % same z
if Node_info(j, 3) == Node_info(i, 3) - 1 % y direction -1
Node_info(i, 7) = j;
elseif Node_info(i, 3) - 1 < 0
Node_info(i, 7) = N_node_go + 2 + 1;
end
if Node_info(j, 3) == Node_info(i, 3) + 1 % y direction +1
Node_info(i, 8) = j;
elseif Node_info(i, 3) + 1 > mesh - 1
Node_info(i, 8) = N_node_go + 2 + 1;
end
end
end
% z axis direction adjacent (2 nodes)
if Node_info(j, 2) == Node_info(i, 2) % same x
if Node_info(j, 3) == Node_info(i, 3) % same y
if Node_info(j, 4) == Node_info(i, 4) - 1 % z direction -1
Node_info(i, 9) = j;
elseif Node_info(i, 4) - 1 < 0
Node_info(i, 9) = N_node_go + 2 + 1;
end
if Node_info(j, 4) == Node_info(i, 4) + 1 % z direction +1
Node_info(i, 10) = j;
elseif Node_info(i, 4) + 1 > mesh
Node_info(i, 10) = N_node_go + 2 + 1;
end
end
end
end
end
clearvars x;
clearvars y;
clearvars z;
%% Making of M matrix
% M
for i = 1 : N_node_go
if Node_info(i, 1) == 4
M(i, i) = m / 2;
else
M(i, i) = m;
end
end
%% Making of S matrix
clearvars x;
clearvars y;
x = zeros(2, 1); % cond
y = zeros(2, 1); % conv
z = zeros(2, 1); % longwave
for i = 1 : N_node_go
x(1, 1) = i;
%%% ground nodes, only conduction
if Node_info(i, 1) ~= 4
for j = 5 : 10
x(2, 1) = Node_info(i, j);
for g = 1 : 2; h = 1 : 2;
S(x(g,1), x(h,1)) = S(x(g,1), x(h,1)) + S_cond(g,h);
end
end
%%% surface nodes
elseif Node_info(i, 1) == 4
% add **conduction between surface nodes and 5 other adjacent nodes
for j = 5 : 9
x(2, 1) = Node_info(i, j);
for n1 = 1 : 2; n2 = 1 : 2;
S(x(n1,1), x(n2,1)) = S(x(n1,1), x(n2,1)) + S_cond(n1, n2);
end
end
% add **convection between surface nodes and T_out
y(1, 1) = i;
y(2, 1) = N_node_go + 1;
for n3 = 1 : 2; n4 = 1 : 2;
S(y(n3,1), y(n4,1)) = S(y(n3,1), y(n4,1)) + S_conv(n3, n4);
end
% add **longwave radiation between surface nodes and T_sky
z(1, 1) = i;
z(2, 1) = N_node_go + 2;
for n5 = 1 : 2; n6 = 1 : 2;
S(z(n5,1), z(n6,1)) = S(z(n5,1), z(n6,1)) + S_rad(n5, n6);
end
%%% building nodes (excepted in this code)
elseif Node_info(i, 1) == 2
for j = 5 : 9
x(2, 1) = Node_info(i, j);
for n1 = 1 : 2; n2 = 1 : 2;
S(x(n1,1), x(n2,1)) = S(x(n1,1), x(n2,1)) + S_cond(n1, n2);
end
end
y(2, 1) = i;
y(2, 2) = floor_node;
for n1 = 1 : 2; n2 = 1 : 2;
S(y(n1,1), y(n2,1)) = S(y(n1,1), y(n2,1)) + S_cond(n1, n2);
end
end
end
%%
clearvars n1; clearvars n2; clearvars n3;
clearvars n4; clearvars n5; clearvars n6;
clearvars x; clearvars y; clearvars z;
clearvars g; clearvars h;
clearvars j; clearvars i;
%% delete the tail of S matrix
S_convert = zeros(N_node_all, N_node_all);
S_convert = S(1 : end - 1, 1 : end - 1);
clearvars S;
S = S_convert;
clearvars S_convert;
%% Boundary conditions
for i = 1 : N_node_go
if Node_info(i, 1) == 3
M(i, :) = 0;
S(i, :) = 0;
S(i, i) = 1;
elseif Node_info(i, 1) == 1
M(i, :) = 0;
S(i, :) = 0;
S(i, i) = 1;
end
end
M(N_node_go + 1 : N_node_all, :) = 0;
S(N_node_go + 1 : N_node_all, :) = 0;
S(N_node_go + 1 : N_node_all, N_node_go + 1 : N_node_all) = 1;
%% Load Tdepth.xlsx
% load('update_initial_condition.mat')
T_depth = xlsread('Tdepth.xlsx');
%% Making of f matrix
f(N_node_go + 2, 1) = 1;
for i = 1 : N_node_go
if Node_info(i, 1) ~= 0
if Node_info(i, 1) ~= 4
f(i, 1) = T_depth(2 * Node_info(i, 4) + 1, 2);
end
end
end
%% Set initial Temperature
T_00 = 25 * ones(N_node_all, 1);
% for i = 1 : N_node_go
% T_00(i, 1) = T_depth(2 * Node_info(i, 4) + 1, 2);
% end
% T_00(N_node_go + 1, 1) = 25;
% T_00(N_node_go + 2, 1) = 1;
%
% T_all = zeros(N_weather, 3 + N_node_all);
% T_all(:, 1:3) = weather(:, 1:3);
%% solve ODE
disp('solving ODE')
tspan = [0 : 1];
for i = 1 : N_weather
%%% f update
f(N_node_go + 1, 1) = weather(i, 4);
%%% update bc nodes
%%%
for j = 1 : N_node_go
if Node_info(j, 1) == 4 % for surface nodes
f(j, 1) = soil_solar_absorptance * meshsize * meshsize * weather(i, 9);
end
end
[t,T]=unsteady(tspan, T_00, M, S, f);
T_00 = T(end, :);
T_all(i, 4:N_node_g2 + N_node + 3) = T_00;
if i == round(N_weather * 1/10)
disp('ODE is 10% solved ...')
end
if i == round(N_weather * 1/5)
disp('ODE is 20% solved ...')
end
if i == round(N_weather * 3/10)
disp('ODE is 30% solved ...')
end
if i == round(N_weather * 2/5)
disp('ODE is 40% solved ...')
end
if i == round(N_weather * 5/10)
disp('ODE is 50% solved ...')
end
if i == round(N_weather * 3/5)
disp('ODE is 60% solved ...')
end
if i == round(N_weather * 7/10)
disp('ODE is 70% solved ...')
end
if i == round(N_weather * 4/5)
disp('ODE is 80% solved ...')
end
if i == round(N_weather * 9/10)
disp('ODE is 90% solved ...')
end
if i == round(N_weather * 5/5)
disp('ODE is 100% solved ...')
end
end
%% save result
save center_temp.mat