# Amplitude of the Voltage output after cycles is decreased even without aging?

**URL:** <https://pybamm.discourse.group/t/amplitude-of-the-voltage-output-after-cycles-is-decreased-even-without-aging/127>\
**Category:** PyBaMM Q&A\
**Created:** [27 January 2025 18:44 UTC](https://pybamm.discourse.group/t/amplitude-of-the-voltage-output-after-cycles-is-decreased-even-without-aging/127 "2025-01-27T18:44:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Notslytherin1](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@Notslytherin1](https://pybamm.discourse.group/u/Notslytherin1)\
**Post date:** [27 January 2025 18:44 UTC](https://pybamm.discourse.group/t/amplitude-of-the-voltage-output-after-cycles-is-decreased-even-without-aging/127/1 "2025-01-27T18:44:30Z")

</div>

Dear PyBaMM community,

I’m trying to apply a current profile on my model, after scaling up the widht to match the actual capacity of the cell. Then i noticed that the voltage output of the model is deviated after cycles and also its amplitude got decreased (As mentionned in the figure attached) even-thought the aging branch is excluded from the model.  
Could someone please help me understand why this problem is happening?

 ![image](https://global.discourse-cdn.com/free1/uploads/pybamm/original/1X/9f46c09835d7b2200a650118b7ec0dd626a258de.jpeg)  
This will be very apperciated.

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![Notslytherin1](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@Notslytherin1](https://pybamm.discourse.group/u/Notslytherin1)\
**Post date:** [28 January 2025 16:16 UTC](https://pybamm.discourse.group/t/amplitude-of-the-voltage-output-after-cycles-is-decreased-even-without-aging/127/2 "2025-01-28T16:16:39Z")

</div>

**Code:**

import pybamm  
import pandas as pd  
import numpy as np  
import matplotlib.pyplot as plt  
from sklearn.metrics import mean\_squared\_error

# Set logging level

pybamm.set\_logging\_level(“WARNING”)

# Create model

model = pybamm.lithium\_ion.DFN(  
options={  
“cell geometry”: “pouch”,  
}  
)

# Create parameter set

parameter\_values = pybamm.ParameterValues(“OKane2022”)

# Calculate total width

parameter\_values.update({  
# Cell geometry

```
    "Nominal cell capacity [A.h]": 65,
    "Electrode width [m]": 1.58 * 62/5,
    "Current function [A]": 65.0,

```

})

# Import drive cycle

drive\_cycle = pd.read\_csv(  
r"C:\Users\OO000009\Desktop------.csv",  
comment=“#”,  
header=None  
).to\_numpy()  
drive\_cycle[:, 1] = -drive\_cycle[:, 1]

# Load experimental data

experimental\_data = pd.read\_csv(r"C:\Users\OO000009\Desktop-----.csv")  
exp\_time\_s = experimental\_data[“Total Time (Seconds)”]  
exp\_voltage\_mV = experimental\_data[“Voltage (mV)”]

# Convert voltage from mV to V

exp\_voltage\_V = exp\_voltage\_mV / 1000

# Skip the first 3200 rows and reset time to start from 0

exp\_time\_s = exp\_time\_s.iloc[3200:].reset\_index(drop=True)  
exp\_voltage\_V = exp\_voltage\_V.iloc[3200:].reset\_index(drop=True)  
exp\_time\_s = exp\_time\_s - exp\_time\_s.iloc[0] # Reset time to start from 0

# Create drive cycle experiment

def create\_experiment(num\_cycles):  
# Create drive cycle step using the current function  
drive\_cycle\_step = pybamm.step.current(drive\_cycle)

```
# Create cycling experiment
cycle_steps = [
    (drive_cycle_step,) # Add rest between cycles
] * num_cycles

return pybamm.Experiment(cycle_steps)

```

# Use drive cycle experiment

experiment = create\_experiment(num\_cycles=100)

# Solver settings

solver = pybamm.CasadiSolver(  
mode=“safe”,  
atol=1e-6, # Stricter tolerance  
rtol=1e-6,  
dt\_max=600, # Smaller timestep  
)

# Create and run simulation

sim = pybamm.Simulation(  
model,  
parameter\_values=parameter\_values,  
experiment=experiment,  
solver=solver  
)

print(“Starting simulation…”)  
solution = sim.solve(initial\_soc=0.3)

# Extract data for plotting

voltage = solution[“Terminal voltage [V]”].entries  
time = solution[“Time [s]”].entries

# Interpolate experimental data to match simulation time points

exp\_voltage\_interp = np.interp(time, exp\_time\_s, exp\_voltage\_V)

# Calculate RMSE between simulated and experimental voltage

rmse = np.sqrt(mean\_squared\_error(exp\_voltage\_interp, voltage))  
print(f"Root Mean Squared Error (RMSE) between simulated and experimental voltage: {rmse:.4f} V")

# Plot voltage comparison

plt.figure(figsize=(12, 6))  
plt.plot(time, voltage, label=“Simulated Voltage”, color=“royalblue”, linewidth=2.5)  
plt.plot(time, exp\_voltage\_interp, label=“Experimental Voltage”, color=“darkorange”, linewidth=2.5)  
plt.xlabel(“Time [s]”)  
plt.ylabel(“Voltage [V]”)  
plt.title(“Voltage Comparison”)  
plt.legend()  
plt.grid(True)  
plt.show()

# Track capacity over cycles

cycle\_numbers =   
capacities =   
capacity\_losses =

# Check if capacity data exists in solution summary variables

if “Capacity [A.h]” in solution.summary\_variables:  
initial\_capacity = solution.summary\_variables[“Capacity [A.h]”][0]  
capacities = solution.summary\_variables[“Capacity [A.h]”]  
capacity\_losses = ((initial\_capacity - np.array(capacities)) / initial\_capacity) \* 100

```
# Print capacity values for each cycle
print("Cycle-wise capacities and capacity losses:")
for cycle_number, (capacity, capacity_loss) in enumerate(zip(capacities, capacity_losses), start=1):
    print(f"Cycle {cycle_number}: Capacity = {capacity:.2f} Ah, Capacity Loss = {capacity_loss:.2f} %")

# Plot results
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 10))

# Capacity plot
ax1.plot(range(1, len(capacities) + 1), capacities, 'b-o')
ax1.set_xlabel('Cycle Number')
ax1.set_ylabel('Capacity [Ah]')
ax1.grid(True)
ax1.set_title('Capacity vs Cycle Number')

# Capacity loss plot
ax2.plot(range(1, len(capacities) + 1), capacity_losses, 'r-o')
ax2.set_xlabel('Cycle Number')
ax2.set_ylabel('Capacity Loss [%]')
ax2.grid(True)
ax2.set_title('Capacity Loss vs Cycle Number')

plt.tight_layout()
plt.show()

```

else:  
print(“Capacity data is not available in the solution’s summary variables.”)

```
# Calculate RMSE between simulated and experimental voltage

```

rmse = np.sqrt(mean\_squared\_error(exp\_voltage\_interp, voltage))  
print(f"Root Mean Squared Error (RMSE) between simulated and experimental voltage: {rmse:.4f} V")
