-
Notifications
You must be signed in to change notification settings - Fork 1
/
thermo_test_suite.py
205 lines (172 loc) · 7.32 KB
/
thermo_test_suite.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
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
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 7 09:18:39 2019
@author: dkorff
"""
import numpy as np
import cantera as ct
from math import pi
from matplotlib import pyplot as plt
from li_s_battery_inputs import inputs
from li_s_battery_init import cathode as cat
"Import cantera objects - this step is the same regardless of test type"
elyte = ct.Solution(inputs.ctifile, inputs.elyte_phase)
sulfur = ct.Solution(inputs.ctifile, inputs.cat_phase1)
Li2S = ct.Solution(inputs.ctifile, inputs.cat_phase2)
carbon = ct.Solution(inputs.ctifile, inputs.cat_phase3)
conductor = ct.Solution(inputs.ctifile, inputs.metal_phase)
sulfur_el_s = ct.Interface(inputs.ctifile, inputs.sulfur_elyte_phase,
[sulfur, elyte, conductor])
Li2S_el_s = ct.Interface(inputs.ctifile, inputs.Li2S_elyte_phase,
[Li2S, elyte, conductor])
carbon_el_s = ct.Interface(inputs.ctifile, inputs.graphite_elyte_phase,
[carbon, elyte, conductor])
Li2S_tpb = ct.Interface(inputs.ctifile, 'tpb', [elyte_obj, Li2S_obj, conductor_obj])
plt.close('all')
N = 100
elyte.electric_potential = SV_dch.iloc[-1, cat.ptr['phi_ed']] - SV_dch.iloc[-1, cat.ptr['phi_dl']]
V_cell = SV_dch.iloc[-1, cat.ptr_vec['phi_ed']]
carbon.electric_potential = V_cell
conductor.electric_potential = V_cell
#carbon_el_s.electric_potential = 2.5
#C_k_0 = np.array([1.023e1,
# 1.023e1,
# 1.024,
# 1.0229,
# 1.943e-2,
# 1.821e-4,
# 3.314e-4,
# 2.046e-5,
# 5.348e-10,
# 8.456e-13])
C_k_0 = SV_dch.iloc[-1, cat.ptr_vec['rho_k_el']].values
C_k_mat = np.zeros([len(C_k_0), N])
C_k_mat[0, :] = np.linspace(C_k_0[0], C_k_0[0], N)
C_k_mat[1, :] = np.linspace(C_k_0[1], C_k_0[1], N)
C_k_mat[2, :] = np.linspace(C_k_0[2], C_k_0[2], N)
C_k_mat[3, :] = np.linspace(C_k_0[3], C_k_0[3], N)
C_k_mat[4, :] = np.linspace(C_k_0[4], 0.001*C_k_0[4], N)
C_k_mat[5, :] = np.linspace(0.001*C_k_0[5], 10*C_k_0[5], N)
C_k_mat[6, :] = np.linspace(0.001*C_k_0[6], 10*C_k_0[6], N)
C_k_mat[7, :] = np.linspace(0.001*C_k_0[7], 100*C_k_0[7], N)
C_k_mat[8, :] = np.linspace(C_k_0[8], 1e5*C_k_0[8], N)
C_k_mat[9, :] = np.linspace(C_k_0[9], 1e4*C_k_0[9], N)
X_range = np.linspace(0, 1, N)
X_0 = elyte.X
X = elyte.X
G_elyte = np.zeros([elyte.n_species, N])
dG_L = np.zeros([elyte.n_species, N])
dG_S = np.zeros([elyte.n_species, N])
dG_C = np.zeros([elyte.n_species, N, carbon_el_s.n_reactions])
dG_global = np.zeros([elyte.n_species, N])
k_f_L = np.zeros([elyte.n_species, N])
k_f_S = np.zeros([elyte.n_species, N])
k_f_C = np.zeros([elyte.n_species, N, carbon_el_s.n_reactions])
labels = ['$S_8(l)$', '$S_8^{2-}$', '$S_6^{2-}$', '$S_4^{2-}$', '$S_2^{2-}$', '$S^{2-}$']
styles = ['o', 'v', 's', '*', 'x', 'd']
for j in np.arange(4, elyte.n_species):
for count in np.arange(0, N):
C_vec = np.copy(C_k_0)
C_vec[j] = C_k_mat[j, count]
elyte.X = C_vec/np.sum(C_vec)
G_elyte[j, count] = elyte.g
dG_L[j, count] = Li2S_el_s.delta_gibbs
dG_S[j, count] = sulfur_el_s.delta_gibbs
dG_C[j, count, :] = carbon_el_s.delta_gibbs
dG_global[j, count] = Li2S.g - sulfur.g
k_f_L[j, count] = Li2S_el_s.net_rates_of_progress
k_f_S[j, count] = sulfur_el_s.net_rates_of_progress
k_f_C[j, count, :] = carbon_el_s.net_rates_of_progress
# print(carbon_el_s.forward_rates_of_progress, '\n', carbon_el_s.reverse_rates_of_progress, '\n\n')
# plt.figure(1)
# plt.plot(C_k_mat[j, :], G_elyte[j, :], label=labels[j-4])
# plt.legend()
# plt.title('Electrolyte Gibbs Free Energy \n as a function of species concentration')
# plt.xlabel(r'$C_k$')
# ax = plt.gca()
# ax.set_xscale('log')
# plt.figure(18)
# plt.plot(C_k_mat[j, :], dG_global[j, :], label=labels[j-4])
# plt.legend()
# plt.title(r'$\Delta G_{global}$ as a function of species concentration')
# plt.xlabel(r'$C_k$')
# ax = plt.gca()
# ax.set_xscale('log')
#plt.figure(2)
#plt.plot(C_k_mat[-1, :], dG_L[-1, :], label=labels[-1])
#plt.title(r'$\Delta G_{rxn}$ at $Li_2S$-Elyte over $S^{2-}$ concentration')
#
#plt.figure(3)
#plt.plot(C_k_mat[4, :], dG_S[4, :], label=labels[0])
#plt.title(r'$\Delta G_{rxn}$ at S-Elyte over $S_8(l)$ concentration')
#
#plt.figure(4)
#plt.plot(C_k_mat[-1, :], k_f_L[-1, :], label=labels[-1])
#plt.title(r'Net rate of progress at $Li_2S$-Elyte over $S^{2-}$ concentration')
#ax = plt.gca()
#ax.set_yscale('log')
#
#plt.figure(5)
#plt.plot(C_k_mat[4, :], k_f_S[4, :], label=labels[0])
#plt.title(r'Net rate of progress at S-Elyte over $S_8(l)$ concentration')
#ax = plt.gca()
#ax.set_yscale('log')
rxn_labels = ['$S_8(l) <-> S_8^{2-}$',
'$S_8^{2-} <-> S_6^{2-}$',
'$S_6^{2-} <-> S_4^{2-}$',
'$S_4^{2-} <-> S_2^{2-}$',
'$S_2^{2-} <-> S^{2-}$']
#for j in np.arange(4, elyte.n_species):
# for k in np.arange(0, carbon_el_s.n_reactions):
# plt.figure(j+2)
# plt.plot(C_k_mat[j, :], dG_C[j, :, k], label=rxn_labels[k])
# plt.title(r'$\Delta G_{rxn}$ at the carbon interface over ' + labels[j-4])
# plt.legend()
rxn_labels = ['$S_8(s) <-> S_8(l)$',
'$S_8(l) <-> S_8^{2-}$',
'$S_8^{2-} <-> S_6^{2-}$',
'$S_6^{2-} <-> S_4^{2-}$',
'$S_4^{2-} <-> S_2^{2-}$',
'$S_2^{2-} <-> S^{2-}$',
'$2 Li^{+} + S^{2-} <-> Li_2S$',
'$Li_2S <-> 2 Li^{+} + 0.5 S_2^{2-}$']
dG = np.zeros([sulfur_el_s.n_reactions+carbon_el_s.n_reactions+Li2S_el_s.n_reactions+Li2S_tpb.n_reactions])
q_f = np.zeros([sulfur_el_s.n_reactions+carbon_el_s.n_reactions+Li2S_el_s.n_reactions+Li2S_tpb.n_reactions])
q_r = np.zeros([sulfur_el_s.n_reactions+carbon_el_s.n_reactions+Li2S_el_s.n_reactions+Li2S_tpb.n_reactions])
C_k = np.copy(C_k_0)
#C_k[-1] = 1e-13
elyte.X = C_k/np.sum(C_k)
q_f[0] = sulfur_el_s.forward_rates_of_progress
q_r[0] = sulfur_el_s.reverse_rates_of_progress
dG[0] = sulfur_el_s.delta_gibbs
q_f[1:carbon_el_s.n_reactions+1] = carbon_el_s.forward_rates_of_progress
q_r[1:carbon_el_s.n_reactions+1] = carbon_el_s.reverse_rates_of_progress
dG[1:carbon_el_s.n_reactions+1] = carbon_el_s.delta_gibbs
q_f[-2] = Li2S_el_s.forward_rates_of_progress
q_r[-2] = Li2S_el_s.reverse_rates_of_progress
dG[-2] = Li2S_el_s.delta_gibbs
q_f[-1] = Li2S_tpb.forward_rates_of_progress
q_r[-1] = Li2S_tpb.reverse_rates_of_progress
dG[-1] = Li2S_tpb.delta_gibbs
x = np.arange(0, len(q_f))
width = 0.25
fig, ax = plt.subplots(figsize=(18,6))
rects1 = ax.bar(x - width/2, q_f, width, label='forward progress')
rects2 = ax.bar(x + width/2, q_r, width, label='reverse progress')
#rects3 = ax.bar(x + 1.5*width, dG, width, label='Delta G')
#fig2, ax2 = plt.subplots()
#rects3 = ax2.bar(x + width, dG, width, color='green', label='$\Delta G$')
ax.legend()
ax.set_xticks(x)
ax.set_xticklabels(rxn_labels)
ax.set_yscale('log')
plt.show()
#for j in np.arange(4, elyte.n_species):
# for k in np.array((0, 1, 2, 3, 4)): #np.arange(0, carbon_el_s.n_reactions):
# plt.figure(j+8)
# plt.plot(C_k_mat[j, :], k_f_C[j, :, k], label=rxn_labels[k])
# plt.title(r'Net rate of progress at the carbon interface over ' + labels[j-4])
# ax = plt.gca()
# ax.set_yscale('log')
# plt.legend()
plt.show()