<jupyter_start><jupyter_text>4 Setting the initial SoC Setting the initial SoC for your pack is performed with an argument passed to the solve algorithm. Currently the same value is applied to each battery but in future it will be possible to vary the SoC across the pack.<jupyter_code>import liionpack as lp
import pybamm
import numpy as np
import matplotlib.pyplot as plt<jupyter_output>c:\users\tom\code\pybamm\pybamm\expression_tree\functions.py:204: RuntimeWarning: invalid value encountered in sign
  return self.function(*evaluated_children)<jupyter_text>Lets set up the most simple pack possible with 1 battery and very low busbar resistance to compare to a pure PyBaMM simulation<jupyter_code>Rsmall = 1e-6
netlist = lp.setup_circuit(Np=1, Ns=1, Rb=Rsmall, Rc=Rsmall, Ri=5e-2, V=4.0, I=1.0)
# Heat transfer coefficients
htc = np.ones(1) * 10
# PyBaMM parameters
chemistry = pybamm.parameter_sets.Chen2020
parameter_values = pybamm.ParameterValues(chemistry=chemistry)
# Cycling experiment
experiment = pybamm.Experiment(
    [
        (
            "Discharge at 1 A for 1000 s or until 3.3 V",
            "Rest for 1000 s",
            "Charge at 1 A for 1000 s or until 4.0 V",
            "Rest for 1000 s",
        )
    ]
    * 3, period="10 s"
)
SoC = 0.5
# Solve pack
output = lp.solve(netlist=netlist,
                  parameter_values=parameter_values,
                  experiment=experiment,
                  htc=htc, initial_soc=SoC)<jupyter_output>c:\users\tom\code\pybamm\pybamm\expression_tree\functions.py:204: RuntimeWarning: invalid value encountered in sign
  return self.function(*evaluated_children)
Solving Pack: 100%|███████████████████████████████████████████████████████████████| 1200/1200 [00:06<00:00, 191.77it/s]<jupyter_text>Let's compare to the PyBaMM simulation<jupyter_code>parameter_values = pybamm.ParameterValues(chemistry=chemistry)
parameter_values.update({"Total heat transfer coefficient [W.m-2.K-1]": 10.0})
sim = lp.create_simulation(parameter_values, experiment, make_inputs=False)
sol = sim.solve(initial_soc=SoC)
def compare(sol, output):
    # Get pack level results
    time = sol["Time [s]"].entries
    v_pack = output["Pack terminal voltage [V]"]
    i_pack = output["Pack current [A]"]
    v_batt = sol["Terminal voltage [V]"].entries
    i_batt = sol["Current [A]"].entries

    # Plot pack voltage and current
    _, (axl, axr) = plt.subplots(1, 2, tight_layout=True, figsize=(15, 10), sharex=True, sharey=True)
    axl.plot(time[1:], v_pack, color="green", label="simulation")
    axl.set_xlabel("Time [s]")
    axl.set_ylabel("Pack terminal voltage [V]", color="green")
    axl2 = axl.twinx()
    axl2.plot(time[1:], i_pack, color="black", label="simulation")
    axl2.set_ylabel("Pack current [A]", color="black")
    axl2.set_title("Liionpack Simulation")
    axr.plot(time, v_batt, color="red", label="simulation")
    axr.set_xlabel("Time [s]")
    axr.set_ylabel("Battery terminal voltage [V]", color="red")
    axr2 = axr.twinx()
    axr2.plot(time, i_batt, color="blue", label="simulation")
    axr2.set_ylabel("Battery current [A]", color="blue")
    axr2.set_title("Single PyBaMM Simulation")
compare(sol, output)<jupyter_output><empty_output><jupyter_text>Now lets start the simulation from a different state of charge<jupyter_code>SoC = 0.25
# Solve pack
output = lp.solve(netlist=netlist,
                  parameter_values=parameter_values,
                  experiment=experiment,
                  htc=htc, initial_soc=SoC)
compare(sol, output)<jupyter_output><empty_output><jupyter_text>Here we are still comparing to the PyBaMM simulation at 0.5 SoC and we can see that liionpack started at a lower voltage corresponding to a lower SoC.<jupyter_code>parameter_values = pybamm.ParameterValues(chemistry=chemistry)
parameter_values.update({"Total heat transfer coefficient [W.m-2.K-1]": 10.0})
sim = lp.create_simulation(parameter_values, experiment, make_inputs=False)
sol = sim.solve(initial_soc=SoC)<jupyter_output><empty_output><jupyter_text>Now we can re-run the PyBaMM simulation and compare again<jupyter_code>compare(sol, output)
lp.draw_circuit(netlist)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12652767792954708, 'fraction_numerical': 0.02564102564102564, 'mean_word_length': 4.602684563758389, 'pattern_counts': {'":': 2, '<': 24, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '1442', 'license': 'MIT', 'n_tokens_mistral': 1524, 'n_tokens_neox': 1405, 'n_words': 349, 'path': 'examples/notebooks/04 Initial SoC.ipynb', 'repo_name': 'brosaplanella/liionpack', 'size': '4173'}