Battery struct
#include <gtopt/battery.hpp>
Represents a battery energy storage system (BESS).
A battery can charge (absorb energy) and discharge (deliver energy) within its operational constraints. The state of charge (SoC) is tracked between time blocks, accounting for round-trip efficiency losses.
The energy balance per block is:
SoC[t+1] = SoC[t] × (1 − annual_standing_loss/8760 × Δt) + input_efficiency × charge − discharge / output_efficiency
When annual_standing_loss is unset the planning-wide default model_options.battery_annual_standing_loss applies — 0.48 p.u./year (4 %/month, lithium-ion cell + BMS; see PlanningOptionsLP::default_battery_annual_standing_loss). An explicit value, including 0, always wins.
When the bus field is set, System::expand_batteries() auto-generates the corresponding Generator, Demand, and Converter elements so the user only needs to define a single Battery object. This approach follows the convention used by PyPSA StorageUnit and pandapower storage.
When source_generator is also set, the battery operates in generation-coupled mode: a dedicated internal bus is created for the charge path so that the source generator feeds the battery directly.
Public static variables
- static LPClassName class_name
Public variables
- OptActive active
- Activation status (default: active).
- OptTRealFieldSched annual_capcost
- Annualized investment cost [$/MWh-year].
- OptTRealFieldSched annual_derating
- Annual capacity derating factor [p.u./year].
- OptTRealFieldSched annual_standing_loss
- OptSingleId bus
- OptTRealFieldSched capacity
- Installed energy capacity [MWh].
- OptTRealFieldSched capmax
- Absolute maximum energy capacity [MWh].
- OptTBRealFieldSched charge_cost
- OptBool commitment
- OptBool daily_cycle
- OptName description
- OptTBRealFieldSched discharge_cost
- OptTBRealFieldSched ecost
- OptReal efin
- OptReal efin_cost
- OptReal eini
- OptTBRealFieldSched emax
- OptTBRealFieldSched emin
- OptReal energy_power_ratio
- OptBool exclusive_charge_discharge
- OptTRealFieldSched expcap
- Energy capacity per expansion module [MWh].
- OptTRealFieldSched expmod
- Maximum number of expansion modules [dimensionless].
- OptTBRealFieldSched input_efficiency
- OptBool integer_expmod
- Integer-constrain the expmod variable.
- OptReal max_cycles_day
- Name name
- Human-readable battery name.
- OptTBRealFieldSched output_efficiency
- OptTBRealFieldSched pmax_charge
- OptTBRealFieldSched pmax_discharge
- OptTBRealFieldSched pmin_charge
- OptTBRealFieldSched pmin_discharge
- OptTRealFieldSched power_annual_capcost
- Annualized power cost [$/MW-year].
- OptTRealFieldSched power_annual_derating
- Power derating [p.u./year].
- OptTRealFieldSched power_capacity
- Installed power [MW].
- OptTRealFieldSched power_capmax
- Absolute max power [MW].
- OptTRealFieldSched power_expcap
- Power per expansion module [MW].
- OptTRealFieldSched power_expmod
- Max number of power modules.
- OptTRealFieldSched power_fixed_om_cost
- OptTRealFieldSched power_overnight_capcost
- OptTBRealFieldSched soft_emin
- OptTBRealFieldSched soft_emin_cost
- OptSingleId source_generator
- OptName storage_integration
- OptName type
- Optional battery type tag (e.g. "li-ion", "flow", "pumped").
- Uid uid
- Unique identifier.
- OptBool use_state_variable
Annuity from overnight cost (per-candidate private rate)
Used only when annual_capcost is unset: the LP charges annual_capcost = overnight_capcost × CRF(wacc, economic_life), CRF(r, n) = r(1+r)^n / ((1+r)^n − 1). wacc unset → the social annual_discount_rate (the stage discount factors are never changed). All unset (default) → today's LP.
Native BESS reserve deliverability (opt-in)
- OptReal reserve_sustain_hours
- OptBool reserve_discharge_credit
- OptReal reserve_energy_usage_up
- OptReal reserve_energy_usage_down
- Down analogue [MWh/MW/h].
Variable documentation
static LPClassName gtopt:: Battery:: class_name
Canonical class-name constant used in LP row labels and config fields like VariableScale::class_name. Single source of truth — BatteryLP exposes no separate ClassName member; callers reach the constant via Battery::class_name directly (or BatteryLP::Element::class_name in generic contexts).
OptTRealFieldSched gtopt:: Battery:: annual_standing_loss
Annual self-discharge rate [p.u./year]. Unset → model_options.battery_annual_standing_loss (default 0.48 = 4 %/month).
OptSingleId gtopt:: Battery:: bus
External bus connection for the unified battery definition. When set, System::expand_batteries() auto-generates a discharge Generator, a charge Demand, and a linking Converter.
OptTBRealFieldSched gtopt:: Battery:: charge_cost
Per-MWh cost paid when charging the battery [$/MWh] per-(stage, block). Mirrors UC.jl's per-hour Charge cost < ($/MW) and PLEXOS's battery charge cost. Counterpart to discharge_cost: discharge_cost prices energy injected into the grid, charge_cost prices energy absorbed from it. Wired through System::expand_batteries() onto the synthetic charge-side Demand element by encoding the cost as a negative Demand.fcost — the demand-LP substitution (demand_lp.cpp:249) then stamps the column with the correct positive coefficient (lcol_cost = -block_ecost). When unset (default), charging is free at the LP level (only the discharge cost is paid).
OptBool gtopt:: Battery:: commitment
Gate the synthetic charge Demand and discharge Generator floors with per-block INTEGER commitment binaries on the linking Converter. When unset (default), pmin_charge / pmin_discharge are HARD floors that fire every block — correct for must-run batteries and LP-only solves. When set, the Converter LP adds a per-block charge-mode binary u_charge with the C2-style rows load ≥ lmin × u_charge, load ≤ lmax × u_charge; the discharge side gets the analogous pair on the status u of the synthesised uc_<bat>_gen commitment. The two mode binaries are independent, so each floor only fires WHEN the battery is actively charging / discharging. Mirrors UC.jl's conditional Minimum charge/discharge rate (MW) semantics and PLEXOS Battery.Commitment Status. Always introduces integer columns — if you need LP-relax behaviour leave commitment unset (hard floors), which is the natural LP-only mode. Propagated by System::expand_batteries() onto Converter.commitment.
OptBool gtopt:: Battery:: daily_cycle
Enable PLP-style daily cycle operation: block durations in the energy balance are scaled by 24/stage_duration so that emin/emax constraints represent a daily cycle regardless of the stage length. Implies decoupled stage/phase behaviour (use_state_variable forced false). Default for batteries is true (enabled); a long-duration / state battery (pumped hydro, large BESS carried across stages like a reservoir) must set it false explicitly (and use_state_variable true): use_state_variable alone has no effect while daily_cycle is on (validate_planning warns).
OptName gtopt:: Battery:: description
Optional free-text description (e.g. conversion provenance)
OptTBRealFieldSched gtopt:: Battery:: discharge_cost
Per-MWh cost paid when discharging the battery (energy injected into the grid) [$/MWh] per-(stage, block). Mirrors UC.jl Discharge cost ($/MW) and PLEXOS Battery.Generation Cost. Forwarded to the synthetic discharge Generator.gcost (also TB) by System::expand_batteries().
OptTBRealFieldSched gtopt:: Battery:: ecost
Storage usage cost (penalty for SoC) [$/MWh] — per-(stage, block); accepts a scalar (broadcasts), a 2-D nested array, or a file-backed schedule.
OptReal gtopt:: Battery:: efin_cost
Penalty cost per unit of efin shortfall [$/MWh]. When set (and > 0) the hard SoC_end >= efin row becomes soft: SoC_end + slack >= efin with the slack priced at efin_cost in the objective. Mirrors the Reservoir.efin_cost mechanism (see storage_lp.hpp). Mostly relevant for very large batteries / LNG- like seasonal storage; daily-cycle BESS typically leave it unset.
OptTBRealFieldSched gtopt:: Battery:: emax
Maximum state of charge (usable capacity) [MWh] — per-(stage, block); see emin for the accepted JSON / C++ shapes.
OptTBRealFieldSched gtopt:: Battery:: emin
Minimum state of charge [MWh] — per-(stage, block). Accepts a scalar (broadcast), a 2-D nested-array [[block0, block1, ...], ...] indexed by stage and block, or a file-backed schedule. The 2-D form lets UC.jl-style Last period minimum level tighten the SoC bound on a single block (typically the last) of a stage without affecting the others.
OptReal gtopt:: Battery:: energy_power_ratio
Fixed storage duration [h]: when set, the LP adds per stage energy capainst = energy_power_ratio × power capainst (installed totals, existing capacity included), so energy and power are built together as one technology with a fixed duration (e.g. 2 h, 4 h, 8 h battery candidates). Leave unset to optimise the two axes independently, each with its own cost.
OptBool gtopt:: Battery:: exclusive_charge_discharge
Charge/discharge exclusivity constraint — only meaningful with commitment = true. When true (the default when unset) the synthetic Converter adds, per block, u_charge + u_discharge ≤ 1 on the two mode binaries (u_discharge is the status of the synthesised uc_<bat>_gen commitment), so the battery is never charging and discharging in the same block (PLEXOS / UC.jl storage semantics). false drops the row: both modes may be on at once, limited only by the power envelope. Ignored when commitment is unset (no mode binaries; validate_planning warns when it is set to true there). Propagated by System::expand_batteries() onto Converter.exclusive_charge_discharge.
OptTBRealFieldSched gtopt:: Battery:: input_efficiency
Charging efficiency [p.u.] per-(stage, block).
OptReal gtopt:: Battery:: max_cycles_day
Daily energy-throughput limit — PLEXOS Battery.Max Cycles Day. Sets the HARD constraint Σ_blocks discharge·Δt ≤ N · capacity per day, where N = max_cycles_day and capacity is the usable energy (one full discharge of the usable capacity = one cycle). The discharge throughput is measured cell-side, i.e. the coefficient includes the 1/output_efficiency drain term (identical to the SoC-drain coefficient in the energy balance), so losses count toward a cycle. This is a constraint, NOT an objective cost: it never enters the objective and therefore does not distort marginal / LMP / operational costs. Unset ⇒ no constraint. The time-model branch (single per-day row for PLP-style daily-cycle stages vs. a rolling 24 h window per day for chronological stages) is selected by the existing daily_cycle flag, mirroring storage_lp.hpp.
OptTBRealFieldSched gtopt:: Battery:: output_efficiency
Discharging efficiency [p.u.] per-(stage, block).
OptTBRealFieldSched gtopt:: Battery:: pmax_charge
Max charging power [MW] (unified definition). Per-(stage, block); accepts scalar, 2-D [[block0, ...], ...], or file-backed. Forwarded to the synthetic charge Demand.lmax by System::expand_batteries().
OptTBRealFieldSched gtopt:: Battery:: pmax_discharge
Max discharging power [MW] per-(stage, block). Forwarded to the synthetic discharge Generator.pmax.
OptTBRealFieldSched gtopt:: Battery:: pmin_charge
Minimum charging power [MW] per-(stage, block). Forwarded to the synthetic charge Demand.lmin. By default a HARD floor every block; when Battery.commitment is set, the synthetic Converter gates the floor with a per-block binary so the bound only fires when the battery is actively charging. Mirrors UC.jl Minimum charge rate (MW) and PLEXOS Battery.Min Charge Rate.
OptTBRealFieldSched gtopt:: Battery:: pmin_discharge
Minimum discharging power [MW] per-(stage, block). HARD floor on the synthetic discharge Generator.pmin; with commitment set it becomes the when-discharging Commitment.pmin of uc_<bat>_gen instead. Mirrors UC.jl Minimum discharge rate (MW) and PLEXOS Battery.Min Generation.
OptTRealFieldSched gtopt:: Battery:: power_fixed_om_cost
Fixed O&M of expansion power [$/MW-year]; forwarded to the converter
OptTRealFieldSched gtopt:: Battery:: power_overnight_capcost
Overnight power cost [$/MW]; annuity at the battery's wacc / economic_life (see above)
OptTBRealFieldSched gtopt:: Battery:: soft_emin
Soft minimum SoC [MWh] — per-(stage, block); accepts a scalar (broadcasts), a 2-D nested array, or a file-backed schedule. Creates a penalized constraint: efin + slack >= soft_emin.
OptTBRealFieldSched gtopt:: Battery:: soft_emin_cost
Penalty cost per unit of soft_emin violation [$/MWh] — per-(stage, block).
OptSingleId gtopt:: Battery:: source_generator
Optional reference to a co-located generator that directly charges the battery (generation-coupled / hybrid battery configuration). When set together with bus, expand_batteries() creates an internal bus so that:
- The discharge Generator connects to the external
bus - The charge Demand connects to the internal bus
- The source generator's bus is set to the internal bus The source generator's own
busfield is overwritten. Withoutsource_generatorthe battery is standalone: both charge and discharge connect to the same externalbus.
OptName gtopt:: Battery:: storage_integration
Point-stage storage integration rule of this element (block = cc | trapezoid | lg4 | lg6 | lg4_pos | lg6_pos); unset: the per-type / global model option (see ModelOptions).
OptBool gtopt:: Battery:: use_state_variable
Whether to propagate SoC state across stage/phase boundaries via StateVariables (SDDP-style coupling). When false (the default for batteries), each phase is solved independently with no state carry-over; an efin==eini constraint is added automatically to close each phase.
OptTRealFieldSched gtopt:: Battery:: overnight_capcost
Overnight investment cost per unit of capacity [$/MWh]
OptTRealFieldSched gtopt:: Battery:: wacc
Private discount rate of the annuity (WACC / hurdle rate) [p.u./year]
OptTRealFieldSched gtopt:: Battery:: fixed_om_cost
Fixed O&M of the expansion capacity [$/unit-year], charged on the capacity built from this stage on, next to the annuity and with the same stage discounting. Unset → no fixed O&M.
OptReal gtopt:: Battery:: reserve_sustain_hours
Reserve sustain duration T [h]. When set (>= 0), every ReserveProvision whose generator is this battery's discharge generator is modelled with the native BESS rows emitted by the linking Converter instead of the generic generator rows (g + r_up <= Pd, g - r_dn >= 0):
reserve_up_headroom: pd - pc + sum r_up <= Pd_max reserve_dn_headroom: pc + sum r_dn <= Pc_max (+ pd, see below) reserve_up_energy: e - (T/eta_d) sum r_up >= e_min (T > 0) reserve_dn_energy: e + T eta_c sum r_dn <= e_max (T > 0)
e is the end-of-block state of charge. No reserve term ever enters a bus balance, so the rows cannot create a forced injection (the mechanism by which CEN's PLEXOS BAT_*_CF_GEN_COMP + AUX battery formulation produces negative marginal costs). T = 0 keeps only the power-headroom rows. Unset (default) => legacy generic generator rows, no change to existing cases.
OptBool gtopt:: Battery:: reserve_discharge_credit
Credit discharge in the down-reserve headroom (pc - pd + sum r_dn <= Pc_max, the full physical inverter range). Default false uses the charge-side headroom only (pc + sum r_dn <= Pc_max), which never rewards an injection. true is the physical upper bound but reintroduces the classical down-reserve negative-price channel (a unit must inject to offer down reserve). Only read when reserve_sustain_hours is set.
OptReal gtopt:: Battery:: reserve_energy_usage_up
Expected reserve deployment energy [MWh per MW of provision per hour], charged to this battery's own state of charge: e_b = … − (a_up/ηd)·Δ·Σr_up + a_dn·ηc·Δ·Σr_dn. The physical replacement for CEN's PLEXOS BAT_*_CF_GEN_COMP / BAT_*_CF_LOAD_COMP (an AUX battery whose generation / load = 0.3 × provision, i.e. a bus injection): here no term enters a bus balance. Only read when reserve_sustain_hours is set.