-
Hi, I have prepared a custom functions for OCV, R0, R1 and C1 which basically convert given SOC into integer and return a value from a predefined table. However, when running the simulation I get the "TypeError: only length-1 arrays can be converted to Python scalars". Debugging shows that at the certain stage of simulation the array (<class 'numpy.ndarray'> [1. 1.]) passed into this function instead of single float value. [IDAHandleFailure, Error: -3] At t = 0 and h = 5.63965e-09, the error test failed repeatedly or with |h| = hmin. Am I missing something? Thanks, Črt |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Thanks for the question. This is a small error in the post-processing step. It doesn't sound like you are doing anything wrong. I will have to patch the code. I have a quick fix that I will work on soon. In the meantime, if you want to try to get your code working try to alter your functions so they can work with either floats or numpy arrays like so: import numpy as np
def ocv(soc):
if isinstance(soc, np.ndarray):
# code here that is compatible with numpy arrays, could be a loop
value = ...
else:
# code here that works with scalars (probably what you already have)
value = ...
return value Here is a minimal example you can use to get started. Let me know if this does not resolve the problem: import numpy as np
import thevenin as thev
def ocv(soc):
if isinstance(soc, np.ndarray):
value = np.empty_like(soc)
for i, s in enumerate(soc):
_ = int(s)
value[i] = 3.
else:
_ = int(soc)
value = 3.
return value
def R0(soc, T):
if isinstance(soc, np.ndarray):
value = np.empty_like(soc)
for i, s in enumerate(soc):
_ = int(s)
value[i] = 1e-1
else:
_ = int(soc)
value = 1e-1
return value
params = {
'num_RC_pairs': 0,
'soc0': 0.5,
'capacity': 1,
'ce': 1,
'gamma': 0,
'mass': 1,
'isothermal': True,
'Cp': 1.,
'T_inf': 300.,
'h_therm': 1.,
'A_therm': 1.,
'ocv': ocv,
'M_hyst': lambda soc: 0.,
'R0': R0,
}
sim = thev.Simulation(params)
expr = thev.Experiment()
expr.add_step('current_C', 1., (100., 1.))
soln = sim.run(expr)
soln.plot('time_s', 'voltage_V') |
Beta Was this translation helpful? Give feedback.
-
This issue is now resolved. You can upgrade your version to either v0.1.3 or v0.2.1 and you should no longer have the problem. In the post-processing steps there were a couple lines that attempted to plug in Post again here (or submit an issue) if you still need help getting your code to run. |
Beta Was this translation helpful? Give feedback.
-
Great, thanks! I will check it out today.
…On Mon, Jun 9, 2025 at 11:52 PM Corey R. Randall ***@***.***> wrote:
This issue is now resolved. You can upgrade your version to either v0.1.3
or v0.2.1 and you should no longer have the problem. In the post-processing
steps there were a couple lines that attempted to plug in soc and T_cell
values into the ocv and R0 functions. For computational efficiency this
was being done assuming the ocv and R0 functions could handle numpy
arrays. Since it is not a requirement to build your functions this way, the
code now has a fall back to using for loops if it detects that numpy
arrays are incompatible with your function definitions.
Post again here (or submit an issue) if you still need help getting your
code to run.
—
Reply to this email directly, view it on GitHub
<#15 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEKZZKHWHNGSND6IUE64ZT3CX6ZLAVCNFSM6AAAAAB6AGWWBOVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTGNBRGQYTKMI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
This issue is now resolved. You can upgrade your version to either v0.1.3 or v0.2.1 and you should no longer have the problem. In the post-processing steps there were a couple lines that attempted to plug in
soc
andT_cell
values into theocv
andR0
functions. For computational efficiency this was being done assuming theocv
andR0
functions could handle numpy arrays. Since it is not a requirement to build your functions this way, the code now has a fall back to usingfor
loops if it detects that numpy arrays are incompatible with your function definitions.Post again here (or submit an issue) if you still need help getting your code to run.