COBRAPRO

COBRAPRO: A MATLAB toolbox for Physics-based Battery Modeling and Co-simulation Parameter Optimization - Published in JOSS (2025)

https://github.com/cobraprosimulator/cobrapro

Science Score: 93.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README and JOSS metadata
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software
Last synced: 6 months ago · JSON representation

Repository

Basic Info
  • Host: GitHub
  • Owner: COBRAPROsimulator
  • License: mit
  • Language: MATLAB
  • Default Branch: main
  • Size: 9.24 MB
Statistics
  • Stars: 22
  • Watchers: 2
  • Forks: 5
  • Open Issues: 4
  • Releases: 2
Created about 2 years ago · Last pushed about 1 year ago
Metadata Files
Readme License

README.md

COBRAPRO: A MATLAB toolbox for Physics-based Battery Modeling and Co-simulation Parameter Optimization

COBRAPRO (Co-simulation Battery Modeling for Accelerated Parameter Optimization) is a MATLAB software for physics-based modeling of lithium-ion batteries (LIB) with an embedded parameter identification routine. We aim to provide the battery modeling community with a versatile toolbox for calibrating battery models, a crucial process to achieve accurate simulation results for predicting real-world battery responses under various operating conditions.

Table of contents

What is COBRAPRO?

COBRAPRO implements the Dolye-Fuller-Newman (DFN) model, also known as the pseudo-two-dimensional (P2D) model, which is a high-fidelity LIB model considering the lithium-ion mass and charge conservation in the liquid electrolyte and solid electrodes, and Butler-Volmer kinetics. Parameter calibration, or identification, is a primary challenge in implementing the DFN model since the parameters such as geometric, transport, kinetic, concentration, and stoichiometric are often not known a prioi.

In response to this challenge, COBRAPRO allows users to identify parameters of any battery cells based on their experimental current-voltage profiles. COBRAPRO solves an optimization problem that minimizes the error between the experimental and simulated voltage and state-of-charge curves to identify the parameters of interest. Although the software employs particle swarm optimization (PSO) by default, users have the flexibility modify the code to implement other MATLAB optimization algorithms such as ga, fmincon, patternsearch, and more.

Why COBRAPRO?

Compared to existing open-source DFN packages like PyBaMM, LIONSIMBA, PETION, fastDFN, and MPET, only COBRAPRO and DEARLIBS include an integrated identification routine. COBRAPRO further distinguishes itself by enabling parameter identifiability analysis, allowing users to identify which parameters can be optimized based on the given data. Efficient computation is critical for parameter optimization, which requires numerous model simulations. COBRAPRO addresses this challenge with a fast solver and PSO parallel computing, offering model simulations up to three orders of magnitude faster than DEARLIBS and enhanced PSO performance through multicore processing.

Accompanying papers

For a comprehensive dive into the numerical methods, determination of consistent initial condition, and parameter optimization pipeline proposed in CORBAPRO, users are encouraged to check out our JES paper:

[1] S. Ha and S. Onori, “COBRAPRO: An Open-Source Software for the Doyle-Fuller-Newman Model with Co-Simulation Parameter Optimization Framework,” J. Electrochem. Soc., vol. 171, no. 9, p. 090522, Sep. 2024, doi: 10.1149/1945-7111/ad7292.

Our JOSS paper can also be viewed for additional information:

[2] S. Ha and S. Onori, “COBRAPRO: A MATLAB toolbox for Physics-based Battery Modeling and Co-simulation Parameter Optimization,” Apr. 16, 2024, arXiv: arXiv:2404.10022.

Software dependencies

  • MATLAB 2016a and later
  • MATLAB Global Optimization Toolbox
  • MATLAB Parallel Computing Toolbox
  • SUNDIALS 2.6.2
  • CasADi (MATLAB version)
  • Xcode (for macOS users only)
  • MinGW (for Window users only)

Installation section below shows how to install the required software.

Installation

  1. Download COBRAPRO by downloading the zip file or cloning this repository by typing in Terminal: git clone https://github.com/COBRAPROsimulator/COBRAPRO.git
  2. Download MATLAB if not installed already. Make sure to select both the Global Optimization Toolbox and Parallel Computing Toolbox during the installation process.

  3. Download SUNDIALS 2.6.2 and unzip the folder. Relocate the sundials-2.6.2 folder inside the COBRAPRO folder.

  4. Download the latest version of CasADi (MATLAB version) corresponding to your operating system. For Mac Apple Silicon users using the Apple Silicon version of MATLAB, download the Mac M1 version of CasADi. Unzip and move the CasADi folder inside the main COBRAPRO folder. Your COBRAPRO folder should now contain the sundials-2.6.2 and CasADi folders.

  5. Before we can install SUNDIALS, the following software are required to compile the mex files that will interface with the SUNDIALS IDA solver:

    • Mac users: Download Xcode application (can be downloaded from Apple’s App Store). Once Xcode[^1] is installed, proceed to accept the license agreement. This can be done by opening the Xcode application, which will launch a license agreement window and click the “Agree” icon, or type sudo xcodebuild -license accept in Terminal. If the license is not accepted, MATLAB may give an error such as “Xcode is installed, but its license has not been accepted”.
    • Window users: Download MinGW
  6. Now you are ready to run install_COBRAPRO.m, which is located in the main COBRAPRO folder. install_COBRAPRO.m will install SUNDIALS by calling the sundials-2.6.2/sundialsTB/install_STB.m file and automatically add the required folders to your MATLAB path. Run install_COBRAPRO.m and respond to the prompts displayed in the Command Window in the following manner:

