discretisation of SPMe model fails with parameter replacement #4508
-
I'm using pybamm v24.9.0 and want to solve an SPMe model with a fairly simple substiution of parameters. I want to replace all instances of the paramter "Positive electrode porosity" with the expression "1 - Positive electrode active material volume fraction". However, when I do this I get an error during discretistion of the model, which I have reproduced below. As far as I can tell both of these parameters in the replacement above should give identical shapes when discretised, so I'm not sure where the problem is occuring, anybody have any ideas? script is: new_model = pybamm.lithium_ion.SPMe()
def find_param_in_model(name):
for p in new_model.parameters:
if p.name == name:
return p
raise ValueError(f"Parameter {name} not found in model")
parameter_to_replace = find_param_in_model('Positive electrode porosity')
replacement_symbol = 1.0 - find_param_in_model('Positive electrode active material volume fraction')
def replace_parameter(symbol):
if symbol == parameter_to_replace:
print('replaced!!!', replacement_symbol, replacement_symbol.children)
return replacement_symbol
else:
new_children = [replace_parameter(child) for child in symbol.children]
if len(new_children) == 0:
new_children = None
return symbol.create_copy(new_children)
def replace_dict(dictionary):
return {key: replace_parameter(value) for key, value in dictionary.items()}
new_model.rhs = replace_dict(new_model.rhs)
new_model.algebraic = replace_dict(new_model.algebraic)
new_model.variables = replace_dict(new_model.variables)
sim = pybamm.Simulation(model=new_model)
sol = sim.solve([0, 3600]) error is:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Judging by the off-by-two shape error you'll also need to update the boundary conditions (the SPMe solves for the product of the porosity and the concentration). Not sure what your workflow looks like, but import pybamm
parameter_values = pybamm.ParameterValues("Chen2020")
parameter_values.update(
{
"Positive electrode porosity": 1
- pybamm.Parameter("Positive electrode active material volume fraction")
}
)
model = pybamm.lithium_ion.SPMe()
sim = pybamm.Simulation(model, parameter_values=parameter_values)
sim.solve([0, 3600])
sim.plot() |
Beta Was this translation helpful? Give feedback.
Judging by the off-by-two shape error you'll also need to update the boundary conditions (the SPMe solves for the product of the porosity and the concentration).
Not sure what your workflow looks like, but
ParameterValues
can be symbols, so you can do something like