pybamm-team / liionpack

A battery pack simulation tool that uses the PyBaMM framework
https://liionpack.readthedocs.io/en/latest/
MIT License
83 stars 26 forks source link

Problem faced in liionpack simulation #185

Closed Ashuprateek closed 1 year ago

Ashuprateek commented 2 years ago

I'm facing some problems regarding the experiment simulation as "keyerror". I'm new to this programing and can't crack it. Please let me know where I'm writing wrong code? Thanks in advance Untitled.pdf

TomTranter commented 2 years ago

Hi @Ashuprateek looking quickly at the code the length of the input array is not the same as number of cells

Ashuprateek commented 2 years ago

Thanks @TomTranter for your valuable reply. You mean to say, in the .csv file , there are more entries for each label than 77 (The number of cells)? Sorry, I didn't get your point.

Ashuprateek commented 2 years ago

I'll explain my al the queries:

  1. The above problem if I need more than one output variable from the simulation and similar kind of problem if I enter these variables for graphical analysis as shown in the above file.
  2. The second query is: I have real time data which I want to implement for the current values, as well as wish to add temp probe 1(ambient temperature) and temp probe 2(battery temperature ) in the experiment, how I can apply that?

(###.csv file and pdf file attached for reference. If I can implement my second query, I can give real time data to all the variables and also can add or delete variables in the experiment as per my requirement.)

Mainly I wish to program a BMS for thermal simulation of the battery pack working on real time data which I can implement later in physical model. Please let me know the possible ideas to perform this task. Thanks in advance!

11P7S Thermal Simulation.pdf

Samsung-50E 7S11P.csv

TomTranter commented 2 years ago

Ah sorry, on looking again I see that the length of inputs is ok actually. I was referring to the htc. If you can post a self contained example of the problem here that I can reproduce and debug I can take a look but I can't work with pdf files

Ashuprateek commented 2 years ago
#Using Real time data 
try:
    import liionpack as lp
except:
    !pip install -q git+https://github.com/pybamm-team/liionpack.git@main
    import liionpack as lp
import pybamm
import numpy as np
import os
import pandas as pd
import matplotlib.pyplot as plt

nproc = os.cpu_count()
os.chdir(pybamm.__path__[0] + "/..")

# import Real time data from file
Real_time_data = pd.read_csv(r"C:\Users\Engineering\Desktop\Data Science/Samsung-50E 7S11P.csv", comment="#",
                             header=None).to_numpy()

# Current vs Time stamp graphical Analysis
with plt.rc_context(lp.lp_context()): 
    plt.figure(figsize=(12, 10))
    plt.plot(Real_time_data[:, 0], Real_time_data[:, 1]) # The first column is the time stamp and the second is the current.

#Thermal Simulation : Overview of Simulation process and Steps 
try:
    import liionpack as lp
except:
    !pip install -q git+https://github.com/pybamm-team/liionpack.git@main
    import liionpack as lp
import pybamm
import numpy as np
import inspect   
lines = inspect.getsource(lp.thermal_simulation)
print(lines)

Np = 11
Ns = 7
I_mag = 2.0
Rsmall = 1e-6
OCV_init = 4.0
Nspm = Np * Ns
# Generate the netlist
netlist = lp.setup_circuit(Np=Np, Ns=Ns, Rb=Rsmall, Rc=Rsmall, Ri=3e-2, I=I_mag, V=OCV_init)
# Define additional output variables
output_variables = [
    "Volume-averaged cell temperature [K]",
]
# Define a cycling experiment using PyBaMM
experiment = pybamm.Experiment(                                           #experiment for constant charge
    [                
        "Charge at 2 A for 30 minutes",             
        "Rest for 15 minutes",
        "Discharge at 2 A for 30 minutes",
        "Rest for 15 minutes",
     ]
    * 3,
    period="10 seconds",
)
experiment = pybamm.Experiment(                                             #experiment for constant discharge
    [
        (
        "Discharge at 2 A for 30 minutes",             
        "Rest for 15 minutes",
        "Charge at 2 A for 30 minutes",
        "Rest for 15 minutes",
        )
    ]
    * 3,
    period="10 seconds",
)
# Define the PyBaMM parameters
parameter_Sets = pybamm.parameter_sets.Chen2020
parameter_values = pybamm.ParameterValues("Chen2020")
parameter_values.update(
    {"Total heat transfer coefficient [W.m-2.K-1]": "[input]"}
)
htc = np.random.random(Nspm) * 50.0
inputs = {"Total heat transfer coefficient [W.m-2.K-1]": htc}
# Solve the pack
output = lp.solve(
    netlist=netlist,
    sim_func=lp.thermal_simulation,
    parameter_values=parameter_values,
    experiment=experiment,
    output_variables=output_variables,
    inputs=inputs,
    initial_soc=0.5,
    nproc=nproc
)
experiment.operating_conditions   # View the experiment steps
# The default included data is the 'Cell current [A]','Terminal voltage [V]',and 'Measured battery open circuit voltage [V]'.
SPMe = pybamm.models.full_battery_models.lithium_ion.SPMe()
SPMe.variable_names()

#use plot_cell_data_image to produce a snapshot of the system in image format which has the same dimensions as the number #of cells in parallel and series.
data = output["Volume-averaged cell temperature [K]"][-1, :]
lp.plot_cell_data_image(netlist, data, tick_labels=False, figsize=(15, 6))

data = output["Terminal voltage [V]"][-1, :]
lp.plot_cell_data_image(netlist, data, tick_labels=False, figsize=(15, 6))

lp.plot_output(output)
Ashuprateek commented 2 years ago

Sir this is my code and the target or objective of the total code, I already explained in my above message. So mainly I have to solve my 2 queries (mentioned above) using this code and then I can go further and explore more application in this code.

Frankly speaking, I have no idea about self contained example but if you are mentioning similar example like this, sorry I don't have any similar work related to this.

TomTranter commented 2 years ago

Hi @Ashuprateek I'm a bit confused myself now. So you fixed the original problem it seems with the ValueError: could not broadcast input array from shape (66,77) into shape (7,77. The code you posted above seems to work. I don't understand your question about needing more than one output variable. You have more than one in a dictionary returned by the solve function. If you have real time data for the pack current you can define a drive cycle. There is an example on how to do that in the docs https://liionpack.readthedocs.io/en/latest/examples/05%20Drive%20cycles/

Ashuprateek commented 2 years ago

Hello Sir, no original problem is not fixed. Mainly i remove those parameters from the code (given in 1st pdf) which I want extra results. Till I run with this parameter output_variables = [ "Volume-averaged cell temperature [K]", ] it works but if I add more like : output_variables = [ "Volume-averaged cell temperature [K]", "Discharge capacity [A.h]", "Cell temperature [K]", ] , it start creating errors as shown in the pdf. Same applies for graphical plotting also. I am adding these parameters here in output by assuming that it will help me to give multiple graphs which is my main interest.

Secondly, if you see the csv file, I have so many current values and temp prob 1 and temp probe 2 values. I want to implement these values in the code (my second query) by some way so that I can get the battery behavior analysis based on these values and I wish to make further predictions for the battery behavior. If I can utilize somehow these values in the code to predict battery behavior, I can implement to get future analysis using Aging (SEI degradation code). I have no idea ,how to implement these csv file values. I hope I clear my point.

TomTranter commented 2 years ago

Ok I see the issue. It's the 'Cell temperature [K]' variable which is not a single value for each battery. Currently we only support exporting the x-averaged or volume-averaged variables or 0D variables in space. As for the second question are you talking about actually applying different currents to different strings or simply changing the terminal current for the pack at each time step. If you want to specify string currents then you can't do that but could be something we develop if you just want to apply a drive cycle then the above example should help

TomTranter commented 1 year ago

Can I close this issue @Ashuprateek ?

Ashuprateek commented 1 year ago

Sure Sir

On Fri, Sep 16, 2022, 10:13 Tom Tranter @.***> wrote:

Can I close this issue @Ashuprateek https://github.com/Ashuprateek ?

— Reply to this email directly, view it on GitHub https://github.com/pybamm-team/liionpack/issues/185#issuecomment-1249058250, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2WK6SVZKGWDRMW2DGA3D6TV6QT2NANCNFSM576DXRYQ . You are receiving this because you were mentioned.Message ID: @.***>