Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Geometry parameters must be Scalars after parameter processing #3649

Open
Mrzhang-hub opened this issue Dec 21, 2023 · 5 comments · May be fixed by #4665
Open

[Bug]: Geometry parameters must be Scalars after parameter processing #3649

Mrzhang-hub opened this issue Dec 21, 2023 · 5 comments · May be fixed by #4665
Labels
bug Something isn't working

Comments

@Mrzhang-hub
Copy link

PyBaMM Version

23.9

Python Version

3.9

Describe the bug

ValueError: Geometry parameters must be Scalars after parameter processing.

Steps to Reproduce

import pybamm
model = pybamm.lithium_ion.SPMe()
param = pybamm.ParameterValues('Prada2013')
param['Current function [A]'] = 1*param['Nominal cell capacity [A.h]']
param.update({'Positive particle radius [m]': "[input]"})
sim = pybamm.Simulation(model=model,parameter_values=param)
sol = sim.solve([0,3600],inputs={'Positive particle radius [m]':5e-08},calculate_sensitivities=True)
J = sol['Voltage [V]'].sensitivities['Positive particle radius [m]']

Relevant log output

No response

@Mrzhang-hub Mrzhang-hub added the bug Something isn't working label Dec 21, 2023
@valentinsulzer
Copy link
Member

Geometry parameters (particle radius and thicknesses) don't work with inputs at the moment unfortunately. This is a known issue but challenging to fix

@Jiyuan-Wangrwth
Copy link

I am also facing the same bug, there is any other way to make these variables?

@BradyPlanden
Copy link
Member

As Valentin mentioned above, the geometric parameters require a rebuild of the model when changes are made. As a result, the gradient information is not available. As far as I know, this is the only way to change the geometric parameters:

import pybamm
model = pybamm.lithium_ion.SPMe()
param = pybamm.ParameterValues('Prada2013')
param['Current function [A]'] = 1*param['Nominal cell capacity [A.h]']
param.update({'Positive particle radius [m]': 5e-8})
sim = pybamm.Simulation(model=model,parameter_values=param)
sol = sim.solve([0,3600])

In PyBOP we have a PR open to allow fitting of these parameters, which essentially rebuilds the required model objects at each iteration. You may be able to find some useful information related to this challenge on that branch.

@Jiyuan-Wangrwth
Copy link

This way is great, which assign the parametervalue directly with avoiding "inputs".
But how to apply it in liionpack?
e.g.
import liionpack import pybamm import numpy as np
Np,Ns=1,96 net= liionpack.setup_circuit(Np=Np, Ns=Ns)
parametervalues=pybamm.ParameterValues("Chen2020")
variable=5.56e-05*np.ones(96)
variable[:50]=6.56e-05
parametervalues.update( { "Negative electrode thickness [m]": variable, } )
experiment= pybamm.Experiment([("Discharge at 5 A for 700 s", "Charge at 5 A for 100 s")]*2, period="10 s")
output= liionpack.solve( netlist=net, parameter_values=parametervalues, experiment=experiment, sim_func=liionpack.basic_simulation, )
liionpack.plot_output(output)
there will be an error TypeError: Cannot process parameter
but it works.
import liionpack
import pybamm
import numpy as np
Np,Ns=1,96 net= liionpack.setup_circuit(Np=Np, Ns=Ns)
parametervalues=pybamm.ParameterValues("Chen2020")
variable=5.56e-05*np.ones(96)
parametervalues.update( { "Negative electrode thickness [m]": 5.56e-05, } )
experiment= pybamm.Experiment([("Discharge at 5 A for 700 s", "Charge at 5 A for 100 s")]*2, period="10 s")
output= liionpack.solve( netlist=net, parameter_values=parametervalues, experiment=experiment, sim_func=liionpack.basic_simulation, )
liionpack.plot_output(output)
maybe because variable is an array rather than a spezifical number.
So when I want to set these cells in different paramter values(radius or thickness), how to make it possible?

@aabills
Copy link
Contributor

aabills commented Dec 11, 2024

Reopening because we are fixing this now.

@aabills aabills linked a pull request Dec 11, 2024 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants