Half-cell OCP fitting¶
In this example, we show how to fit the half-cell Open-Circuit Potential to pseudo-OCP data. Our recommended workflow for fitting OCPs is to first fit the MSMR model to the data and then create an interpolant to find a function \(U(x)\), where \(x\) is the stoichiometry. For comparison, we also show how to fit a function \(U(x)\) directly to pseudo-OCP data.
import ionworkspipeline as iwp
import numpy as np
import pandas as pd
import pybamm
import matplotlib.pyplot as plt
from scipy.signal import savgol_filter
Pre-process and visualize the data¶
First, we load and pre-process the data.
# Load data
raw_ocp_data = pd.read_csv("anode_ocp_delithiation.csv", comment="#")
q = raw_ocp_data["Capacity [A.h]"].values
U = raw_ocp_data["Voltage [V]"].values
# Smooth
q_smoothed = savgol_filter(q, window_length=11, polyorder=1)
U_smoothed = savgol_filter(U, window_length=11, polyorder=1)
dQdU_smoothed = -np.gradient(q_smoothed, U_smoothed)
# Store in a dataframe
ocp_data = pd.DataFrame({"Capacity [A.h]": q_smoothed, "Voltage [V]": U_smoothed})
ocp_data = iwp.data_fits.preprocess.sort_capacity_and_ocp(ocp_data)
# Maximum capacity, will be used later as an initial guess for the electrode capacity
Q_max_data = ocp_data["Capacity [A.h]"].max()
# Plot
_, ax = plt.subplots(1, 2, figsize=(10, 5))
ax[0].plot(q_smoothed, U_smoothed, "-x")
ax[0].set_xlabel("Capacity [A.h]")
ax[0].set_ylabel("Voltage [V]")
ax[1].plot(dQdU_smoothed, U_smoothed, "-x")
ax[1].set_xlabel("dQ/dU [A.h/V]")
ax[1].set_ylabel("Voltage [V]")
ax[1].set_xlim(0, 200)
plt.tight_layout()
/home/docs/checkouts/readthedocs.org/user_builds/ionworks-ionworkspipeline/envs/v0.8.0/lib/python3.12/site-packages/numpy/lib/function_base.py:1242: RuntimeWarning: divide by zero encountered in divide
a = -(dx2)/(dx1 * (dx1 + dx2))
/home/docs/checkouts/readthedocs.org/user_builds/ionworks-ionworkspipeline/envs/v0.8.0/lib/python3.12/site-packages/numpy/lib/function_base.py:1243: RuntimeWarning: divide by zero encountered in divide
b = (dx2 - dx1) / (dx1 * dx2)
/home/docs/checkouts/readthedocs.org/user_builds/ionworks-ionworkspipeline/envs/v0.8.0/lib/python3.12/site-packages/numpy/lib/function_base.py:1244: RuntimeWarning: divide by zero encountered in divide
c = dx1 / (dx2 * (dx1 + dx2))
/home/docs/checkouts/readthedocs.org/user_builds/ionworks-ionworkspipeline/envs/v0.8.0/lib/python3.12/site-packages/numpy/lib/function_base.py:1250: RuntimeWarning: invalid value encountered in add
out[tuple(slice1)] = a * f[tuple(slice2)] + b * f[tuple(slice3)] + c * f[tuple(slice4)]

Fit the MSMR model to data¶
We begin by getting literature values for the MSMR parameters from the ionworkspipeline library
lib = iwp.Library()
gr = lib["Graphite - Verbrugge 2017"]
gr_params = gr.parameter_values
This gives us initial guesses for the MSMR species parameters (\(X_j\), \(U^0_j\), and \(w_j\)). We also need estimates for the total electrode capacity and lower excess capacity. We can use the helper function get_initial_capacity_and_lower_excess_capacity
to estimate these from the species parameters and data
gr_params.update(
iwp.data_fits.objectives.get_initial_capacity_and_lower_excess_capacity(
gr_params, "negative", ocp_data
)
)
We can plot these against the data and, if required, manually adjust them to get a better starting point. For this example, let’s keep the Graphite parameters as our initial guess.
fig, ax = iwp.objectives.plot_each_species_msmr(
ocp_data, gr_params, "negative", voltage_limits=(0, 1.5)
)
_ = ax[1].set_xlim(0, 50)

Now we can set up the objective and parameters to fit, run the data fit and plot the results.
# Loop over the initial guesses and set up the parameters to fit with appropriate bounds
paramaters_to_fit = {}
for k, v in gr_params.items():
if "X" in k:
bounds = (0, 1)
elif "U0_" in k:
bounds = (max(0, v - 0.5), v + 0.5)
elif "w_" in k:
bounds = (1e-2, 100)
elif "lower excess" in k:
bounds = (0, 0.1 * Q_max_data)
elif "capacity" in k:
bounds = (Q_max_data, 1.5 * Q_max_data)
else:
continue
paramaters_to_fit[k] = iwp.Parameter(k, initial_value=v, bounds=bounds)
# Calculate dUdQ cutoff to prevent overfitting to extreme dUdQ values
dUdq_cutoff = iwp.data_fits.util.calculate_dUdQ_cutoff(ocp_data)
# Set up model, objective and fit
model = iwp.data_fits.models.MSMRHalfCellModel(
"negative", options={"species format": "Xj"}
)
objective = iwp.data_fits.objectives.MSMRHalfCell(
ocp_data, options={"model": model, "dUdQ cutoff": dUdq_cutoff}
)
ocp_msmr = iwp.DataFit(objective, parameters=paramaters_to_fit)
# Run the fit
results = ocp_msmr.run({"Ambient temperature [K]": 298.15})
# Plot results
fig_ax = ocp_msmr.plot_fit_results()
axes = fig_ax["MSMRHalfCell"][0][1]
_ = axes[2].set_xlim(0, 100)

Lastly, we can look at the fitted parameters.
results
Result(
U0_n_0: 0.0923011
X_n_0: 0.216919
w_n_0: 0.0195237
U0_n_1: 0.132874
X_n_1: 0.166923
w_n_1: 0.0397932
U0_n_2: 0.21725
X_n_2: 0.0555398
w_n_2: 0.193303
U0_n_3: 0.144143
X_n_3: 0.121123
w_n_3: 0.519779
U0_n_4: 0.0920626
X_n_4: 0.116636
w_n_4: 0.11419
U0_n_5: 0.0243555
X_n_5: 0.576909
w_n_5: 6.70857
Negative electrode capacity [A.h]: 6.6498
Negative electrode lower excess capacity [A.h]: 0.08694
)
results.callbacks["MSMRHalfCell"].callbacks[0].fit_results_["outputs"]
{'Voltage [V]': array([0.57042509, 0.55625879, 0.54209249, 0.52792619, 0.51375989,
0.49959359, 0.48648957, 0.47295495, 0.46045517, 0.44915866,
0.43675264, 0.42406013, 0.41270112, 0.40113721, 0.39000913,
0.37774201, 0.36722685, 0.35521324, 0.34456959, 0.33331822,
0.32313643, 0.31454164, 0.30540338, 0.2967374 , 0.28874685,
0.28124941, 0.27411313, 0.26702894, 0.26037709, 0.25435727,
0.2486604 , 0.24312153, 0.23816607, 0.23433054, 0.23066864,
0.22734184, 0.22472 , 0.22253744, 0.22104247, 0.22010138,
0.21935997, 0.21880088, 0.2183286 , 0.2178459 , 0.21732327,
0.21679716, 0.2160245 , 0.21504521, 0.21366136, 0.21194241,
0.20987445, 0.20766585, 0.20530271, 0.20272775, 0.19990449,
0.19689023, 0.1936763 , 0.19042243, 0.18722066, 0.18420119,
0.1813189 , 0.17866233, 0.1761325 , 0.17363741, 0.17126907,
0.16905526, 0.1669873 , 0.16509297, 0.16329762, 0.16157692,
0.15996041, 0.15830917, 0.15676558, 0.15520289, 0.15365235,
0.1521296 , 0.15061032, 0.14913097, 0.14770024, 0.14644488,
0.14522251, 0.14403487, 0.14302085, 0.14203462, 0.14115778,
0.14040769, 0.13969059, 0.13896828, 0.13829285, 0.13772334,
0.13718161, 0.13674926, 0.13624226, 0.13586547, 0.13546959,
0.13515358, 0.13483757, 0.13466741, 0.1345285 , 0.13442259,
0.13429237, 0.13414304, 0.13400414, 0.1339642 , 0.1338878 ,
0.13382182, 0.13368986, 0.13354054, 0.13331135, 0.13323668,
0.13318807, 0.13305263, 0.13296755, 0.13284775, 0.13285295,
0.13276961, 0.1327453 , 0.13266717, 0.13260639, 0.13255257,
0.13245533, 0.13232337, 0.13233726, 0.13227302, 0.13226781,
0.13208203, 0.13200042, 0.13192055, 0.13177643, 0.13174518,
0.13159412, 0.1314257 , 0.13134235, 0.13110621, 0.13087876,
0.13058358, 0.13036307, 0.13005574, 0.12960256, 0.12914243,
0.1286198 , 0.1280555 , 0.12725679, 0.1262341 , 0.1250152 ,
0.12335007, 0.12166063, 0.12012919, 0.11810117, 0.11562517,
0.11317522, 0.11070617, 0.10817288, 0.10582017, 0.1036515 ,
0.10194296, 0.10062336, 0.09939057, 0.09774106, 0.09668017,
0.09637284, 0.09584326, 0.09548037, 0.09543002, 0.09532063,
0.09513311, 0.09471118, 0.09449067, 0.09411736, 0.09405659,
0.0938899 , 0.09374058, 0.0938899 , 0.09378225, 0.09352006,
0.09342804, 0.09335511, 0.09337942, 0.0932683 , 0.0932492 ,
0.09321794, 0.09334122, 0.09315891, 0.09299222, 0.0929436 ,
0.09300264, 0.09291061, 0.09285158, 0.09280817, 0.09277518,
0.0927665 , 0.0926901 , 0.09255293, 0.09251994, 0.0924939 ,
0.09249563, 0.09237236, 0.09237409, 0.09238798, 0.09233242,
0.09235152, 0.09235499, 0.0923411 , 0.09235847, 0.09233589,
0.09230985, 0.0922022 , 0.09218136, 0.09216573, 0.0921258 ,
0.09208934, 0.09203204, 0.09202336, 0.0920303 , 0.09196779,
0.09198689, 0.09192091, 0.09190876, 0.09186188, 0.09179763,
0.09180458, 0.09175075, 0.09168477, 0.09168651, 0.09162053,
0.09150072, 0.09143474, 0.09138439, 0.0913323 , 0.09127674,
0.09111526, 0.09104928, 0.09092947, 0.09077147, 0.09066208,
0.09052491, 0.09039121, 0.09016376, 0.08997971, 0.08973488,
0.08936331, 0.0890282 , 0.08862017, 0.08808017, 0.08741863,
0.08661298, 0.08549305, 0.08441167, 0.08333029, 0.08224891,
0.08116752, 0.08008614]),
'Capacity [A.h]': array([0.03659061, 0.04671019, 0.05761795, 0.06936836, 0.08201855,
0.09562813, 0.10912519, 0.12403727, 0.1387354 , 0.15282357,
0.16921899, 0.18704111, 0.20393083, 0.2220764 , 0.24047975,
0.261878 , 0.28118037, 0.30435493, 0.32591625, 0.34979024,
0.37237654, 0.39218384, 0.4140015 , 0.4354245 , 0.45581922,
0.47552274, 0.49479563, 0.51444131, 0.53338306, 0.55100958,
0.56830056, 0.5861902 , 0.60424933, 0.62120982, 0.6423168 ,
0.66878423, 0.69688541, 0.72618276, 0.74934717, 0.76505728,
0.77793392, 0.78787438, 0.7963885 , 0.80516905, 0.81472807,
0.82436334, 0.83844669, 0.85599393, 0.87977597, 0.90695156,
0.93545927, 0.96079114, 0.98283515, 1.00237034, 1.02024769,
1.03702555, 1.05377621, 1.07059425, 1.08770123, 1.10479188,
1.1222998 , 1.13971643, 1.15764885, 1.17681006, 1.19651805,
1.21641291, 1.23638338, 1.25592016, 1.2755764 , 1.29547986,
1.31513379, 1.33615685, 1.35665268, 1.37819595, 1.40031087,
1.42268339, 1.44557556, 1.46833104, 1.49068982, 1.51052213,
1.52996414, 1.54892487, 1.56513801, 1.58092137, 1.59499546,
1.60713808, 1.61897546, 1.63140846, 1.64400274, 1.65602065,
1.66956721, 1.68277805, 1.70252957, 1.72156296, 1.74719805,
1.77306003, 1.8048684 , 1.82482503, 1.84271467, 1.85736273,
1.87659935, 1.90034656, 1.92405531, 1.93115638, 1.9450881 ,
1.95747917, 1.9832181 , 2.01377161, 2.06317071, 2.07979003,
2.09072135, 2.1215275 , 2.14106435, 2.1686756 , 2.16747491,
2.18667101, 2.19225817, 2.21015519, 2.22398694, 2.23615417,
2.25788565, 2.28673978, 2.28374202, 2.29752069, 2.29862806,
2.33705395, 2.35321539, 2.36857071, 2.39505664, 2.40058641,
2.42620569, 2.45257789, 2.4647728 , 2.4963194 , 2.52270276,
2.551635 , 2.56980284, 2.59096498, 2.61512566, 2.63337085,
2.64893542, 2.66180859, 2.6760123 , 2.69072603, 2.70600352,
2.72512325, 2.74332377, 2.75899297, 2.7786454 , 2.80109846,
2.82188139, 2.84174577, 2.86165188, 2.88082833, 2.9009243 ,
2.92045414, 2.93950021, 2.96204398, 3.00250847, 3.0367603 ,
3.04814997, 3.06964739, 3.08608656, 3.08850718, 3.09390514,
3.10366912, 3.12893528, 3.14490825, 3.17950547, 3.18642816,
3.20799011, 3.23124549, 3.20799001, 3.22432425, 3.27457378,
3.29658949, 3.31596758, 3.30930802, 3.34148005, 3.34747061,
3.35757969, 3.31986576, 3.37774182, 3.44260624, 3.46381288,
3.43819793, 3.478798 , 3.50680506, 3.52835764, 3.54526726,
3.54979121, 3.5908842 , 3.6698186 , 3.68962606, 3.70544603,
3.70438692, 3.78086679, 3.77977595, 3.77106075, 3.80600595,
3.79397085, 3.79178474, 3.80053318, 3.78959937, 3.80381617,
3.82024487, 3.88800409, 3.90101375, 3.9107337 , 3.93539707,
3.95765027, 3.99199197, 3.99711967, 3.9930194 , 4.02940229,
4.01841345, 4.05585685, 4.06258913, 4.0880388 , 4.12150945,
4.11797224, 4.14485505, 4.17610967, 4.17531135, 4.20470699,
4.25319789, 4.27727401, 4.29444103, 4.31114288, 4.32782404,
4.37021703, 4.38519588, 4.40939746, 4.43628219, 4.45213643,
4.46944837, 4.48409189, 4.50517604, 4.51964327, 4.53639917,
4.55824421, 4.57556508, 4.59463765, 4.61736837, 4.64204507,
4.66797054, 4.69741639, 4.71977269, 4.73744101, 4.75155248,
4.76303585, 4.7726125 ]),
'Differential capacity [Ah/V]': array([2.32572561e+107, 2.32572561e+107, 2.32572561e+107, 2.32572561e+107,
2.32572561e+107, 2.32572561e+107, 2.32572561e+107, 2.32572561e+107,
2.32572561e+107, 3.78828332e+101, 3.64833371e+090, 4.75456656e+080,
4.43220861e+070, 1.04029835e+061, 2.83831540e+050, 2.32028911e+041,
3.31219802e+040, 2.64596180e+030, 2.70794937e+021, 6.98084693e+011,
1.30160776e+003, 2.35709926e+000, 2.43137958e+000, 2.50428202e+000,
2.57604679e+000, 2.64680080e+000, 2.71688848e+000, 2.78736552e+000,
2.86150959e+000, 2.94933456e+000, 3.08226629e+000, 3.34890508e+000,
3.92448213e+000, 4.97332324e+000, 6.54366094e+000, 8.38221122e+000,
1.02547622e+001, 1.21251260e+001, 1.37530809e+001, 1.52323453e+001,
1.64604546e+001, 1.73725620e+001, 1.79900388e+001, 1.82804567e+001,
1.82500424e+001, 1.78984161e+001, 1.72339588e+001, 1.63180700e+001,
1.51333448e+001, 1.36798817e+001, 1.21119025e+001, 1.04163783e+001,
8.73821625e+000, 7.23927797e+000, 6.08113401e+000, 5.38260507e+000,
5.14887598e+000, 5.26429691e+000, 5.57586359e+000, 6.00948277e+000,
6.52112583e+000, 7.08572274e+000, 7.68534459e+000, 8.30608236e+000,
8.93728552e+000, 9.56990369e+000, 1.01962351e+001, 1.08093787e+001,
1.14036968e+001, 1.19745186e+001, 1.25171602e+001, 1.30298770e+001,
1.35055104e+001, 1.39419808e+001, 1.43392367e+001, 1.46963881e+001,
1.50122150e+001, 1.52866519e+001, 1.55181747e+001, 1.56954088e+001,
1.58306914e+001, 1.59211089e+001, 1.59709721e+001, 1.59929510e+001,
1.60207070e+001, 1.61895616e+001, 1.67752111e+001, 1.87825213e+001,
2.30042715e+001, 3.04594821e+001, 4.03138537e+001, 5.15255603e+001,
6.36039379e+001, 7.59734114e+001, 8.84296234e+001, 1.00623650e+002,
1.12694665e+002, 1.24296553e+002, 1.35420558e+002, 1.45996011e+002,
1.56043861e+002, 1.65604996e+002, 1.74456581e+002, 1.82757591e+002,
1.90436002e+002, 1.97334052e+002, 2.03587257e+002, 2.09455292e+002,
2.13948562e+002, 2.18441833e+002, 2.22448144e+002, 2.25488900e+002,
2.27573771e+002, 2.30510329e+002, 2.30069440e+002, 2.28888706e+002,
2.27100690e+002, 2.24532544e+002, 2.21361947e+002, 2.07318735e+002,
2.01648732e+002, 1.95142540e+002, 1.87816486e+002, 1.79903278e+002,
1.71311330e+002, 1.62226720e+002, 1.52404587e+002, 1.42096082e+002,
1.31029968e+002, 1.19653121e+002, 1.07813468e+002, 9.53731285e+001,
8.27695350e+001, 6.99318864e+001, 5.71528367e+001, 4.46281791e+001,
3.30878546e+001, 2.34342973e+001, 1.66825253e+001, 1.31591185e+001,
1.17347063e+001, 1.09312497e+001, 1.03135969e+001, 9.73623219e+000,
9.17952127e+000, 8.65445041e+000, 8.19975046e+000, 7.89614088e+000,
7.90088150e+000, 8.52992918e+000, 1.00862497e+001, 1.25617254e+001,
1.57422624e+001, 1.93744690e+001, 2.31818518e+001, 2.70484317e+001,
3.08962739e+001, 3.47264297e+001, 3.86498491e+001, 4.29280778e+001,
4.81393566e+001, 5.53919110e+001, 6.51739667e+001, 7.77598239e+001,
9.49025105e+001, 1.12552163e+002, 1.33601915e+002, 1.55777920e+002,
1.79122376e+002, 2.03018851e+002, 2.26928228e+002, 2.51029273e+002,
3.21704859e+002, 3.44261742e+002, 3.65809596e+002, 4.07692485e+002,
4.28074913e+002, 4.47155630e+002, 4.82529698e+002, 4.98976015e+002,
5.14559215e+002, 5.28885343e+002, 5.42411146e+002, 5.55131312e+002,
5.65577017e+002, 5.76022721e+002, 6.30333076e+002, 6.29429847e+002,
6.27918755e+002, 6.26407662e+002, 6.23853683e+002, 6.19435517e+002,
6.14217840e+002, 6.07795732e+002, 6.00155904e+002, 5.48957220e+002,
5.35788999e+002, 5.21443422e+002, 4.56005944e+002, 3.97413808e+002,
3.77050471e+002, 3.55428706e+002, 3.10516837e+002, 2.87247630e+002,
2.63543921e+002, 2.39840225e+002, 2.15998818e+002, 1.92312575e+002,
1.69189267e+002, 1.46618701e+002, 1.25448974e+002, 1.05929726e+002,
8.90741377e+001, 7.46236437e+001, 6.35649559e+001, 5.55101834e+001,
4.94203040e+001, 4.47942066e+001, 4.08407066e+001, 3.70454931e+001,
3.32444600e+001, 2.93679078e+001, 2.53129756e+001, 2.12197851e+001,
1.71164768e+001, 1.31784505e+001, 9.64129061e+000]),
'Differential voltage [V/Ah]': array([0.38824813, 0.37787006, 0.36811977, 0.35881621, 0.3495213 ,
0.33912179, 0.32454055, 0.29887794, 0.25541365, 0.20112025,
0.15415668, 0.12237467, 0.09896548, 0.08253642, 0.0733161 ,
0.06580554, 0.06077875, 0.05757514, 0.05558773, 0.0547034 ,
0.0547954 , 0.05588 , 0.05807626, 0.06139101, 0.0661622 ,
0.07360282, 0.08314636, 0.09609916, 0.11517582, 0.13911075,
0.1651144 , 0.18593439, 0.19421845, 0.19001383, 0.17948656,
0.16661333, 0.15356932, 0.14134726, 0.13033246, 0.12058138,
0.11204244, 0.10461035, 0.09815732, 0.0925729 , 0.08773412,
0.08353784, 0.07990848, 0.07674948, 0.07404991, 0.07173958,
0.06975432, 0.06805666, 0.06662055, 0.06541972, 0.06444063,
0.0637144 , 0.06316921, 0.06281002, 0.06261367, 0.06252755,
0.06241927, 0.06177064, 0.05961301, 0.05338424, 0.04355009,
0.03316066, 0.02528805, 0.01967244, 0.01597935, 0.0132323 ,
0.0113651 , 0.01004154, 0.0088841 , 0.008049 , 0.00738791,
0.00685718, 0.0064155 , 0.0060396 , 0.00573537, 0.00547314,
0.00525132, 0.00506978, 0.00491451, 0.00477447, 0.00467737,
0.00458028, 0.00449562, 0.00443483, 0.00439441, 0.0043382 ,
0.00434652, 0.00436897, 0.00440336, 0.00445388, 0.00451762,
0.00482723, 0.0049601 , 0.00512448, 0.00532661, 0.00556123,
0.0058443 , 0.00616812, 0.00656948, 0.00704349, 0.00766571,
0.00839257, 0.00927538, 0.01057618, 0.0121496 , 0.0144563 ,
0.01783163, 0.02256444, 0.0305295 , 0.04330931, 0.06049244,
0.07606327, 0.08531173, 0.09153672, 0.0970085 , 0.10280352,
0.10906123, 0.11561492, 0.12197486, 0.12664415, 0.12656816,
0.1172496 , 0.09939241, 0.08006612, 0.06391746, 0.05222397,
0.04420369, 0.03771956, 0.03267336, 0.02898441, 0.0259005 ,
0.02330936, 0.0207743 , 0.01813387, 0.01543642, 0.01287716,
0.01084617, 0.00889269, 0.00754596, 0.00644249, 0.00564138,
0.00501927, 0.0044098 , 0.00398818, 0.00310947, 0.00290818,
0.00274601, 0.00246456, 0.00233665, 0.00223639, 0.00207332,
0.00200475, 0.00194372, 0.00189169, 0.00184487, 0.00180199,
0.00177027, 0.00173855, 0.00158646, 0.00158876, 0.00159259,
0.00159642, 0.00160295, 0.00161441, 0.00162809, 0.00164533,
0.00166647, 0.00182189, 0.0018666 , 0.00191869, 0.00219386,
0.00252589, 0.00265307, 0.00281562, 0.0032205 , 0.00348846,
0.00383381, 0.00417916, 0.00463508, 0.00521638, 0.005965 ,
0.00684726, 0.00801531, 0.0094706 , 0.01131347, 0.01342052,
0.01574457, 0.0180572 , 0.02024401, 0.02233556, 0.02453793,
0.02710947, 0.03025702, 0.03411209, 0.04001613, 0.04777092,
0.0591041 , 0.0767708 , 0.10372073]),
'Full voltage [V]': array([-1.91991386, -1.91946478, -1.9190157 , ..., 2.56952693,
2.56997601, 2.57042509]),
'Full capacity [A.h]': array([ 6.56282407, 6.56282397, 6.56282387, ..., -0.08693885,
-0.08693885, -0.08693886]),
'Full differential capacity [Ah/V]': array([2.32572561e+107, 2.32572561e+107, 2.32572561e+107, 2.32572561e+107,
2.32572561e+107, 2.32572561e+107, 2.32572561e+107, 2.32572561e+107,
2.32572561e+107, 2.32572561e+107, 3.83506854e+101, 3.93277633e+090,
5.75643271e+080, 5.60040505e+070, 1.29900777e+061, 3.11060017e+050,
2.44849534e+041, 9.71882857e+030, 5.92140789e+021, 1.07419528e+012,
1.64577096e+003, 2.34460213e+000, 2.43070097e+000, 2.51365972e+000,
2.59122209e+000, 2.66503651e+000, 2.73663062e+000, 2.81039860e+000,
2.88667757e+000, 2.97449540e+000, 3.10976552e+000, 3.38918091e+000,
3.98417256e+000, 4.96882943e+000, 6.72942397e+000, 9.36481775e+000,
1.21566578e+001, 1.46836285e+001, 1.62650611e+001, 1.70948870e+001,
1.76195300e+001, 1.79259692e+001, 1.81191224e+001, 1.82507932e+001,
1.83158941e+001, 1.82989911e+001, 1.81261084e+001, 1.76684606e+001,
1.66360685e+001, 1.49259128e+001, 1.26386147e+001, 1.03571687e+001,
8.39290149e+000, 6.88554373e+000, 5.87578739e+000, 5.33107070e+000,
5.14655069e+000, 5.22666101e+000, 5.48458207e+000, 5.85466705e+000,
6.31014425e+000, 6.81564971e+000, 7.37369159e+000, 7.99753095e+000,
8.65582733e+000, 9.32598896e+000, 9.99446357e+000, 1.06362058e+001,
1.12628474e+001, 1.18720175e+001, 1.24435645e+001, 1.30172408e+001,
1.35350556e+001, 1.40315496e+001, 1.44870096e+001, 1.48890589e+001,
1.52369133e+001, 1.55171419e+001, 1.57276319e+001, 1.58603236e+001,
1.59424073e+001, 1.59817068e+001, 1.59950653e+001, 1.60178926e+001,
1.61009638e+001, 1.63067056e+001, 1.67690761e+001, 1.77841385e+001,
1.97280526e+001, 2.27564651e+001, 2.76760807e+001, 3.38436574e+001,
4.48821258e+001, 5.67528280e+001, 7.35677036e+001, 9.06790818e+001,
1.11184227e+002, 1.23516623e+002, 1.34136622e+002, 1.42493953e+002,
1.52973439e+002, 1.65089152e+002, 1.76236383e+002, 1.79385027e+002,
1.85302808e+002, 1.90273623e+002, 1.99704535e+002, 2.09305070e+002,
2.21095187e+002, 2.24011928e+002, 2.25640139e+002, 2.28984598e+002,
2.30151054e+002, 2.30533029e+002, 2.30547295e+002, 2.29982796e+002,
2.29683656e+002, 2.28316365e+002, 2.26832872e+002, 2.25220715e+002,
2.21627493e+002, 2.15447861e+002, 2.16164417e+002, 2.12728593e+002,
2.12436692e+002, 2.00863800e+002, 1.95164937e+002, 1.89300086e+002,
1.78167334e+002, 1.75682835e+002, 1.63465084e+002, 1.49706086e+002,
1.42953758e+002, 1.24410653e+002, 1.07818835e+002, 8.87005631e+001,
7.63555598e+001, 6.18740547e+001, 4.56970949e+001, 3.43379585e+001,
2.58709471e+001, 2.02290703e+001, 1.58536066e+001, 1.32819582e+001,
1.19619215e+001, 1.10878975e+001, 1.04782974e+001, 9.99161141e+000,
9.39834502e+000, 8.75469075e+000, 8.23471307e+000, 7.89588616e+000,
7.90089872e+000, 8.54396719e+000, 1.02277101e+001, 1.28874959e+001,
1.61959679e+001, 2.06152265e+001, 2.89259267e+001, 3.58943849e+001,
3.82644913e+001, 4.31497390e+001, 4.76936478e+001, 4.84579141e+001,
5.02738549e+001, 5.40121932e+001, 6.71403924e+001, 7.84172705e+001,
1.10288847e+002, 1.17665207e+002, 1.42161488e+002, 1.70411146e+002,
1.42161366e+002, 1.61857905e+002, 2.25408354e+002, 2.53592434e+002,
2.78187108e+002, 2.69768712e+002, 3.09992414e+002, 3.17338676e+002,
3.29614346e+002, 2.83095113e+002, 3.53599364e+002, 4.25447154e+002,
4.46950493e+002, 4.20847704e+002, 4.61506537e+002, 4.87242099e+002,
5.05704356e+002, 5.19351401e+002, 5.22875823e+002, 5.52399108e+002,
5.96195479e+002, 6.04461759e+002, 6.10269040e+002, 6.09902369e+002,
6.28173905e+002, 6.28030714e+002, 6.26764374e+002, 6.30529261e+002,
6.29627631e+002, 6.29419301e+002, 6.30170735e+002, 6.29197355e+002,
6.30396112e+002, 6.31059681e+002, 6.25620988e+002, 6.23073489e+002,
6.20855079e+002, 6.14019674e+002, 6.06372364e+002, 5.91834229e+002,
5.89380264e+002, 5.91348402e+002, 5.72255465e+002, 5.78408066e+002,
5.56087212e+002, 5.51669095e+002, 5.33868115e+002, 5.07852174e+002,
5.10739239e+002, 4.87996750e+002, 4.59287688e+002, 4.60050551e+002,
4.30972096e+002, 3.78809193e+002, 3.51158027e+002, 3.30820586e+002,
3.10597144e+002, 2.90030481e+002, 2.36654420e+002, 2.17655943e+002,
1.87206674e+002, 1.54406356e+002, 1.36004186e+002, 1.17129590e+002,
1.02480440e+002, 8.40998577e+001, 7.36507433e+001, 6.38743895e+001,
5.45279833e+001, 4.91760890e+001, 4.45423108e+001, 3.98125128e+001,
3.48948461e+001, 2.95692938e+001, 2.32270134e+001, 1.83181718e+001,
1.45344474e+001, 1.17076743e+001, 9.64138146e+000, 8.15320419e+000]),
'Full differential voltage [V/Ah]': array([4.29973336e-108, 4.29973336e-108, 4.29973336e-108, 4.29973336e-108,
4.29973336e-108, 4.29973336e-108, 4.29973336e-108, 4.29973336e-108,
4.29973336e-108, 4.29973336e-108, 2.60751533e-102, 2.54273296e-091,
1.73718699e-081, 1.78558513e-071, 7.69818338e-062, 3.21481369e-051,
4.08414092e-042, 1.02893059e-031, 1.68878756e-022, 9.30929426e-013,
6.07617963e-004, 4.26511597e-001, 4.11403958e-001, 3.97826322e-001,
3.85918291e-001, 3.75229382e-001, 3.65412852e-001, 3.55821412e-001,
3.46419015e-001, 3.36191477e-001, 3.21567653e-001, 2.95056542e-001,
2.50993145e-001, 2.01254644e-001, 1.48601129e-001, 1.06782644e-001,
8.22594510e-002, 6.81030579e-002, 6.14814781e-002, 5.84970230e-002,
5.67552028e-002, 5.57849893e-002, 5.51903111e-002, 5.47921392e-002,
5.45973892e-002, 5.46478216e-002, 5.51690400e-002, 5.65980264e-002,
6.01103560e-002, 6.69975776e-002, 7.91225954e-002, 9.65514835e-002,
1.19148307e-001, 1.45231813e-001, 1.70189956e-001, 1.87579580e-001,
1.94304897e-001, 1.91326738e-001, 1.82329298e-001, 1.70803906e-001,
1.58474983e-001, 1.46721155e-001, 1.35617280e-001, 1.25038591e-001,
1.15529107e-001, 1.07227234e-001, 1.00055395e-001, 9.40184888e-002,
8.87874942e-002, 8.42316818e-002, 8.03628254e-002, 7.68211955e-002,
7.38822235e-002, 7.12679660e-002, 6.90273583e-002, 6.71634120e-002,
6.56300906e-002, 6.44448577e-002, 6.35823630e-002, 6.30504158e-002,
6.27257844e-002, 6.25715395e-002, 6.25192823e-002, 6.24301850e-002,
6.21080833e-002, 6.13244652e-002, 5.96335775e-002, 5.62298814e-002,
5.06892404e-002, 4.39435561e-002, 3.61322837e-002, 2.95476339e-002,
2.22805846e-002, 1.76202673e-002, 1.35929212e-002, 1.10279017e-002,
8.99408151e-003, 8.09607630e-003, 7.45508561e-003, 7.01784166e-003,
6.53708257e-003, 6.05733318e-003, 5.67419725e-003, 5.57460127e-003,
5.39657231e-003, 5.25558922e-003, 5.00739756e-003, 4.77771513e-003,
4.52293881e-003, 4.46404801e-003, 4.43183561e-003, 4.36710595e-003,
4.34497251e-003, 4.33777321e-003, 4.33750480e-003, 4.34815132e-003,
4.35381436e-003, 4.37988753e-003, 4.40853212e-003, 4.44008892e-003,
4.51207558e-003, 4.64149422e-003, 4.62610829e-003, 4.70082552e-003,
4.70728474e-003, 4.97849787e-003, 5.12387119e-003, 5.28261779e-003,
5.61270114e-003, 5.69207572e-003, 6.11751436e-003, 6.67975518e-003,
6.99526904e-003, 8.03789689e-003, 9.27481729e-003, 1.12738856e-002,
1.30966233e-002, 1.61618631e-002, 2.18832292e-002, 2.91222904e-002,
3.86533975e-002, 4.94338091e-002, 6.30771298e-002, 7.52901028e-002,
8.35986088e-002, 9.01884239e-002, 9.54353519e-002, 1.00083956e-001,
1.06401712e-001, 1.14224480e-001, 1.21437139e-001, 1.26648229e-001,
1.26567880e-001, 1.17041648e-001, 9.77735964e-002, 7.75945929e-002,
6.17437629e-002, 4.85078347e-002, 3.45710618e-002, 2.78595107e-002,
2.61338899e-002, 2.31751112e-002, 2.09671528e-002, 2.06364640e-002,
1.98910548e-002, 1.85143380e-002, 1.48941638e-002, 1.27522929e-002,
9.06709998e-003, 8.49868898e-003, 7.03425391e-003, 5.86816075e-003,
7.03425995e-003, 6.17825866e-003, 4.43639282e-003, 3.94333531e-003,
3.59470289e-003, 3.70687910e-003, 3.22588540e-003, 3.15120745e-003,
3.03384853e-003, 3.53238172e-003, 2.82805939e-003, 2.35046818e-003,
2.23738426e-003, 2.37615648e-003, 2.16681655e-003, 2.05236781e-003,
1.97743996e-003, 1.92547858e-003, 1.91249998e-003, 1.81028533e-003,
1.67730222e-003, 1.65436438e-003, 1.63862155e-003, 1.63960668e-003,
1.59191586e-003, 1.59227881e-003, 1.59549592e-003, 1.58596922e-003,
1.58824034e-003, 1.58876602e-003, 1.58687153e-003, 1.58932645e-003,
1.58630420e-003, 1.58463618e-003, 1.59841185e-003, 1.60494712e-003,
1.61068184e-003, 1.62861231e-003, 1.64915167e-003, 1.68966233e-003,
1.69669747e-003, 1.69105048e-003, 1.74747130e-003, 1.72888322e-003,
1.79827908e-003, 1.81268084e-003, 1.87312179e-003, 1.96907693e-003,
1.95794629e-003, 2.04919398e-003, 2.17728458e-003, 2.17367417e-003,
2.32033584e-003, 2.63985146e-003, 2.84772075e-003, 3.02278650e-003,
3.21960462e-003, 3.44791346e-003, 4.22557078e-003, 4.59440705e-003,
5.34168990e-003, 6.47641734e-003, 7.35271484e-003, 8.53755232e-003,
9.75795967e-003, 1.18906265e-002, 1.35775955e-002, 1.56557269e-002,
1.83392075e-002, 2.03350860e-002, 2.24505640e-002, 2.51177313e-002,
2.86575272e-002, 3.38188665e-002, 4.30533182e-002, 5.45906007e-002,
6.88020654e-002, 8.54140602e-002, 1.03719576e-001, 1.22651166e-001]),
'Integral Capacity': array([-1.20331468e-03, -1.50706328e-03, -1.83436994e-03, -2.18684671e-03,
-2.56617991e-03, -2.73595525e-03, -3.21794441e-03, -3.34931617e-03,
-3.35849118e-03, -4.07398325e-03, -4.61092812e-03, -4.52855836e-03,
-5.02336824e-03, -5.24878233e-03, -6.28389728e-03, -5.82285796e-03,
-7.17298897e-03, -6.84056176e-03, -7.75241371e-03, -7.49782433e-03,
-6.70070920e-03, -7.51228594e-03, -7.50614485e-03, -7.26184410e-03,
-7.12025459e-03, -7.06089503e-03, -7.29049496e-03, -7.10729564e-03,
-6.65647152e-03, -6.50220065e-03, -6.52056106e-03, -6.01540693e-03,
-4.79289759e-03, -4.71807239e-03, -4.44769789e-03, -3.65112213e-03,
-3.16712199e-03, -2.24934036e-03, -1.45326694e-03, -1.16652891e-03,
-8.92684860e-04, -7.62956155e-04, -7.88299065e-04, -8.63291875e-04,
-8.79325357e-04, -1.31010688e-03, -1.69203474e-03, -2.44936901e-03,
-3.13182501e-03, -3.88509855e-03, -4.27057697e-03, -4.68354645e-03,
-5.21255310e-03, -5.82288708e-03, -6.32332524e-03, -6.85208924e-03,
-7.04861362e-03, -7.04653536e-03, -6.75059088e-03, -6.54560715e-03,
-6.12760688e-03, -5.92643393e-03, -5.93945642e-03, -5.73160103e-03,
-5.44701862e-03, -5.17221836e-03, -4.81425795e-03, -4.63448419e-03,
-4.51116777e-03, -4.30324268e-03, -4.46417691e-03, -4.23849047e-03,
-4.35791985e-03, -4.39305647e-03, -4.38342174e-03, -4.44355249e-03,
-4.39561229e-03, -4.31697296e-03, -3.84183657e-03, -3.78982949e-03,
-3.72866871e-03, -3.21991207e-03, -3.16387081e-03, -2.83964756e-03,
-2.44921824e-03, -2.35903040e-03, -2.39403976e-03, -2.25589671e-03,
-1.91643490e-03, -1.83707597e-03, -1.47792171e-03, -1.75018987e-03,
-1.31555829e-03, -1.40027570e-03, -1.13436142e-03, -1.15293837e-03,
-6.29794291e-04, -5.19478695e-04, -3.99616821e-04, -4.95830615e-04,
-5.75099433e-04, -5.41697011e-04, -1.56993069e-04, -3.01972782e-04,
-2.62564693e-04, -5.30256505e-04, -6.08604565e-04, -9.52823507e-04,
-3.15415476e-04, -2.06753810e-04, -5.81724148e-04, -3.69806762e-04,
-5.26507509e-04, 2.30284179e-05, -3.70040315e-04, -1.08545108e-04,
-3.50762033e-04, -2.74776104e-04, -2.44799160e-04, -4.45585575e-04,
-6.11528936e-04, 6.47390424e-05, -3.00120095e-04, -2.44134766e-05,
-8.78211185e-04, -3.90297192e-04, -3.84559559e-04, -7.00034130e-04,
-1.52838812e-04, -7.43501229e-04, -8.37892322e-04, -4.17895573e-04,
-1.19459440e-03, -1.16410608e-03, -1.52732652e-03, -1.15159819e-03,
-1.61730381e-03, -2.40578575e-03, -2.46254362e-03, -2.81509981e-03,
-3.05592882e-03, -4.34735649e-03, -5.59666860e-03, -6.70766520e-03,
-9.22172522e-03, -9.42064488e-03, -8.59246247e-03, -1.14517332e-02,
-1.40876159e-02, -1.40474458e-02, -1.42592921e-02, -1.47330489e-02,
-1.37766153e-02, -1.27857368e-02, -1.01420249e-02, -7.88517968e-03,
-7.41869997e-03, -1.00324114e-02, -6.53324696e-03, -1.90691502e-03,
-3.30368791e-03, -2.27787150e-03, -3.17039686e-04, -6.89606945e-04,
-1.18508609e-03, -2.68151318e-03, -1.41072103e-03, -2.40747989e-03,
-3.94486465e-04, -1.08686756e-03, -9.80471940e-04, 9.80476699e-04,
-7.06095334e-04, -1.73748246e-03, -6.16629468e-04, -4.91725507e-04,
1.64223967e-04, -7.53628710e-04, -1.30270588e-04, -2.13687314e-04,
8.39405457e-04, -1.24512858e-03, -1.15926340e-03, -3.42385620e-04,
4.15488321e-04, -6.49076829e-04, -4.20515887e-04, -3.11397278e-04,
-2.37960647e-04, -6.28077155e-05, -5.56283848e-04, -1.01556758e-03,
-2.47570323e-04, -1.96396079e-04, 1.31169166e-05, -9.40953073e-04,
1.33894877e-05, 1.06952475e-04, -4.29294614e-04, 1.48018904e-04,
2.68615934e-05, -1.07539324e-04, 1.34385463e-04, -1.74774906e-04,
-2.02477498e-04, -8.46152976e-04, -1.65488862e-04, -1.24481555e-04,
-3.19515364e-04, -2.93470347e-04, -4.64475416e-04, -7.07280833e-05,
5.65870769e-05, -5.11342843e-04, 1.56735897e-04, -5.43239084e-04,
-1.00620969e-04, -3.89632933e-04, -5.37802718e-04, 5.83529498e-05,
-4.53521695e-04, -5.59836751e-04, 1.47899130e-05, -5.63810671e-04,
-1.03327355e-03, -5.73933241e-04, -4.40121887e-04, -4.57094552e-04,
-4.89458800e-04, -1.43221410e-03, -5.89066543e-04, -1.07440482e-03,
-1.42520686e-03, -9.91443113e-04, -1.24787813e-03, -1.22064280e-03,
-2.08496770e-03, -1.69374221e-03, -2.26079602e-03, -3.44590274e-03,
-3.12113950e-03, -3.81549459e-03, -5.07246126e-03, -6.24614682e-03,
-7.64842576e-03, -1.06952123e-02, -1.03842182e-02, -1.04283528e-02,
-1.04633960e-02, -1.04916191e-02, -1.05148417e-02]),
'Integral Voltage': array([0.00243164, 0.00230473, 0.00219746, 0.00210311, 0.00201965,
0.0019441 , 0.00187546, 0.00181216, 0.00175362, 0.00169893,
0.00164772, 0.0015994 , 0.00155373, 0.00151032, 0.00146899,
0.00142946, 0.00139162, 0.00135525, 0.00132025, 0.00128649,
0.00125387, 0.00122229, 0.00119169, 0.00116196, 0.00113308,
0.00110496, 0.00107757, 0.00105087, 0.00102485, 0.00099964,
0.00097544, 0.00095337, 0.00093434, 0.00091928, 0.00090785,
0.00089881, 0.00089157, 0.00088537, 0.00087999, 0.00087509,
0.00087058, 0.00086628, 0.00086215, 0.00085807, 0.000854 ,
0.00084983, 0.00084553, 0.00084096, 0.00083606, 0.0008306 ,
0.00082446, 0.00081726, 0.00080872, 0.00079836, 0.00078606,
0.00077236, 0.00075791, 0.00074383, 0.00073046, 0.00071806,
0.00070664, 0.00069612, 0.00068643, 0.00067746, 0.00066913,
0.00066134, 0.00065405, 0.00064716, 0.00064063, 0.00063441,
0.00062847, 0.00062275, 0.00061725, 0.00061191, 0.00060672,
0.00060165, 0.0005967 , 0.00059183, 0.00058704, 0.00058229,
0.00057759, 0.00057292, 0.00056826, 0.00056361, 0.00055896,
0.00055438, 0.00054995, 0.00054601, 0.00054276, 0.00054028,
0.00053842, 0.00053695, 0.00053578, 0.00053479, 0.00053395,
0.00053321, 0.00053255, 0.00053195, 0.0005314 , 0.00053089,
0.00053041, 0.00052996, 0.00052954, 0.00052913, 0.00052874,
0.00052836, 0.00052799, 0.00052764, 0.0005273 , 0.00052695,
0.00052662, 0.00052629, 0.00052596, 0.00052564, 0.00052532,
0.00052499, 0.00052467, 0.00052434, 0.00052402, 0.00052369,
0.00052335, 0.00052301, 0.00052266, 0.0005223 , 0.00052193,
0.00052155, 0.00052115, 0.00052074, 0.00052031, 0.00051985,
0.00051936, 0.00051883, 0.00051827, 0.00051764, 0.00051695,
0.00051617, 0.00051527, 0.00051419, 0.00051289, 0.00051119,
0.00050892, 0.00050566, 0.00050116, 0.00049557, 0.0004892 ,
0.0004824 , 0.00047518, 0.00046753, 0.00045941, 0.00045081,
0.00044172, 0.00043235, 0.00042294, 0.00041432, 0.0004069 ,
0.00040091, 0.00039617, 0.00039228, 0.00038907, 0.0003863 ,
0.00038389, 0.00038174, 0.00037982, 0.00037808, 0.00037654,
0.00037519, 0.00037404, 0.00037308, 0.00037229, 0.00037163,
0.00037106, 0.00037058, 0.00037017, 0.0003698 , 0.00036947,
0.00036917, 0.0003689 , 0.00036865, 0.00036842, 0.0003682 ,
0.000368 , 0.00036781, 0.00036763, 0.00036745, 0.00036729,
0.00036713, 0.00036697, 0.00036682, 0.00036667, 0.00036653,
0.00036639, 0.00036626, 0.00036613, 0.00036601, 0.00036588,
0.00036576, 0.00036564, 0.00036552, 0.00036539, 0.00036527,
0.00036514, 0.00036502, 0.0003649 , 0.00036478, 0.00036467,
0.00036455, 0.00036444, 0.00036432, 0.0003642 , 0.00036409,
0.00036396, 0.00036384, 0.00036371, 0.00036358, 0.00036345,
0.00036331, 0.00036317, 0.00036304, 0.00036289, 0.00036275,
0.00072504, 0.00036228, 0.00036211, 0.00036193, 0.00036175,
0.00036155, 0.00072245, 0.00036087, 0.00036061, 0.00036033,
0.00036002, 0.00035968, 0.00035929, 0.00035884, 0.00035833,
0.00035774, 0.00035703, 0.00035619, 0.00035519, 0.00035402,
0.00035268, 0.00035117, 0.00034951, 0.00034768, 0.00034568,
0.00034343, 0.0003409 , 0.00033793, 0.00033443, 0.00033 ,
0.00032426])}
We can access tabulated capacity vs OCP data from the MSMR callback
outputs = results.callbacks["MSMRHalfCell"].callbacks[0].fit_results_["outputs"]
q = outputs["Capacity [A.h]"]
U = outputs["Voltage [V]"]
ocp_fit_data = pd.DataFrame({"Capacity [A.h]": q, "Voltage [V]": U})
ocp_fit_data.head()
Capacity [A.h] | Voltage [V] | |
---|---|---|
0 | 0.036591 | 0.570425 |
1 | 0.046710 | 0.556259 |
2 | 0.057618 | 0.542092 |
3 | 0.069368 | 0.527926 |
4 | 0.082019 | 0.513760 |
Fit OCP as a function of stoichiometry¶
Now, we directly fit a function \(U(x)\) to the pseudo-OCP data.
First, we define the function and initial guesses for the parameters.
def U_half_cell(theta):
u00 = pybamm.Parameter("u00_pos")
u10 = pybamm.Parameter("u10_pos")
u11 = pybamm.Parameter("u11_pos")
u20 = pybamm.Parameter("u20_pos")
u21 = pybamm.Parameter("u21_pos")
u22 = pybamm.Parameter("u22_pos")
u30 = pybamm.Parameter("u30_pos")
u31 = pybamm.Parameter("u31_pos")
u32 = pybamm.Parameter("u32_pos")
u40 = pybamm.Parameter("u40_pos")
u41 = pybamm.Parameter("u41_pos")
u42 = pybamm.Parameter("u42_pos")
u_eq = (
u00
+ u10 * pybamm.exp(-u11 * theta)
+ u20 * pybamm.tanh(u21 * (theta - u22))
+ u30 * pybamm.tanh(u31 * (theta - u32))
+ u40 * pybamm.tanh(u41 * (theta - u42))
)
return u_eq
ocp_param_init = {
"u00_pos": 0.2,
"u10_pos": 2,
"u11_pos": 30,
"u20_pos": -0.1,
"u21_pos": 30,
"u22_pos": 0.1,
"u30_pos": -0.1,
"u31_pos": 30,
"u32_pos": 0.3,
"u40_pos": -0.1,
"u41_pos": 30,
"u42_pos": 0.6,
}
Then we set up our DataFit
object and fit the data.
# Set up Parameter objects to fit
ocp_params = {k: iwp.Parameter(k, initial_value=v) for k, v in ocp_param_init.items()}
# Add the functional form of the OCP
ocp_params = {"Positive electrode OCP [V]": U_half_cell, **ocp_params}
# Use the experimental capacity to map between capacity in the experiment and the
# stoichiometry. In practice we would calculate the capacity from other means,
# (e.g. electrode loading) or use the MSMR model to fit the electrode capacity.
known_parameter_values = {"Positive electrode capacity [A.h]": Q_max_data}
# Set up objective and fit
objective = iwp.objectives.OCPHalfCell(
"positive",
ocp_data,
)
ocp = iwp.DataFit(objective, parameters=ocp_params)
# Fit
params_fit_ocp = ocp.run(known_parameter_values)
# Plot
_ = ocp.plot_fit_results()

Then, we look at the fitted parameters.
params_fit_ocp
Result(
Positive electrode OCP [V]: <function U_half_cell at 0x75a0bc1744a0>
u00_pos: 0.26766
u10_pos: 0.148291
u11_pos: 21.9377
u20_pos: -0.115899
u21_pos: 17.9201
u22_pos: 0.0648092
u30_pos: -0.0381474
u31_pos: 17.4306
u32_pos: 0.246712
u40_pos: -0.0194789
u41_pos: 32.1578
u42_pos: 0.593834
)