-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-functions.c
222 lines (171 loc) · 5.09 KB
/
update-functions.c
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
#include <stdlib.h>
#include "fd-solver.h"
#include "can.h"
double h = 0;
// Yay for meeting deadlines!
void seth(double x)
{
h = x;
printh();
return;
}
void printh()
{
printf("h = %g\n", h);
return;
}
double UpdateTest(struct Node1D *node, int Var)
{
int t = Var; // Get rid of the annoying warning about not using "Var"
t = node->TimeIndex;
/* t is t */
return (double) t;
}
/* Heat conduction in a slab */
double UpdateSubdomain(struct Node1D *node, int Var)
{
double T, Ta, Tb, Tc;
int t = node->TimeIndex;
double Cond, Dens, Cap, alpha, M;
Ta = node->Prev->Value[Var][t];
Tb = node->Value[Var][t];
Tc = node->Next->Value[Var][t];
/* Calculate the thermal properties based on the temperature of the node at
the pervious time step. */
Cond = k(Tb); //0.5985; // W/(m K)
Dens = rho(Tb); //1000; // kg/m^3
Cap = Cp(Tb); //1865; // J/(kg K)
alpha = Cond/(Dens*Cap);
M = (node->dx)*(node->dx)/(alpha*node->dt);
T = 1/M * (Ta + (M-2)*Tb + Tc);
return T;
}
/* Heat conduction in a cylinder */
double UpdateSubdomainCyl(struct Node1D *node, int Var)
{
double T, Ta, Tb, Tc;
int t = node->TimeIndex;
double n = node->NodeNum; // Node number where n=0 at the center
double Cond, Dens, Cap, alpha, M;
Ta = node->Prev->Value[Var][t];
Tb = node->Value[Var][t];
Tc = node->Next->Value[Var][t];
/* Calculate the thermal properties based on the temperature of the node at
the pervious time step. */
Cond = k(Tb); //0.5985; // W/(m K)
Dens = rho(Tb); //1000; // kg/m^3
Cap = Cp(Tb); //1865; // J/(kg K)
alpha = Cond/(Dens*Cap);
M = (node->dx)*(node->dx)/(alpha*node->dt);
T = 1/M * ( (2*n+1)/(2*n) * Tc + (M-2) * Tb + (2*n-1)/(2*n) * Ta );
return T;
}
double UpdateSubdomainRxn1(struct Node1D *node, int Var)
{
double k; /* Rate Constant */
double T;
int t = node->TimeIndex;
double dt = node->dt;
double c = node->Value[Var][t];
T = NodeGetValue(node, 'T', t);
k = reaction_rate1(T, c);
return c * (1-k*dt);
}
double UpdateSubdomainRxn2(struct Node1D *node, int Var)
{
double k; /* Rate Constant */
double T;
int t = node->TimeIndex;
double dt = node->dt;
double c = node->Value[Var][t];
T = NodeGetValue(node, 'T', t);
k = reaction_rate2(T, c);
return c * (1-k*dt);
}
double UpdateConvectiveBoundary(struct Node1D *node, int Var)
{
double T, Text, Ta, Tb;
int t = node->TimeIndex;
double Cond, Dens, Cap, alpha, M, N;
//double h;
Tb = node->Value[Var][t];
Text = T_ext(t*node->dt);
/* Figure out which side the boundary is on */
if(node->Next == NULL)
Ta = node->Prev->Value[Var][t];
else
Ta = node->Next->Value[Var][t];
//h = 3000; //W/(m^2 K)
//h = find_val("HConv", node->varlst);
printf("%g\n", h);
Cond = k(Tb); //0.5985; // W/(m K)
Dens = rho(Tb); //1000; // kg/m^3
Cap = Cp(Tb); //1865; // J/(kg K)
alpha = Cond/(Dens*Cap);
M = (node->dx)*(node->dx)/(alpha*node->dt);
N = h*node->dx/Cond;
T = 1/M * (2*N*Text + (M-(2*N+2))*Tb + 2*Ta);
return T;
}
double UpdateInsulatedBoundary(struct Node1D *node, int Var)
{
double T, Ta, Tb;
int t = node->TimeIndex;
double Cond, Dens, Cap, alpha, M;
Tb = node->Value[Var][t];
if(node->Next == NULL)
Ta = node->Prev->Value[Var][t];
else
Ta = node->Next->Value[Var][t];
Cond = k(Tb); //0.5985; // W/(m K)
Dens = rho(Tb); //1000; // kg/m^3
Cap = Cp(Tb); //1865; // J/(kg K)
alpha = Cond/(Dens*Cap);
M = (node->dx)*(node->dx)/(alpha*node->dt);
T = 1/M * ((M-2)*Tb + 2*Ta);
return T;
}
double UpdateRadialSymmetryBoundary(struct Node1D *node, int Var)
{
int t = node->TimeIndex;
double Ta, Tb, T, Cond, Dens, Cap, alpha, M;
Tb = node->Value[Var][t];
if(node->Next == NULL)
Ta = node->Prev->Value[Var][t];
else
Ta = node->Next->Value[Var][t];
/* Calculate the thermal properties based on the temperature of the node at
the pervious time step. */
Cond = k(Tb); //0.5985; // W/(m K)
Dens = rho(Tb); //1000; // kg/m^3
Cap = Cp(Tb); //1865; // J/(kg K)
alpha = Cond/(Dens*Cap);
M = (node->dx)*(node->dx)/(alpha*node->dt);
T = 4/M * Ta + (M-4)/M * Tb;
return T;
}
double UpdateConvectiveBoundaryCyl(struct Node1D *node, int Var)
{
double T, Text, Ta, Tb;
int t = node->TimeIndex;
int n = node->NodeNum;
double Cond, Dens, Cap, alpha, M, N;
//double h;
Tb = node->Value[Var][t];
Text = T_ext(t*node->dt);
/* Figure out which side the boundary is on */
if(node->Next == NULL)
Ta = node->Prev->Value[Var][t];
else
Ta = node->Next->Value[Var][t];
//h = 3000; //W/(m^2 K)
//h = find_val("HConv", node->varlst);
Cond = k(Tb); //0.5985; // W/(m K)
Dens = rho(Tb); //1000; // kg/m^3
Cap = Cp(Tb); //1865; // J/(kg K)
alpha = Cond/(Dens*Cap);
M = (node->dx)*(node->dx)/(alpha*node->dt);
N = h*node->dx/Cond;
T = n*N/((2*n-1)/2 + n*N) * Text + (2*n-1)/2/((2*n-1)/2 + n*N) * Ta;
return T;
}