forked from Battery-Intelligence-Lab/SLIDE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readAgeing_cyclingData.m
139 lines (118 loc) · 5.79 KB
/
readAgeing_cyclingData.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
% Script to read and plot the cycling data from the degradation simulation.
% The cycling data contains the current, voltage and temperature of the
% cell at a fixed time interval.
% If 'proc.includeCycleData' in the degradation function in Degradation.cpp
% is true, the cycling data contains both the periods from the actual
% degradation experiment, and from the check-ups.
% If 'proc.includeCycleData' in the degradation function in Degradation.cpp
% is false, the cycling data contains only the periods from the actual
% degradation experiment.
%
% This script should not be executed on its own, but is called by one of
% three higher-level scripts:
% readCalendarAgeing
% readCycleAgeing
% readProfileAgeing
%
%
% Copyright (c) 2019, The Chancellor, Masters and Scholars of the University
% of Oxford, VITO nv, and the 'Slide' Developers.
% See the licence file LICENCE.txt for more information.
fileName = 'CyclingData'; % Name of the file which contains the cycling data
%% Read the csv files & plot the cycling data
% Note we read and plot in one loop because this avoids you have to store
% all the cyling data from all simulations first (and then plot all of it).
% The cycling data can be very large (many GigaBytes) so we want to
% minimise the memory requirements.
% A loop to read & plot the files of each ageing regime
for i=1:length(IDs)
fol = strcat(pref,'_',ageingID,'_',IDs{i}); % Folder in which to find the file
fi = dir (fol); % list the files in the subfolder
A = [];
% Check that the folder exist and has data files
if length(fi)<1
warning(['warning no files exist in folder ' fol])
A = nan(1,15);
end
% A loop to read each cycling data batch from this ageing regime
for jj = 1:length(fi) % loop through all files from this folder
ni = fi(jj).name;
if contains(ni,fileName) % check if it is a file with cyclingData, i.e. if the name contains 'cyclingData'
% older versions of Matlab don't have the 'contains' command. In
% that case, use strfind. Replace 'if contains(ni,fileName)' with
% 'if strfind(ni,fileName)'
% Read the file
na = fullfile(fol,ni); % Full name of the file
try
Ai = csvread(na);
catch
Ai = nan(1,15); % If we can't read the file, print a warning to the user, and fill the data with NaNs
warning(['warning no file ' na ' could be found'])
end
% Add up the cumulative variables (e.g. total time, total charge
% throughput, etc.). In the C++ code, they are reset to 0 after a
% data batch is written, so here we need to add them up to insert
% the new data batch 'after' the previous one.
% These cumulative variables are in columns 1-3,9-15
cumulative = [1:3 9:15];
if ~isempty(A)
Ai(:,cumulative) = Ai(:,cumulative) + A(end,cumulative);
end
% Append the new data behind the old data
A = [A ; Ai];
end
end
% Store the data in a struct
capini = state{i}.cap(1); % initial capacity of this cell [Ah] (from readAgeing_BatteryState)
cycdat.timetot = A(:,1); % total time since the start [s]
cycdat.Ahtot = A(:,2); % total charge throughput
cycdat.Whtot = A(:,3); % total energy throughput
cycdat.I = A(:,4); % current, < 0 for charge [A]
cycdat.V = A(:,5); % cell voltage [V]
cycdat.OCVp = A(:,6); % cathode potential [V]
cycdat.OCVn = A(:,7); % anode potential [V]
cycdat.T = A(:,8); % cell temperature [K]
cycdat.timeCha = A(:,9); % time spent on charging [s]
cycdat.AhCha = A(:,10); % charged charge [Ah]
cycdat.WhCha = A(:,11); % charged energy [Wh]
cycdat.timeDis = A(:,12); % time spent on discharging [s]
cycdat.AhDis = A(:,13); % discharged charge [Ah]
cycdat.WhDis = A(:,14); % discharged energy [Wh]
cycdat.timeRest = A(:,15); % time spent on rest [s]
cycdat.FEC = cycdat.Ahtot / (2*capini); % cumulative full equivalent cycles [-]
clear('A', 'Ai'); % clear the matrix to free up memory
% Plot the current, voltage and temperature
figure()
subplot(2,1,1)
yyaxis left
if FECx
plot(cycdat.FEC,cycdat.I)
xlabel('full equivalent cycles [-]');
else
plot(cycdat.timetot/3600,cycdat.I)
xlabel('time [hour]')
end
ylabel('[A]')
yyaxis right
if FECx
plot(cycdat.FEC,cycdat.V)
xlabel('full equivalent cycles [-]');
else
plot(cycdat.timetot/3600,cycdat.V)
xlabel('time [hour]')
end
ylabel('[V]')
legend('current','voltage')
title(strcat('cell current and voltage of ', IDs{i}))
subplot(2,1,2)
if FECx
plot(cycdat.FEC,cycdat.T-273)
xlabel('full equivalent cycles [-]');
else
plot(cycdat.timetot/3600,cycdat.T-273)
xlabel('time [hour]')
end
ylabel('[degrees]')
title(strcat('cell temperature of ', IDs{i}))
clear('cycdat'); % clear the struct with the data to free up memory
end