MEX files will be compiled and built using the above options Proceed? (y/n) → Type y and hit enter

Compile CVODES interface? (y/n) → Type n and hit enter Compile IDAS interface? (y/n) → Type y and hit enter Compile KINSOL interface? (y/n) → Type n and hit enter MEX files were successfully created. Install toolbox? (y/n) → Type y and hit enter Specify the location where you wish to install the toolbox. The toolbox will be installed in a subdirectory "sundialsTB". Enter return to cancel the installation. Installation directory: → Just hit enter Type the name of your CasADi folder (case-sensitive): → Type the name of the CasADi folder exactly as it appears and hit enter

  1. Successful installation will output to the Command Window: COBRAPRO installed successfully! To get started, try running scripts in the Examples folder. ## Testing ##

Automated test codes are provided in test folder: - test_1_casadiCheck.m checks that CasADi is installed and working properly. Successful run will output to Command Window: test_1 successful: CasADi is working properly! - test_2_comsolValidation.m validates COBRAPRO against results generated from COMSOL Multiphysics[^2] as a benchmark. This ensures that COBRAPRO is installed properly and that the SUNDIALS IDA solver is working as expected. Successful validation will output to Command Window: test_2 successful: COBRAPRO is working as expected! Results validated against COMSOL. - test_3_psoCheck.m ensures that MATLAB's Global Optimization Toolbox and Parallel Computing Toolbox are installed, and makes sure that the PSO in parallel (required for parameter identification) is working correctly. Successful run will output to Command Window: test_3 successful: PSO in parallel is working as expected!

Examples

In the Examples folder, you will find example codes that will help you get started. * Examples/Cycling: examples showing how to perform battery cycling simulations using experimentally identified parameters * Examples/Cycling/cycle_CC.m: simulating constant current (CC) cycling experiments and result visualization (voltage, state-of-charge, internal variable curves) * Examples/Cycling/cycle_HPPC.m: simulating hybrid pulse power characterization (HPPC) profile and result visualization (voltage, state-of-charge, internal variable curves) * Examples/Cycling/cycle_UDDS.m: simulating driving cycle profile and result visualization (voltage, state-of-charge, internal variable curves) * Examples/Parameter_Identification_Routines: examples showing how to perform parameter identification using PSO → NOTE: In general, these scripts take a while to run. Using a processor with multiple cores, e.g., 12 or 24 cores, will significantly speed up the PSO. Also, PSO particle size and PSO exit conditions affect the PSO convergence accuracy and time.) * Examples/Parameter_Identification_Routines/DFN_pso_0_05C.m: parameter identification using C/20 discharge data * Examples/Parameter_Identification_Routines/DFN_pso_HPPC.m: parameter identification using HPPC data (given same number of PSO particles and PSO exit conditions, takes longer to run than DFN_pso_0_05C.m since HPPC takes much longer to run than C/20 discharge) * Examples/Parameter_Identification_Results: examples showing parameter identification results * Examples/Parameter_Identification_Results/DFN_pso_0_05C_identification.m: parameter identification results using C/20 discharge data * Examples/Parameter_Identification_Results/DFN_pso_HPPC_identification.m: parameter identification results using HPPC data * Examples/Parameter_Identification_Results/DFN_pso_UDDS_validation.m: parameter identification validation using UDDS data * Examples/Parameter_Identifiability_Analysis: examples showing how to perform LSA and correlation analysis to determine a subset of identifiable parameters for the given data * Examples/Parameter_Identifiability_Analysis/DFN_LSA_Corr_CC.m: LSA and correlation analysis on CC profile * Examples/Parameter_Identifiability_Analysis/DFN_LSA_Corr_HPPC.m: LSA and correlation analysis on HPPC profile

Examples

Refer to our API documentation page for a list of all the functions as scripts in CORBAPRO.

Contributing

