@@ -178,9 +178,6 @@ def update(self, values, check_conflict=False, path=""):
178
178
).to_numpy ()
179
179
# Save name and data
180
180
super ().__setitem__ (name , (function_name , data ))
181
- # Special case (hacky) for zero current
182
- elif value == "[zero]" :
183
- super ().__setitem__ (name , 0 )
184
181
# Anything else should be a converted to a float
185
182
else :
186
183
super ().__setitem__ (name , float (value ))
@@ -190,19 +187,18 @@ def update(self, values, check_conflict=False, path=""):
190
187
self ._processed_symbols = {}
191
188
192
189
def check_and_update_parameter_values (self , values ):
193
- # Make sure "C-rate" and current are both non-zero
194
- if "C-rate " in values and values ["C-rate " ] == 0 :
190
+ # Make typical current is non-zero
191
+ if "Typical current [A] " in values and values ["Typical current [A] " ] == 0 :
195
192
raise ValueError (
196
193
"""
197
- "C-rate " cannot be zero. A possible alternative is to set
198
- "Current function" to `0` instead.
194
+ "Typical current [A] " cannot be zero. A possible alternative is to set
195
+ "Current function [A] " to `0` instead.
199
196
"""
200
197
)
201
- if "Typical current [A] " in values and values [ "Typical current [A]"] == 0 :
198
+ if "C-rate " in values and "Current function [A]" in values :
202
199
raise ValueError (
203
200
"""
204
- "Typical current [A]" cannot be zero. A possible alternative is to set
205
- "Current function" to `0` instead.
201
+ Cannot provide both "C-rate" and "Current function [A]" simultaneously
206
202
"""
207
203
)
208
204
# If the capacity of the cell has been provided, make sure "C-rate" and current
@@ -214,30 +210,22 @@ def check_and_update_parameter_values(self, values):
214
210
else :
215
211
capacity = self ["Cell capacity [A.h]" ]
216
212
# Make sure they match if both provided
217
- if "C-rate" in values and "Typical current [A]" in values :
218
- if values ["C-rate" ] * capacity != values ["Typical current [A]" ]:
219
- raise ValueError (
220
- """
221
- "C-rate" ({}C) and Typical current ({} A) provided do not match
222
- given capacity ({} Ah). These can be updated individually
223
- instead.
224
- """ .format (
225
- values ["C-rate" ], values ["Typical current [A]" ], capacity
226
- )
227
- )
228
213
# Update the other if only one provided
229
- elif "C-rate" in values :
230
- values ["Typical current [A]" ] = float (values ["C-rate" ]) * capacity
231
- elif "Typical current [A]" in values :
232
- values ["C-rate" ] = float (values ["Typical current [A]" ]) / capacity
233
-
234
- # Update the current function if it is constant
235
- self_and_values = {** self , ** values }
236
- if "Current function" in self_and_values and (
237
- self_and_values ["Current function" ] == "[constant]"
238
- or isinstance (self_and_values ["Current function" ], numbers .Number )
239
- ):
240
- values ["Current function" ] = {** self , ** values }["Typical current [A]" ]
214
+ if "C-rate" in values :
215
+ # Can't provide C-rate as a function
216
+ if callable (values ["C-rate" ]):
217
+ values ["Current function [A]" ] = CrateToCurrent (
218
+ values ["C-rate" ], capacity
219
+ )
220
+ else :
221
+ values ["Current function [A]" ] = float (values ["C-rate" ]) * capacity
222
+ elif "Current function [A]" in values :
223
+ if callable (values ["Current function [A]" ]):
224
+ values ["C-rate" ] = CurrentToCrate (
225
+ values ["Current function [A]" ], capacity
226
+ )
227
+ else :
228
+ values ["C-rate" ] = float (values ["Current function [A]" ]) / capacity
241
229
242
230
return values
243
231
@@ -546,3 +534,23 @@ def evaluate(self, symbol):
546
534
return processed_symbol .evaluate ()
547
535
else :
548
536
raise ValueError ("symbol must evaluate to a constant scalar" )
537
+
538
+
539
+ class CurrentToCrate :
540
+ "Convert a current function to a C-rate function"
541
+ def __init__ (self , function , capacity ):
542
+ self .function = function
543
+ self .capacity = capacity
544
+
545
+ def __call__ (self , t ):
546
+ return self .function (t ) / self .capacity
547
+
548
+
549
+ class CrateToCurrent :
550
+ "Convert a C-rate function to a current function"
551
+ def __init__ (self , function , capacity ):
552
+ self .function = function
553
+ self .capacity = capacity
554
+
555
+ def __call__ (self , t ):
556
+ return self .function (t ) * self .capacity
0 commit comments