Battery storage API

Start with the battery storage overview for model selection, units and the distinction between energy and charge-based SoC.

Power-energy storage

See the PE model for equations and usage, and Multi-period OPF for scheduling and solve results. The scheduling API documents the shared solver and result type used by PE storage and EV sessions.

PowerOptLab.StorageDevice — Type
StorageDevice(; id, bus, kwargs...)

A grid-connected battery (or generic energy-storage) inverter with an inter-temporal state of charge. Powers are SI watts, energies SI watt-hours.

Required

  • id::String — unique device id.
  • bus::String — connection bus.
  • p_charge_max, p_discharge_max — charge / discharge power limits (W ≥ 0).
  • energy_max — usable energy capacity (Wh).
  • energy_init — energy at the start of the horizon (Wh).

Optional

  • phase_terminals=["1"], neutral="n" — the inverter's phase conductor(s) and the return terminal (nothing if referenced directly to ground).
  • energy_min=0.0 — lower energy bound (Wh).
  • q_min=0.0, q_max=0.0 — reactive-power box (var); default is unity power factor.
  • eff_charge=1.0, eff_discharge=1.0 — one-way efficiencies (0,1].
  • cyclic=true — require the terminal state of charge to equal energy_init.
  • energy_final=nothing — if set, pin the terminal energy to this value (Wh), overriding cyclic.
  • s_max=nothing, i_max=nothing, neutral_current_max=nothing — optional aggregate VA, per-phase A and neutral A limits. Multi-phase devices require i_max; legacy single-phase devices may retain a power-only abstraction.
  • phase_policy=:equal_power — equal P and Q on each phase; :independent explicitly permits phase redistribution within the conductor limits.
  • operation=:relaxed, complementarity_tolerance=1e-8 — normalized product bound on bidirectional operation. :complementarity requires an MPCC solver; :independent is an explicitly unphysical outer relaxation in general.
source

Current-voltage-charge storage

See the IVQ model for the cell/converter boundary, chemistry assumptions and numerical limits.

PowerOptLab.IVQBattery — Type
IVQBattery(; id, bus, chemistry, n_series, n_parallel, soc_init, inverter, kwargs...)

A current–voltage battery: n_series × n_parallel cells of a BatteryChemistry, coupled to the grid through an AdvancedInverter at the DC port. The pack terminal voltage is n_series · v_cell and the pack current n_parallel · i_cell.

