-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththermal.m
181 lines (147 loc) · 5.64 KB
/
thermal.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
function thermal()
%% iron bar
specificHeatBar = 475 ; %specific heat in joules per kg kelvin
densityBar = 7850; %density in kg per meter cubed
%% size in contact with liquid
lengthBar = 5/100 ;%length of bar in meters
diameterBar = 4/100 ;%length of side of bar in meters
volumeBar = pi*(diameterBar/2)^2*lengthBar; %volume
surfaceAreaBar = pi * diameterBar * lengthBar + pi * (diameterBar/2)^2;
massOfBar = densityBar * volumeBar;
%% size of mug
diameterCider = 8/100; %meters
heatOfVaporization = 2256*10^3; %J/kG
heightCider = 10/100;
thicknessMug = 0.7/100;
%% steam surface area
thicknessSteam = 1/100;
steamSA = (lengthBar + thicknessSteam) * (pi * (diameterBar + 2 * thicknessSteam)) + 2 * pi * (diameterBar/2 + thicknessSteam)^2;
thermalConductivityMug =1.5; %W/(m*K)
specificHeatSteam = 1865;%%specific heat in joules per kg kelvin
specificHeatLiquid = 4186;%specific heat in joules per kg kelvin
densityOfSteam = 0.590; %kg/m^3
volumeSteam = steamSA * thicknessSteam;
massOfSteam = volumeSteam * densityOfSteam;
barSteamTransferCoefficient = 50; %this is shit
barTemp = 1500;
liquidDensity = 1000;
liquidTemp = 290;
liquidVolume = (pi * (diameterCider/2)^2) * heightCider - (volumeBar + volumeSteam);
liquidMass = liquidVolume * liquidDensity;
barEnergy = temperatureToEnergy(barTemp, massOfBar, specificHeatBar);
liquidEnergy = temperatureToEnergy(liquidTemp, liquidMass, specificHeatLiquid);
%% time settings
initialTime = 0;
finalTime = 5000;
emissivityCoefficient = .25; %lol magic space rays
thermalConductivitySteam = .00185;
%% params
params(1) = massOfBar;
params(2) = surfaceAreaBar;
params(3) = barEnergy;
params(4) = emissivityCoefficient;
params(5) = specificHeatBar;
params(6) = barSteamTransferCoefficient;
params(7) = thermalConductivityMug;
params(8) = thicknessMug;
params(9) = heatOfVaporization;
params(10) = liquidEnergy;
params(11) = liquidMass;
params(12) = 0;% was liquidVolume
params(13) = specificHeatLiquid;
params(14) = thermalConductivitySteam;
params(15) = thicknessSteam;
params(16) = steamSA;
%% main
<<<<<<< HEAD
tspan = 0:1:finalTime;
[T, Y] = ode23(@netFlow, tspan, params.');
T = T.';
Y = Y.';
=======
%used ode45
%use for loop
% T = zeros(1, 1000);
% Y = zeros(1, 1000);
% for n = 1:1000
% temp = barToLiquid(6969, params.');
% params = params + temp.';
% T(n) = n;
% Y(n) = energyToTemperature(params(10), params(11), params(13));
% deltaEnergy = params(10) - temperatureToEnergy(373, params(11), params(13)); %energy differency between liquid and boiling point, for phase change
% temp2 = [0 0];
% if(deltaEnergy > 0)
% temp2 = phaseChange(deltaEnergy, params);
% % display(temp2);
% end
% params(10) = params(10) - temp2(1);
% params(11) = params(11) - temp2(2);
% end
% plot(T,Y);
%% commented out code
[T, Y] = ode45(@barToLiquid, [initialTime, 10000], params.');
T = T.';
Y = Y.';
>>>>>>> shit
blah = zeros(1, length(T));
for n = 1:length(T)
blah(n) = Y(3, n);
end
<<<<<<< HEAD
plot(T, energyToTemperature(blah, massOfBar, specificHeatBar), 'b-');
=======
plot(T, energyToTemperature(blah, massOfBar, specificHeatBar), 'r+-');
% plot(T, blah, 'b');
>>>>>>> shit
hold on;
blah2 = zeros(1, length(T));
for n = 1:length(T)
blah2(n) = Y(10, n);
end
<<<<<<< HEAD
plot(T, energyToTemperature(blah2, liquidMass, specificHeatLiquid), 'b-');
figure
blah3 = zeros(1, length(T));
for n = 1:length(T)
blah3(n) = Y(11, n);
end
plot(T,blah3);
=======
plot(T, energyToTemperature(blah2, liquidMass, specificHeatLiquid), 'b+-');
% % [T, Y] = ode45(@steamToLiquid, [initialTime, 10], params.'); %works perfectly
% % T = T.';
% % Y = Y.';
% % blah = zeros(1, length(T));
% % for n = 1:length(T)
% % blah(n) = Y(18, n);
% % end
% % plot(T, blah, 'b');
% [T, Y] = ode45(@barToSteam, [initialTime, 10], params.');
% T = T.';
% Y = Y.';
% blah = zeros(1, length(T));
% for n = 1:length(T)
% blah(n) = Y(21, n);
% end
% plot(T, energyToTemperature(blah, massOfBar, specificHeatBar), 'b');
% % plot(T, blah, 'b');
% hold on;
% blah2 = zeros(1, length(T));
% for n = 1:length(T)
% blah2(n) = Y(17, n);
% end
% plot(T, energyToTemperature(blah2, massOfSteam, specificHeatSteam), 'b');
%
% hold on;
>>>>>>> shit
end
%% helpers
function res = energyToTemperature(U, m, c)
res = U / heatCapacity(m,c);
end
function res = temperatureToEnergy( T, m, c)
res = T * heatCapacity(m,c);
end
function res = heatCapacity(mass, specificHeat)
res = mass * specificHeat;
end