You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, when I tried to run PyBaMM-EIS with degradation submodels it gave me the following errors. The snipped code and error message are mentioned below.
Is it possible to guide me in this matter thank you in advance.
importmatplotlib.pyplotaspltimportnumpyasnpfromscipy.fftimportfftimportpybammimporttimeastimer# Set random seednp.random.seed(0)
# Original function for degradation parameterspp=pybamm.ParameterValues("OKane2022")
# Function to get Chen2020 parametersdefget_chen2020_parameters():
parameter_values=pybamm.ParameterValues("Chen2020")
returnparameter_values# Function to get OKane2022 degradation parameters with k_cr includeddefget_okane2022_degradation_parameters():
degradation_parameters= {
'Dead lithium decay constant [s-1]': 1e-06,
'Dead lithium decay rate [s-1]': pp["Dead lithium decay rate [s-1]"],
'Initial plated lithium concentration [mol.m-3]': 0.0,
'Lithium metal partial molar volume [m3.mol-1]': 1.3e-05,
'Lithium plating kinetic rate constant [m.s-1]': 1e-09,
'Lithium plating transfer coefficient': 0.65,
'Negative electrode LAM constant exponential term': 2.0,
'Negative electrode LAM constant proportional term [s-1]': 2.7778e-07,
"Negative electrode Paris' law constant b": 1.12,
"Negative electrode Paris' law constant m": 2.2,
"Negative electrode Poisson's ratio": 0.3,
"Negative electrode Young's modulus [Pa]": 15000000000.0,
'Negative electrode cracking rate': pp["Negative electrode cracking rate"], # Function'Negative electrode critical stress [Pa]': 60000000.0,
'Negative electrode initial crack length [m]': 2e-08,
'Negative electrode initial crack width [m]': 1.5e-08,
'Negative electrode number of cracks per unit area [m-2]': 3180000000000000.0,
'Negative electrode partial molar volume [m3.mol-1]': 3.1e-06,
'Negative electrode reference concentration for free of deformation [mol.m-3]': 0.0,
'Negative electrode volume change': pp["Negative electrode volume change"],
'Positive electrode LAM constant exponential term': 2.0,
'Positive electrode LAM constant proportional term [s-1]': 2.7778e-07,
'Positive electrode OCP entropic change [V.K-1]': 0.0,
"Positive electrode Paris' law constant b": 1.12,
"Positive electrode Paris' law constant m": 2.2,
"Positive electrode Poisson's ratio": 0.2,
"Positive electrode Young's modulus [Pa]": 375000000000.0,
'Positive electrode active material volume fraction': 0.665,
'Positive electrode cracking rate': pp["Positive electrode cracking rate"], # Function'Positive electrode critical stress [Pa]': 375000000.0,
'Positive electrode initial crack length [m]': 2e-08,
'Positive electrode initial crack width [m]': 1.5e-08,
'Positive electrode number of cracks per unit area [m-2]': 3180000000000000.0,
'Positive electrode partial molar volume [m3.mol-1]': 1.25e-05,
'Positive electrode reference concentration for free of deformation [mol.m-3]': 0.0,
'Positive electrode volume change': pp["Positive electrode volume change"],
'Typical plated lithium concentration [mol.m-3]': 1000.0,
'Exchange-current density for stripping [A.m-2]': pp["Exchange-current density for stripping [A.m-2]"],
'Exchange-current density for plating [A.m-2]': pp["Exchange-current density for plating [A.m-2]"],
"k_cr": pybamm.Parameter("k_cr"), # Define as a parameter object
}
returndegradation_parameters# Graphite cracking rate functiondefgraphite_cracking_rate_Ai2020(T_dim):
""" Calculates the graphite cracking rate using an Arrhenius-like relationship. T_dim: Dimensional temperature (in Kelvin) """Eac_cr=0# Activation energy for cracking [J/mol], update if neededarrhenius=pybamm.exp(Eac_cr/pybamm.constants.R* (1/T_dim-1/298.15))
returnpybamm.Parameter("k_cr") *arrhenius# Function to update parametersdefupdate_parameters():
# Load Chen2020 parameterschen2020_params=get_chen2020_parameters()
# Load OKane2022 degradation parametersokane2022_degradation_params=get_okane2022_degradation_parameters()
# Update Chen2020 parameters with OKane2022 degradation parameterschen2020_params.update(okane2022_degradation_params, check_already_exists=False)
# Add graphite cracking rate functionchen2020_params["k_cr"] =3.9e-20returnchen2020_params# Update the parametersupdated_parameters=update_parameters()
# Define the model with configurationmodel=pybamm.lithium_ion.SPMe(
{
"thermal": "lumped", # Lumped thermal submodel"surface form": "differential", # Adding capacitance to the model"SEI": "solvent-diffusion limited",
"SEI porosity change": "true",
"particle mechanics": "swelling and cracking",
"SEI on cracks": "true",
}
)
# Variable pointsvar_pts= {
"x_n": 5,
"x_s": 5,
"x_p": 5,
"r_n": 30,
"r_p": 30,
}
# Simulation parameterscycle_numbers= [50]
# Store results for Nyquist plotimpedance_data= {}
# Loop through each cycle countforcycle_numberincycle_numbers:
exp=pybamm.Experiment(
[
(
"Discharge at 1C until 2.5 V", # Ageing cycles"Charge at 0.6C until 4.2 V (5 minute period)",
"Hold at 4.2 V until C/100 (5 minute period)",
)
]
*cycle_number
)
sim=pybamm.Simulation(
model,
parameter_values=updated_parameters,
experiment=exp,
solver=pybamm.CasadiSolver(mode='safe without grid'),
var_pts=var_pts,
)
sol=sim.solve()
# Frequency domainimportpbeisaged_model=model.set_initial_conditions_from(sol)
frequencies=np.logspace(-4, 2, 30)
methods= ["direct"]
impedances_freqs= []
formethodinmethods:
start_time=timer.time()
eis_sim=pbeis.EISSimulation(aged_model, parameter_values=updated_parameters)
impedances_freq=eis_sim.solve(frequencies, method)
end_time=timer.time()
time_elapsed=end_time-start_timeprint(f"Frequency domain ({method}): ", time_elapsed, "s")
impedances_freqs.append(impedances_freq)
---------------------------------------------------------------------------ModelErrorTraceback (mostrecentcalllast)
CellIn[4], line119formethodinmethods:
10start_time=timer.time()
--->11eis_sim=pbeis.EISSimulation(aged_model, parameter_values=updated_parameters)
12impedances_freq=eis_sim.solve(frequencies, method)
13end_time=timer.time()
File~/pybamm-eis/pbeis/eis_simulation.py:61, inEISSimulation.__init__(self, model, parameter_values, geometry, submesh_types, var_pts, spatial_methods)
52parameter_values["Current function [A]"] =053sim=pybamm.Simulation(
54self.model,
55geometry=geometry,
(...)
59spatial_methods=spatial_methods,
60 )
--->61sim.build()
62self.built_model=sim.built_model64# Extract mass matrix and JacobianFile~/pybamm-eis/env/lib/python3.9/site-packages/pybamm/simulation.py:439, inSimulation.build(self, check_model, initial_soc)
437self._mesh=pybamm.Mesh(self._geometry, self._submesh_types, self._var_pts)
438self._disc=pybamm.Discretisation(self._mesh, self._spatial_methods)
-->439self._built_model=self._disc.process_model(
440self._model_with_set_params, inplace=False, check_model=check_model441 )
File~/pybamm-eis/env/lib/python3.9/site-packages/pybamm/discretisations/discretisation.py:269, inDiscretisation.process_model(self, model, inplace, check_model, remove_independent_variables_from_rhs)
267ifcheck_model:
268pybamm.logger.verbose("Performing model checks for {}".format(model.name))
-->269self.check_model(model_disc)
271pybamm.logger.info("Finish discretising {}".format(model.name))
273# Record that the model has been discretisedFile~/pybamm-eis/env/lib/python3.9/site-packages/pybamm/discretisations/discretisation.py:1076, inDiscretisation.check_model(self, model)
1074defcheck_model(self, model):
1075"""Perform some basic checks to make sure the discretised model makes sense."""->1076self.check_initial_conditions(model)
1077self.check_variables(model)
File~/pybamm-eis/env/lib/python3.9/site-packages/pybamm/discretisations/discretisation.py:1106, inDiscretisation.check_initial_conditions(self, model)
1104forvarinmodel.rhs.keys():
1105ifmodel.rhs[var].shape!=model.initial_conditions[var].shape:
->1106raisepybamm.ModelError(
1107"rhs and initial conditions must have the same shape after "1108"discretisation but rhs.shape = "1109"{} and initial_conditions.shape = {} for variable '{}'.".format(
1110model.rhs[var].shape, model.initial_conditions[var].shape, var1111 )
1112 )
1113forvarinmodel.algebraic.keys():
1114ifmodel.algebraic[var].shape!=model.initial_conditions[var].shape:
ModelError: rhsandinitialconditionsmusthavethesameshapeafterdiscretisationbutrhs.shape= (20, 1) andinitial_conditions.shape= (30, 1) forvariable'X-averaged negative particle concentration'.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello Everyone,
I was instructed in in this discussion to use PyBaMM-EIS.
However, when I tried to run PyBaMM-EIS with degradation submodels it gave me the following errors. The snipped code and error message are mentioned below.
Is it possible to guide me in this matter thank you in advance.
Beta Was this translation helpful? Give feedback.
All reactions