How to evaluate an expression tree with specific variable values? #2064
-
Hello all, I'm fairly new to PyBaMM and am having an issue evaluating an expression tree with specific values substituted for variables. In this simple case, I am trying to extract the RHS of the ODE for SEI growth and get its value by processing it with parameters, but there remains a variable 'Outer SEI thickness' that I would like to substitute different values for (I understand I can just copy the expression but I'd like to automate for other examples as well. This is what I have done to get the expression tree I'd like to evaluate... import pybamm
model = pybamm.lithium_ion.DFN({'SEI porosity change' : 'true', 'SEI' : 'solvent-diffusion limited'})
params = pybamm.ParameterValues('Chen2020_plating')
dLdt = params.process_symbol(list(model.submodels['sei'].rhs.values())[0]) which gives me the output In[2]: dLdt
My question is how to substitute different values of 'Outer SEI thickness' into this expression? I have tried to update the Any help would be much appreciated. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There is no straightforward way to do this, but a hacky way is import pybamm
import numpy as np
model = pybamm.lithium_ion.DFN(
{"SEI porosity change": "true", "SEI": "solvent-diffusion limited"}
)
params = pybamm.ParameterValues("Chen2020_plating")
# Discretize the model
sim = pybamm.Simulation(model, parameter_values=params)
sim.build()
# Extract dLdt
L = model.variables["Outer SEI thickness"]
L_disc = sim.built_model.variables["Outer SEI thickness"]
dLdt = sim.built_model.rhs[L]
dLdt.render()
# Build a y to evaluate
y = np.zeros(L_disc.y_slices[0].stop)
y[L_disc.y_slices[0]] = 1
print(dLdt.evaluate(y=y)) |
Beta Was this translation helpful? Give feedback.
There is no straightforward way to do this, but a hacky way is