Required

  • id::String, bus::String — identifier and point-of-connection bus (must match the inverter's bus).
  • chemistry::BatteryChemistry — the cell model.
  • n_series::Int, n_parallel::Int — pack configuration.
  • soc_init::Float64 — state of charge (0–1) at the operating point / horizon start.
  • inverter::AdvancedInverter — the AC↔DC converter (reused as-is).

Optional (reserved for multi-period use; ignored in the single-snapshot solve)

  • cyclic::Bool=true — require terminal SoC to return to soc_init.
  • soc_final::Union{Float64,Nothing}=nothing — pin terminal SoC (overrides cyclic).

The multi-period charge balance uses a forward update q[t+1] = q[t] − i[t]·Δt, which is exact for the piecewise-constant current of each period (there is one current variable per period, not per time node). A true trapezoidal rule needs currents at all T+1 nodes with consistent endpoint semantics and is deferred.

source
PowerOptLab.solve_ivq_battery — Function
solve_ivq_battery(net, battery; objective=:max_export, kwargs...) -> IVQBatteryResult

Stamp battery (and its AdvancedInverter) into net and solve at a single operating point (SoC fixed at battery.soc_init), demonstrating the coupled cell + converter feasible region. The network supplies the surrounding grid (a voltage source, lines); the battery exchanges power at its POC bus through the inverter.

Objective

  • :max_export — maximise active power delivered to the grid (battery discharges until a cell voltage/current limit or the converter rating binds).
  • :max_charge — maximise power drawn from the grid into the battery.
  • :min_loss — minimise converter loss subject to a p_set (W) POC delivery.

Keywords

  • p_set=nothing — required active-power target (W) for :min_loss.
  • q_set=nothing — optional reactive-power constraint at the POC (var).
  • per_unit=true, s_base=1e6, optimizer=Ipopt.Optimizer, verbose=false, solver_options=(). Results are returned in SI regardless of per_unit. Per-unit conditions the voltage–current bilinear coupling and is markedly more robust for this nonconvex solve; pass per_unit=false only to reproduce a raw SI solve.
source
PowerOptLab.IVQBatteryResult — Type
IVQBatteryResult

Result of solve_ivq_battery. SI units throughout.

Fields

  • termination_status::String
  • p_poc, q_poc — active/reactive power at the grid POC (from the inverter).
  • p_conv — converter-side active power at the internal node (W).
  • p_dc — DC-link power (W; = pack discharge power, p_dc = p_conv + p_loss).
  • p_loss — converter loss (W).
  • soc — state of charge at the operating point (0–1).
  • v_cell, i_cell — cell terminal voltage (V) and signed current (A; > 0 discharge).
  • v_pack, i_pack — pack terminal voltage (V) and current (A).
  • bus::Dict{String,Any} — the BMOPFTools result["bus"].
source
PowerOptLab.solve_multiperiod_ivq — Function
solve_multiperiod_ivq(nets, batteries; kwargs...) -> MultiperiodIVQResult

Co-optimise a chronological sequence of network snapshots nets with a set of IVQBattery devices whose state of charge couples the periods. Each battery arbitrages across time subject to its cell voltage/current limits, SoC window, and terminal/cyclic condition, exchanging power through its AdvancedInverter. The snapshots share one model and one objective (the total generation cost across the horizon); period economics come from the snapshots (e.g. a time-varying slack import price via each net's voltage_source cost).

Arguments

  • nets::Vector — T network dicts (parse_bmopf output), one per period.
  • batteries::Vector{IVQBattery} — each battery's bus/inverter must exist in every snapshot. soc_init sets the horizon start; cyclic/soc_final the terminal condition. The charge balance is a forward update, exact for the piecewise-constant per-period current, so it conserves charge exactly.

Keywords

  • dt_h=1.0 — uniform period duration in hours (compatibility shorthand).
  • time_grid=nothing — a TimeGrid for nonuniform durations; when supplied it takes precedence over dt_h.
  • per_unit=true, s_base=1e6, optimizer=Ipopt.Optimizer, verbose=false, solver_options=(). Results are SI regardless of per_unit. Per-unit conditions the coupled nonconvex solve and converges far more reliably across platforms/Ipopt builds; per_unit=false reproduces a raw SI solve.
source
PowerOptLab.MultiperiodIVQResult — Type
MultiperiodIVQResult

Result of solve_multiperiod_ivq. SI units throughout.

Fields

  • termination_status::String, objective::Float64.
  • snapshots::Vector{Dict{String,Any}} — the per-period BMOPFTools result dict.
  • dispatch::Dict{String,NamedTuple} — per battery id: i_cell, v_cell, i_pack, v_pack, p_poc, q_poc, p_dc (each length T) and soc (length T+1, 0–1, with soc[1] the initial state). SI throughout.

The coupled cell + inverter model is nonconvex, so solve_multiperiod_ivq finds a local optimum and may not converge for every configuration; a non-LOCALLY_SOLVED /OPTIMAL status returns NaN trajectories rather than an unconverged point.

source
PowerOptLab.BatteryChemistry — Type
BatteryChemistry

One battery cell in the voltage–current–charge (IVQ) variable space. The cell terminal voltage follows the Thévenin/Rint decomposition v(soc, i) = OCV(soc) − i · R(soc) with i > 0 on discharge, so charging (i < 0) raises the terminal voltage above OCV and discharging lowers it.

Construct one with thevenin_chemistry, linear_chemistry or tabulated_chemistry, or use a preloaded shape (illustrative_lfp, illustrative_nmc, illustrative_nca, illustrative_lead_acid, illustrative_leaf).

Fields

  • name::String — chemistry label.
  • ocv::Function — soc ∈ [0,1] → open-circuit voltage (V); non-decreasing and smooth (C¹). linear/thevenin OCV is affine; tabulated OCV is a monotone cubic (PCHIP), embedded as a function of the SoC variable. Interior knots are C¹ rather than C²; smoothness alone does not guarantee NLP convergence.
  • r_internal::Function — soc ∈ [0,1] → internal resistance (Ω) ≥ 0.
  • ocv_affine::Union{Tuple{Float64,Float64},Nothing} — (intercept, slope) when OCV is affine (so the multi-period model embeds it as a plain expression rather than a registered operator), else nothing.
  • r_constant::Union{Float64,Nothing} — the resistance value when R is constant, else nothing.
  • q_cell::Float64 — cell capacity (Ah).
  • v_cell_min, v_cell_max::Float64 — terminal-voltage operating bounds (V).
  • i_charge_max, i_discharge_max::Float64 — current magnitude limits (A ≥ 0).
  • soc_min, soc_max::Float64 — usable SoC window; the device clamps to it so the optimiser cannot exploit extrapolation outside the fitted range.
  • source::String — data provenance / reference for the OCV and R values.
source
PowerOptLab.thevenin_chemistry — Function
thevenin_chemistry(; name, v_nominal, r_internal, q_cell, kwargs...)

A Thévenin cell: a fixed open-circuit voltage v_nominal behind a constant internal resistance r_internal (Ω). v(soc, i) = v_nominal − i·R. The paper's PE-model is the further special case r_internal = 0 (constant voltage, so power and current are proportional and the current limit reduces to a power limit). Useful as a floor-fidelity model and as a warm-start generator.

Keywords

  • name="Thevenin", v_nominal, r_internal, q_cell (Ah).
  • v_cell_min = 0.8·v_nominal, v_cell_max = 1.2·v_nominal — voltage bounds (V).
  • i_charge_max = q_cell, i_discharge_max = q_cell — current limits (A; default 1C).
  • soc_min = 0.0, soc_max = 1.0.
  • source="Thévenin / Rint model".
source
PowerOptLab.linear_chemistry — Function
linear_chemistry(; name, v_full, v_empty, r_internal, q_cell, kwargs...)

A state-dependent voltage source: the open-circuit voltage falls linearly from v_full at soc = 1 to v_empty at soc = 0, behind a constant internal resistance. OCV(soc) = v_empty + (v_full − v_empty)·soc. A good first model whenever only the charged/discharged voltage endpoints and a resistance are known, and the natural discretisation of a real OCV curve.

Keywords

  • name="Linear", v_full, v_empty (V, with v_full ≥ v_empty), r_internal (Ω), q_cell (Ah).
  • v_cell_min = 0.95·v_empty, v_cell_max = 1.05·v_full — voltage bounds (V).
  • i_charge_max, i_discharge_max, soc_min, soc_max, source — as thevenin_chemistry.
source
PowerOptLab.tabulated_chemistry — Function
tabulated_chemistry(; name, soc_points, ocv_points, r_internal, q_cell, kwargs...)

Open-circuit voltage (and optionally resistance) from data points — e.g. a published OCV curve or a slow-rate (≈ C/20) discharge test. OCV(soc) is a monotone cubic (PCHIP) interpolant of (soc_points, ocv_points), which must be strictly increasing in soc and non-decreasing in ocv (a physical OCV curve). Outside the fitted range it is held flat so the optimiser cannot extrapolate into non-physical voltage. Clamping can make the derivative discontinuous at an outer knot. The defaults include those knots; choose soc_min/soc_max strictly inside them when avoiding endpoint derivative discontinuities matters to the solve. r_internal may be a scalar Ω or a matching vector r_points interpolated the same way.

Keywords

  • name, soc_points::Vector (strictly increasing), ocv_points::Vector (non-decreasing, V).
  • r_internal — scalar Ω, or pass r_points::Vector (Ω) for an R(soc) table.
  • q_cell (Ah), v_cell_min = minimum(ocv_points), v_cell_max = maximum(ocv_points), i_charge_max, i_discharge_max, soc_min = minimum(soc_points), soc_max = maximum(soc_points), source.
source
PowerOptLab.illustrative_lfp — Function
illustrative_lfp(; q_cell=100.0, r_internal=0.006, kwargs...)

Illustrative lithium iron phosphate (LFP) shape — a flat ~3.2–3.3 V plateau between sharp knees. The flat OCV is where a constant-voltage PE-model is least wrong in mid-SoC yet where the terminal-voltage and current limits still bite hardest at the knees — a good stress case for the IVQ model. Hand-drawn to a typical LFP voltage band (knee ≈ 2.5 V, nominal ≈ 3.2 V, charged ≈ 3.65 V); not a fit. q_cell/r_internal are representative round numbers, not a specific cell.

source
PowerOptLab.illustrative_nmc — Function
illustrative_nmc(; q_cell=5.0, r_internal=0.03, kwargs...)

Illustrative NMC (nickel-manganese-cobalt) shape — a monotonic slope from ≈ 3.0 V to 4.2 V, the workhorse EV form. Hand-drawn to a typical NMC voltage band; not a fit. For a calibrated NMC811 set to fit against, see PyBaMM Chen2020 (LG INR21700-M50, from GITT/EIS) — this preset is not that set.

source
PowerOptLab.illustrative_nca — Function
illustrative_nca(; q_cell=3.2, r_internal=0.035, kwargs...)

Illustrative NCA (nickel-cobalt-aluminium) shape — a sloped ≈ 2.5–4.2 V profile similar to NMC (Panasonic/Tesla cylindrical form). Hand-drawn; not a fit.

source
PowerOptLab.illustrative_lead_acid — Function
illustrative_lead_acid(; q_cell=100.0, r_internal=0.004, kwargs...)

Illustrative lead-acid shape — a roughly linear OCV from ≈ 1.75 V (empty) to ≈ 2.15 V (full) per cell, via linear_chemistry. Consistent with the textbook flooded/AGM OCV–SoC relation (e.g. IEEE 1188); endpoints only, not a fit.

source
PowerOptLab.illustrative_leaf — Function
illustrative_leaf(; kwargs...)

Illustrative shape in the voltage band of the 2013 Nissan-Leaf cell used by the source paper (Aaslid et al., 2020) — an LMO/NMC blend. The voltage bounds and capacity/current match the paper's Table 2 (Vmin/Vmax = 3.20/4.15 V, Qmax = 29 Ah, Ib,ch/Ib,dch = 30/90 A), but the OCV curve is a hand-drawn monotone line through that band — it does not reproduce the paper, which used an empirical current–SoC voltage surface f_v(soc, i). To actually reproduce the paper, fit that surface from the cell dataset (Wiggins, Allu & Wang, ORNL, 2020, https://doi.org/10.5281/zenodo.2580327) and supply an R(soc)/surface model.

source