We welcome contributions from the community to improve COBRAPRO! * To report bugs, ask questions, and get help, please open a new issue through the Github issues page. Be as specific as possible (including screenshots, sample codes) for efficient communication. * To make changes to the code or add new functions, 1) fork the repo and create your branch from main, 2) make your changes to the code, and 3) open a Pull request. Once approved, your contribution will be merged into the master branch. * For general discussions and project ideas, open a new Discussions through the Github issues page. You can also contact Sara Ha (sungyeon.sara.ha@stanford.edu).

Known issues

  1. To run COBRAPRO, only the SUNDIALS IDAS interface is required. In Installation step 4, if you install the KINSOL interface, you may run into the following issue: Error using mex COBRAPRO/sundials-2.6.2/sundialsTB/kinsol/kim/src/kim.c:687:24: error: non-void function 'KIM_Stats' should return a value [-Wreturn-type] if (kimData == NULL) return; COBRAPRO/sundials-2.6.2/sundialsTB/kinsol/kim/src/kim.c:687:24: error: non-void function 'KIM_Free' should return a value [-Wreturn-type] return; 2 errors generated. To fix this issue, please go to sundials-2.6.2/sundialsTB/kinsol/kim/src/kim.c and modify line 687 to if (kimData == NULL) return NULL; and modify line 815 to return NULL;
  2. If you happen to run into the following error when installing/running COBRAPRO: Error using mex 'idm.mexmaca64' locked by mexLock API. This seems to occur when MATLAB is trying to compile the mex files and mexLock is triggered. To resolve the issue, please restart MATLAB. 
  3. For Mac users, when running install_COBRAPRO.m to install COBRAPRO, if you run into the following error: Error using mex. Supported compiler not detected. try running the following command in Terminal: sudo xcodebuild -license accept

How to cite this code

If you use this code in your research, please cite our accompanying JES and JOSS papers: @article{cobrapro_jes_2024, author = {Ha, Sara and Onori, Simona}, doi = {10.1149/1945-7111/ad7292}, journal = {Journal of The Electrochemical Society}, year = {2024}, title = {{COBRAPRO: An Open-Source Software for the Doyle-Fuller-Newman Model with Co-Simulation Parameter Optimization Framework}}, } @article{cobrapro_joss_2024, author = {Ha, Sara and Onori, Simona}, doi = {arXiv:2404.10022}, journal = {Journal of Open Source Software}, year = {2024}, title = {{COBRAPRO: A MATLAB toolbox for Physics-based Battery Modeling and Co-simulation Parameter Optimization}}, }

Contributors

All Contributors

[^1]: Note that Xcode requires ~3.4 GB of storage space.
[^2]: COMSOL Multiphsyics is a commerically available finite element analysis software.

Owner

  • Login: COBRAPROsimulator
  • Kind: user

JOSS Publication

COBRAPRO: A MATLAB toolbox for Physics-based Battery Modeling and Co-simulation Parameter Optimization
Published
January 02, 2025
Volume 10, Issue 105, Page 6803
Authors
Sara Ha ORCID
Mechanical Engineering, Stanford University, 440 Escondido Mall, Stanford 94305, CA, United States of America
Simona Onori ORCID
Energy Science and Engineering, Stanford University, 367 Panama Mall, Stanford 94305, CA, United States of America
Editor
Mojtaba Barzegari ORCID
Tags
lithium-ion batteries physics-based modeling DFN model P2D model parameter identification particle swarm optimization

GitHub Events

Total
  • Create event: 2
  • Issues event: 4
  • Release event: 1
  • Watch event: 6
  • Issue comment event: 2
  • Push event: 58
  • Fork event: 3
Last Year
  • Create event: 2
  • Issues event: 4
  • Release event: 1
  • Watch event: 6
  • Issue comment event: 2
  • Push event: 58
  • Fork event: 3

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 505
  • Total Committers: 3
  • Avg Commits per committer: 168.333
  • Development Distribution Score (DDS): 0.02
Past Year
  • Commits: 302
  • Committers: 3
  • Avg Commits per committer: 100.667
  • Development Distribution Score (DDS): 0.033
Top Committers
Name Email Commits
COBRAPROsimulator 1****r 495
sarasyha s****4@g****m 8
Mojtaba Barzegari 4****y 2

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 6
  • Total pull requests: 1
  • Average time to close issues: 2 months
  • Average time to close pull requests: 1 day
  • Total issue authors: 5
  • Total pull request authors: 1
  • Average comments per issue: 2.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 5
  • Pull requests: 1
  • Average time to close issues: 9 days
  • Average time to close pull requests: 1 day
  • Issue authors: 4
  • Pull request authors: 1
  • Average comments per issue: 1.2
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • aykharal (2)
  • PonrajJenis (1)
  • COBRAPROsimulator (1)
  • yuefan98 (1)
  • mikofski (1)
Pull Request Authors
  • mbarzegary (1)
Top Labels
Issue Labels
Pull Request Labels