-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather_example.py
159 lines (123 loc) · 4.14 KB
/
weather_example.py
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
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from scipy.integrate import odeint
import os
from lookup.iam import kdir
params = {
'lines.linewidth':3,
'font.size': 16,
'savefig.dpi': 150,
}
plt.rcParams.update(params)
# CARNOT parameters
area = 1 # collector surface (m2)
F_ta = 0.507 # F'(tau alfa)
c1 = 0.7153 # heat loss coefficient at (Tm-Ta)=0 [W/(m2*K)]
c2 = 0.00339 # temperature dependent heat loss coefficient [W/(m*K)²]
c5 = 675 # effective thermal capacity [J/(m²K)]
# my parameters
mdot = 80 / 3600 # mass flow rate (L/h to kg/s for water density=1000 kg/m3)
t_in = 280 # water inlet temperature (K)
cp = 4200 # water heat capacity (J/kg*K)
final_time = 30 # final simulation time (s)
def iso_equation(Tm, t):
dTmdt = (F_ta*kdir(az, zen)*dni - c1 * (Tm - t_amb) -
c2 * (Tm - t_amb)**2 - 2 * mdot*cp*(Tm - t_in)/area)/c5
return dTmdt
def iso_equation_modified(Tout, t):
dToutdt = (F_ta*kdir(az, zen)*dni - c1 * (Tout + t_in-2*t_amb) -
c2 * (Tout + t_in - 2*t_amb)**2 - mdot*cp*(Tout - t_in)/area)*2/c5
return dToutdt
def mkdir_if_not_exists(dirname):
if not os.path.exists(dirname):
os.makedirs(dirname)
def plot_temps():
plt.figure(figsize=(12, 4))
plt.subplot(1, 3, 1)
df_all_iso['t_out'].plot(label='ISO')
# df_all_iso_mod['t_out'].plot(label='ISO mod')
# plt.legend()
plt.title('$T_{out}$')
plt.ylabel("$(K)$")
plt.xlabel("time (s)")
plt.subplot(1, 3, 2)
df_all_iso['t_in'].plot(label="$T_{in}$")
df_all_iso['t_amb'].plot(label="$T_{amb}$")
plt.legend()
plt.ylabel("$(K)$")
plt.xlabel("time (s)")
plt.subplot(1, 3, 3)
df_all_iso['delta_t'].plot(label='ISO')
# df_all_iso_mod['delta_t'].plot(label='ISO mod')
# plt.legend()
plt.title('$T_{out} - T_{in}$')
plt.ylabel("$(K)$")
plt.xlabel("time (s)")
plt.tight_layout()
pic_path="plots/weather_example_temps.png"
mkdir_if_not_exists(os.path.dirname(pic_path))
plt.savefig(pic_path)
plt.show()
def plot_power_eff():
plt.figure(figsize=(12, 4))
plt.subplot(1, 3, 1)
df_all_iso['irr'].plot(label='ISO')
plt.title("$DNI$")
plt.ylabel("$(W \cdot m^{-2})$")
plt.xlabel("time (s)")
plt.subplot(1, 3, 2)
df_all_iso['qdot'].plot(label='ISO')
# df_all_iso_mod['qdot'].plot(label='ISO mod')
# plt.legend()
plt.title("$\dot{Q}$")
plt.ylabel("$(W)$")
plt.xlabel("time (s)")
plt.subplot(1, 3, 3)
df_all_iso['eff'].plot(label='ISO')
# df_all_iso_mod['eff'].plot(label='ISO mod')
# plt.legend()
plt.title("$n$")
plt.xlabel("time (s)")
plt.tight_layout()
pic_path="plots/weather_example_power_eff.png"
mkdir_if_not_exists(os.path.dirname(pic_path))
plt.savefig(pic_path)
plt.show()
def calc_qdot(df):
df['qdot'] = mdot * cp * (df['t_out'] - df['t_in']) / area
def calc_eff(df):
df['eff'] = df['qdot'] / df['irr']
def calc_delta(df):
df['delta_t'] = df['t_out'] / df['t_in']
df = pd.read_csv("input/2016_weather_upat.dat", sep="\t",
usecols=["az", "zen", "T", "dni"], nrows=560)
df = df.loc[(df['zen'] < 90) & (df["T"] > -10)]
df['az'] = abs(df['az'])
df['T'] = df['T'] + 273
df.reset_index(drop=True, inplace=True)
df = df[150:155] # select rows with DNI about 800 W
iso_list = []
iso_mod_list = []
for index, row in df.iterrows():
zen, az, dni, t_amb = row.tolist()
t = np.arange(0, final_time)
tm = odeint(iso_equation, t_in, t)
t_out = 2*tm - t_in
t_out_mod = odeint(iso_equation_modified, t_in, t)
iso = pd.DataFrame(data={"time": t, "irr": dni, "t_in": t_in,
"t_amb": t_amb, "t_out": t_out.flatten()})
iso_mod = iso.copy()
iso_mod["t_out"] = t_out_mod
iso_list.append(iso)
iso_mod_list.append(iso_mod)
df_all_iso = pd.concat(iso_list, ignore_index=True)
df_all_iso_mod = pd.concat(iso_mod_list, ignore_index=True)
calc_qdot(df_all_iso)
calc_eff(df_all_iso)
calc_delta(df_all_iso)
calc_qdot(df_all_iso_mod)
calc_eff(df_all_iso_mod)
calc_delta(df_all_iso_mod)
plot_temps()
plot_power_eff()