forked from decaluwe/1D-SEI-Model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SEI_prelim_functions.py
116 lines (97 loc) · 4.86 KB
/
SEI_prelim_functions.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
# -*- coding: utf-8 -*-
"""
Created on Thu May 17 18:49:06 2018
@author: Daniel Korff
This code takes in an empty solution vector for tracking temperature,
concentration, and potential of 2 species based on the grid used in the top
level script and updates the column headers to reflect the data stored in the
respective columns.
"""
# %% The function below will apply column labels to the data frame sol_vec
def df_2spec2var(sol_vec,N_x,N_y,len_sol_vec,track_vars,track_temp,num_species):
# Initialize base strings
temp_tag = ["T_" for i in range(N_x*N_y)]
V_elyte_tag = ["V_elyte_" for i in range(N_x*N_y)]
V_sei_an_tag = ["V_sei_an_" for i in range(N_x*N_y)]
V_sei_elyte_tag = ["V_sei_elyte_" for i in range(N_x*N_y)]
phi_tag = ["phi_" for i in range(N_x*N_y)]
c_elyte_tag = {}
c_SEI_tag = {}
for i in range(num_species[0]):
c_elyte_tag[str(i+1)] = ["c_elyte"+str(i+1)+"_" for j in range(N_x*N_y)]
for i in range(num_species[1]):
c_SEI_tag[str(i+1)] = ["c_SEI"+str(i+1)+"_" for j in range(N_x*N_y)]
# concatenate appropriate indices onto base strings
for j in range(N_y):
for i in range(N_x):
temp_tag[i+j*N_x] = temp_tag[i+j*N_x]+str(j)
V_elyte_tag[i+j*N_x] = V_elyte_tag[i+j*N_x]+str(j)
V_sei_an_tag[i+j*N_x] = V_sei_an_tag[i+j*N_x]+str(j)
V_sei_elyte_tag[i+j*N_x] = V_sei_elyte_tag[i+j*N_x]+str(j)
for key in c_elyte_tag:
c_elyte_tag[key][i+j*N_x] = c_elyte_tag[key][i+j*N_x]+str(j)
c_elyte_tag[key][i+j*N_x] = c_elyte_tag[key][i+j*N_x]+str(i)
for key in c_SEI_tag:
c_SEI_tag[key][i+j*N_x] = c_SEI_tag[key][i+j*N_x]+str(j)
c_SEI_tag[key][i+j*N_x] = c_SEI_tag[key][i+j*N_x]+str(i)
phi_tag[i+j*N_x] = phi_tag[i+j*N_x]+str(j)
temp_tag[i+j*N_x] = temp_tag[i+j*N_x]+str(i)
V_elyte_tag[i+j*N_x] = V_elyte_tag[i+j*N_x]+str(i)
V_sei_an_tag[i+j*N_x] = V_sei_an_tag[i+j*N_x]+str(i)
V_sei_elyte_tag[i+j*N_x] = V_sei_elyte_tag[i+j*N_x]+str(i)
phi_tag[i+j*N_x] = phi_tag[i+j*N_x]+str(i)
# Determine columns where each variable is being stored
V_ctr = track_temp + 0
elyte_species_ctr = track_temp + 3
SEI_species_ctr = elyte_species_ctr + num_species[0]
phi_ctr = SEI_species_ctr + num_species[1]
c_elyte_cols = [0 for i in range(num_species[0])]
c_SEI_cols = [0 for i in range(num_species[1])]
temp_cols = list(range(0, len_sol_vec, track_vars))
V_elyte_cols = list(range(V_ctr, len_sol_vec, track_vars))
V_sei_an_cols = list(range(V_ctr+1, len_sol_vec, track_vars))
V_sei_elyte_cols = list(range(V_ctr+2, len_sol_vec, track_vars))
for i in range(num_species[0]):
c_elyte_cols[i] = list(range(elyte_species_ctr+i, len_sol_vec, track_vars))
for i in range(num_species[1]):
c_SEI_cols[i] = list(range(SEI_species_ctr+i, len_sol_vec, track_vars))
phi_cols = list(range(phi_ctr, len_sol_vec, track_vars))
# Loop over all columns updating column names to appropriate var label
count = 0
for i in range(N_x*N_y):
if track_temp == 1:
sol_vec = sol_vec.rename(columns = \
{temp_cols[i]:temp_tag[count]})
sol_vec = sol_vec.rename(columns = \
{V_elyte_cols[i]:V_elyte_tag[count]})
sol_vec = sol_vec.rename(columns = \
{V_sei_an_cols[i]:V_sei_an_tag[count]})
sol_vec = sol_vec.rename(columns = \
{V_sei_elyte_cols[i]:V_sei_elyte_tag[count]})
j = 0
for key in c_elyte_tag:
sol_vec = sol_vec.rename(columns = \
{c_elyte_cols[j][i]:c_elyte_tag[key][count]})
j += 1
j = 0
for key in c_SEI_tag:
sol_vec = sol_vec.rename(columns = \
{c_SEI_cols[j][i]:c_SEI_tag[key][count]})
j += 1
sol_vec = sol_vec.rename(columns = \
{phi_cols[i]:phi_tag[count]})
count += 1
# Return cleaned up solution vector to top level script
return sol_vec
# %% The following function applies boundary conditions to sol_vec
def IC_fun(sol_vec, IC_vec, len_sol_vec, track_vars, track_temp):
if track_temp == 1:
for i in range(track_vars):
for j in range(i, len_sol_vec, track_vars):
sol_vec[0, j] = IC_vec[i]
elif track_temp == 0:
for i in range(track_vars):
for j in range(i, len_sol_vec, track_vars):
sol_vec[0, j] = IC_vec[i+1]
return sol_vec
#-----------------------------------------------------------------------------