-
Notifications
You must be signed in to change notification settings - Fork 10
/
ActiveMaterial.m
318 lines (200 loc) · 9.78 KB
/
ActiveMaterial.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
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
classdef ActiveMaterial < BaseModel
properties
%
% instance of :class:`Interface <Electrochemistry.Electrodes.Interface>`
%
%% Sub-Models
Interface
SolidDiffusion
%% Input parameters
% Standard parameters
electronicConductivity % the electronic conductivity of the material (symbol: sigma)
density % the mass density of the material (symbol: rho)
massFraction % the ratio of the mass of the material to the total mass of the phase or mixture (symbol: gamma)
thermalConductivity % the intrinsic Thermal conductivity of the active component
specificHeatCapacity % Specific Heat capacity of the active component
diffusionModelType % either 'full' or 'simple'
% Coupling parameters
externalCouplingTerm % structure to describe external coupling (used in absence of current collector)
end
methods
function model = ActiveMaterial(inputparams)
%
% ``inputparams`` is instance of :class:`ActiveMaterialInputParams <Electrochemistry.ActiveMaterialInputParams>`
%
model = model@BaseModel();
fdnames = {'electronicConductivity', ...
'density' , ...
'massFraction' , ...
'thermalConductivity' , ...
'specificHeatCapacity' , ...
'volumeFraction' , ...
'externalCouplingTerm' , ...
'diffusionModelType' , ...
'isRootSimulationModel'};
model = dispatchParams(model, inputparams, fdnames);
model.Interface = Interface(inputparams.Interface);
diffusionModelType = model.diffusionModelType;
switch model.diffusionModelType
case 'simple'
model.SolidDiffusion = SimplifiedSolidDiffusionModel(inputparams.SolidDiffusion);
case 'full'
model.SolidDiffusion = FullSolidDiffusionModel(inputparams.SolidDiffusion);
otherwise
error('Unknown diffusionModelType %s', diffusionModelType);
end
end
function model = registerVarAndPropfuncNames(model)
%% Declaration of the Dynamical Variables and Function of the model
% (setup of varnameList and propertyFunctionList)
model = registerVarAndPropfuncNames@BaseModel(model);
itf = 'Interface';
sd = 'SolidDiffusion';
varnames = {'T'};
model = model.registerVarNames(varnames);
fn = @ActiveMaterial.dispatchTemperature;
model = model.registerPropFunction({{sd, 'T'}, fn, {'T'}});
model = model.registerPropFunction({{itf, 'T'}, fn, {'T'}});
if model.isRootSimulationModel
varnames = {};
% Volumetric current in A/m^3. It corresponds to the current density multiplied with the volumetric
% surface area.
varnames{end + 1} = 'I';
% Potential at Electrode
varnames{end + 1} = 'E';
% Charge Conservation equation
varnames{end + 1} = 'chargeCons';
model = model.registerVarNames(varnames);
varnames = {{itf, 'dUdT'}, ...
'jCoupling' , ...
'jExternal'};
model = model.removeVarNames(varnames);
varnames = {'T' , ...
{itf, 'cElectrolyte'}, ...
{itf, 'phiElectrolyte'}};
model = model.setAsStaticVarNames(varnames);
end
fn = @ActiveMaterial.updateRvol;
model = model.registerPropFunction({{sd, 'Rvol'}, fn, {{itf, 'R'}}});
fn = @ActiveMaterial.updateConcentrations;
model = model.registerPropFunction({{itf, 'cElectrodeSurface'}, fn, {{sd, 'cSurface'}}});
if model.isRootSimulationModel
fn = @ActiveMaterial.updateControl;
fn = {fn, @(propfunction) PropFunction.drivingForceFuncCallSetupFn(propfunction)};
model = model.registerPropFunction({'I', fn, {}});
fn = @ActiveMaterial.updateChargeCons;
inputnames = {'I', ...
{sd, 'Rvol'}};
model = model.registerPropFunction({'chargeCons', fn, inputnames});
fn = @ActiveMaterial.updatePhi;
model = model.registerPropFunction({{itf, 'phiElectrode'}, fn, {'E'}});
end
end
function model = setupForSimulation(model)
model = model.equipModelForComputation();
itf = 'Interface';
sd = 'SolidDiffusion';
n = model.(itf).numberOfElectronsTransferred; % number of electron transfer (equal to 1 for Lithium)
F = model.(sd).constants.F;
rp = model.(sd).particleRadius;
scalingcoef = 1/(n*F/(4*pi*rp^3/3));
scalings = {{{sd, 'massCons'}, scalingcoef}, ...
{{sd, 'solidDiffusionEq'}, scalingcoef}};
model.scalings = scalings;
end
function forces = getValidDrivingForces(model)
forces = getValidDrivingForces@PhysicalModel(model);
forces.src = [];
end
function state = updateControl(model, state, drivingForces)
state.I = drivingForces.src(state.time);
end
function state = updatePhi(model, state)
itf = 'Interface';
state.(itf).phiElectrode = state.E;
end
function cleanState = addStaticVariables(model, cleanState, state, state0)
cleanState = addStaticVariables@BaseModel(model, cleanState, state);
if model.isRootSimulationModel
itf = 'Interface';
cleanState.T = state.T;
cleanState.(itf).cElectrolyte = state.(itf).cElectrolyte;
cleanState.(itf).phiElectrolyte = state.(itf).phiElectrolyte;
end
end
function state = updateChargeCons(model, state)
% Only used for stand-alone model
sd = 'SolidDiffusion';
itf = 'Interface';
n = model.(itf).numberOfElectronsTransferred;
F = model.(itf).constants.F;
I = state.I;
Rvol = state.(sd).Rvol;
state.chargeCons = I - Rvol*n*F;
end
function model = validateModel(model, varargin)
%
end
%% assembly functions use in this model
function state = updateRvol(model, state)
itf = 'Interface';
sd = 'SolidDiffusion';
vsa = model.(itf).volumetricSurfaceArea;
Rvol = vsa.*state.(itf).R;
state.(sd).Rvol = Rvol;
end
function state = updateConcentrations(model, state)
sd = 'SolidDiffusion';
itf = 'Interface';
state.(itf).cElectrodeSurface = state.(sd).cSurface;
end
function state = dispatchTemperature(model, state)
state.Interface.T = state.T;
state.SolidDiffusion.T = state.T;
end
function state = updateAverageConcentration(model, state)
% shortcut
sd = 'SolidDiffusion';
vf = model.volumeFraction;
am_frac = model.activeMaterialFraction;
vols = model.G.getVolumes();
c = state.(sd).cAverage;
vols = am_frac*vf.*vols;
cAverage = sum(c.*vols)/sum(vols);
state.cAverage = cAverage;
end
end
methods (Static)
function str = varToStr(varname)
str = strjoin(varname, '_');
end
function str = shortenName(name)
namemapping = {'ActiveMaterial' , 'am' ; ...
'ActiveMaterial1' , 'am1' ; ...
'ActiveMaterial2' , 'am2' ; ...
'Interface' , 'itf' ; ...
'SolidDiffusion' , 'sd'};
[found, ind] = ismember(name, namemapping(:, 1));
if found
str = namemapping{ind, 2};
else
str = name;
end
end
end
end
%{
Copyright 2021-2024 SINTEF Industry, Sustainable Energy Technology
and SINTEF Digital, Mathematics & Cybernetics.
This file is part of The Battery Modeling Toolbox BattMo
BattMo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
BattMo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with BattMo. If not, see <http://www.gnu.org/licenses/>.
%}