Hi everyone,
I’m working on a project using PyBaMM, and trying to update parameter values by uploading a custom parameter function. However, I’m unsure about the correct way to do this.
Could someone guide me on how to define and upload parameter functions in PyBaMM to replace or modify default parameter values? Any examples or tips you can give me would be greatly appreciated!
I really appreciate any help you can provide.
Hi,
You just define your function, e.g.:
def custom_ocp(sto):
x = sto
p = np.array([ 1.20912055e+00, 5.62297420e+01, -1.11020020e-01, -2.53458213e-01, 4.92581391e+01, 1.22046522e-02, 4.73538620e-02, 1.79631246e+01, 1.75283209e-01, 1.88038929e-02, 3.03255334e+01, 4.66328034e-01])
return (
p[0] * pb.exp(-p[1] * x)
+ p[2]
- p[3] * pb.tanh(p[4] * (x - p[5]))
- p[6] * pb.tanh(p[7] * (x - p[8]))
- p[9] * pb.tanh(p[10] * (x - p[11]))
)
And then you insert it into the parameter set, e.g:
param = pb.ParameterValues("Chen2020")
param.update({'Positive electrode OCP [V]': custom_ocp}, check_already_exists=False)
Also, see the official documentation, and make sure that the parameter you are trying to set to a function is actually described as a FunctionParameter
.
good luck