ROVI-org / thevenin

A packaged Thevenin equivalent circuit model in Python.
2 stars 0 forks source link

<img alt='Logo' style='width: 75%; min-width: 250px; max-width: 500px;' src='https://github.com/ROVI-org/thevenin/blob/main/images/dark.png?raw=true#gh-dark-mode-only'/> <img alt='Logo' style='width: 75%; min-width: 250px; max-width: 500px;' src='https://github.com/ROVI-org/thevenin/blob/main/images/light.png?raw=true#gh-light-mode-only'/>


CI   tests   coverage   pep8

Summary

This package is a wrapper for the well-known Thevenin equivalent circuit model. The model is comprised of a single series reistor followed by any number of parallel RC pairs. Figure 1 below illustrates a circuit with 2 RC pairs; however, the model can be run with as few as zero, and as many as $N$.

2RC Thevenin circuit.
Figure 1: 2RC Thevenin circuit.

This system is governed by the evolution of the state of charge (SOC, -), RC overpotentials ($Vj$, V), cell voltage ($V{\rm cell}$, V), and temperature ($T_{\rm cell}$, K). SOC and $V_j$ evolve in time as

\begin{align}
  &\frac{d\rm SOC}{dt} = \frac{-I}{3600 Q_{\rm max}}, \\
  &\frac{dV_j}{dt} = -\frac{V_j}{R_jC_j} + \frac{I}{C_j},
\end{align}

where $I$ is the load current (A), $Q_{\rm max}$ is the maximum nominal cell capacity (Ah), and $R_j$ and $C_j$ are the resistance (Ohm) and capacitance (F) of each RC pair $j$. Note that the sign convention for $I$ is chosen such that positive $I$ discharges the battery (reduces SOC) and negative $I$ charges the battery (increases SOC). This convention is consistent with common physics-based models, e.g., the single particle model or pseudo-2D model. While not explicitly included in the equations above, $R_j$ and $Cj$ are functions of SOC and $T{\rm cell}$. The temperature increases while the cell is active according to

\begin{equation}
  mC_p\frac{dT_{\rm cell}}{dt} = \dot{Q}_{\rm gen} + \dot{Q}_{\rm conv},
\end{equation}

where $m$ is mass (kg), $Cp$ is specific heat capacity (J/kg/K), $Q{\rm gen}$ is the heat generation (W), and $Q_{\rm conv}$ is the convective heat loss (W). Heat generation and convection are defined by

\begin{align}
  &\dot{Q}_{\rm gen} = I \times (V_{\rm OCV}({\rm SOC}) - V_{\rm cell}), \\
  &\dot{Q}_{\rm conv} = hA(T_{\infty} - T_{\rm cell}),
\end{align}

where $h$ is the convecitive heat transfer coefficient (W/m2/K), $A$ is heat loss area (m2), and $T{\infty}$ is the air/room temperature (K). $V{\rm OCV}$ is the open circuit voltage (V) and is a function of SOC.

The overall cell voltage is

\begin{equation}
  V_{\rm cell} = V_{\rm OCV}({\rm SOC}) - \sum_j V_j - IR_0,
\end{equation}

where $R_0$ the lone series resistance (Ohm), as shown in Figure 1. Just like the other resistive elements, $R0$ is a function of SOC and $T{\rm cell}$.

Installation

We recommend using Anaconda to install this package due to the scikits-odes-sundials dependency, which is installed separately using conda install to avoid having to download and compile SUNDIALS locally. Please refer to the linked scikits-odes documentation if you prefer installing without using conda. Note that we plan to replace this dependency in a future release to streamline installation.

After cloning the repository, or downloading the files, use your terminal (MacOS/Linux) or Anaconda Prompt (Windows) to navigate into the folder with the pyproject.toml file. Once in the correct folder, execute the following commands:

conda create -n rovi python=3.12 scikits_odes_sundials -c conda-forge
conda activate rovi
pip install .

The first command creates a new Python environment named rovi. The environment will be set up using Python 3.12 and will install the scikits-odes-sundials dependency from the conda-forge channel. Feel free to use an alternate environment name and/or to specify a different Python version >= 3.9. Although the package supports multiple Python versions, development and testing is primarily done using 3.12. Therefore, if you have issues with another version, you should revert to using 3.12. The last two commands activate your new environment and install thevenin.

If you plan to make changes to the package, you may also want to consider installing in "editable" mode using the -e flag, and including the optional developer dependencies, using [dev], as shown below. If you plan to push any changes back into this repository, you should see the contributing section first.

pip install -e .[dev]

Get Started

The API is organized around three main classes that allow you to construct the model, define an experiment, and interact with the solution. A basic example for a constant-current discharge is given below. To see the documentation for any of the classes or their methods, use Python's built in help() function. You can also access the documentation by visiting the website hosted through GitHub pages. The website includes search functionality and more detailed examples compared to those included in the docstrings.

import thevenin

model = thevenin.Model()

expr = thevenin.Experiment()
expr.add_step('current_A', 75., (3600., 1.), limits=('voltage_V', 3.))

soln = model.run(expr)
soln.plot('time_h', 'voltage_V')

Notes:

Contributing

If you'd like to contribute to this package, please look through the existing issues. If the bug you've caught or the feature you'd like to add isn't already being worked on, please submit a new issue before getting started. You should also read through the developer guidelines.

Acknowledgements

This work was authored by the National Renewable Energy Laboratory (NREL), operated by Alliance for Sustainable Energy, LLC, for the U.S. Department of Energy (DOE). The views expressed in the repository do not necessarily represent the views of the DOE or the U.S. Government.

The motivation and funding for this project came from the Rapid Operational Validation Initiative (ROVI) sponsored by the Office of Electricity. The focus of ROVI is "to greatly reduce time required for emerging energy storage technologies to go from lab to market by developing new tools that will accelerate the testing and validation process needed to ensure commercial success." If interested, you can read more about ROVI here.