/** * Pure primary-battery physics used by the simulator. * * Scope and evidence * ------------------ * The three exact profiles are compact teaching fits to manufacturer data: * * - Energizer E91 AA alkaline: https://data.energizer.com/pdfs/e91.pdf * - Energizer 522 PP3/6LR61: https://data.energizer.com/pdfs/522.pdf * - Energizer CR2032: https://data.energizer.com/pdfs/cr2032.pdf * - Alkaline resistance behaviour: * https://data.energizer.com/pdfs/alkaline_appman.pdf * * Those sheets publish typical loaded discharge envelopes rather than a full * electrochemical equivalent circuit. We therefore use a deliberately small * Thevenin model: * * V_terminal = V_oc(S) - I_discharge * R_internal(S, T) * * V_oc(S) is linearly interpolated through chemistry-shaped voltage/SoC * anchors. The final 2% of usable SoC collapses from the manufacturer's cutoff * voltage to zero so a clamped-empty state cannot remain an infinite source. * * Internal resistance is: * * R(S,T) = R_fresh * [1 + A(1-S)^p/(S+K)] * * max(F_min, exp(alpha * (T_ref - T_clamped))) * * This captures the two effects supported by the manufacturer guidance: * resistance rises non-linearly with depletion and as ambient temperature * falls. `alpha` is calibrated to a documented profile assumption at the * lowest rated temperature; it is not presented as a manufacturer-guaranteed * coefficient. * * SoC uses coulomb counting: * * S_next = clamp01(S - max(I_discharge, 0) * dt / (3600 * capacity_Ah)) * * All supported cells are primary. Reverse current is counted as rejected * charge but never increases SoC. This module intentionally omits recovery, * rate-capacity/Peukert effects, self-discharge, ageing, and self-heating. Rated * capacity is therefore a reference-drain approximation, not a runtime promise. */ export type BatteryChemistry = "alkaline-zn-mno2" | "lithium-mno2" | "generic-primary"; export type BatteryProfileId = "alkaline-aa-4s" | "alkaline-pp3-9v" | "lithium-cr2032" | "generic-primary"; export interface BatteryOcvPoint { /** Usable state of charge, 0..1. */ soc: number; /** Pack open-circuit source voltage at this SoC. */ voltageV: number; } export interface BatteryPhysicsProfile { id: BatteryProfileId; catalogUid: string | null; label: string; chemistry: BatteryChemistry; rechargeable: false; cellCount: number; nominalVoltageV: number; referenceCapacityAh: number; freshInternalResistanceOhm: number; referenceTemperatureC: number; operatingTemperatureC: { min: number; max: number; }; ocvCurve: readonly BatteryOcvPoint[]; resistance: { /** A in the depletion multiplier equation. */ depletionScale: number; /** p in the depletion multiplier equation. */ depletionExponent: number; /** K in the depletion multiplier equation; keeps R finite at S=0. */ kneeSoc: number; /** alpha in exp(alpha * (T_ref - T)). */ temperatureCoefficientPerC: number; /** Prevents optimistic near-zero resistance at high temperature. */ minimumTemperatureFactor: number; }; assumptions: readonly string[]; } export interface ResolveBatteryProfileInput { catalogUid?: string | null; /** Used only by the generic fallback. */ fallbackNominalVoltageV?: number; /** Used only by the generic fallback. */ fallbackCapacityAh?: number; /** Used only by the generic fallback. Zero is allowed for legacy ideal-source compatibility. */ fallbackFreshInternalResistanceOhm?: number; } export interface BatteryProfileResolution { profile: BatteryPhysicsProfile; source: "exact-catalog-uid" | "generic-fallback"; requestedCatalogUid: string | null; warning: string | null; } export interface BatteryDynamicState { soc: number; /** Accepted discharge since this state was initialised. */ dischargedCoulombs: number; /** Reverse-current charge deliberately not accepted by a primary cell. */ rejectedRechargeCoulombs: number; } export interface BatteryStateStepInput { /** Positive means current delivered out of the positive terminal. */ dischargeCurrentA: number; dtSeconds: number; } export interface BatteryStateStepResult { state: BatteryDynamicState; requestedDischargeCoulombs: number; acceptedDischargeCoulombs: number; rejectedRechargeCoulombs: number; depleted: boolean; } export interface BatteryOperatingPointInput { soc: number; ambientTemperatureC?: number; /** Optional explicit part parameter; otherwise the chemistry profile value is used. */ referenceInternalResistanceOhm?: number; } export interface BatteryOperatingPoint { soc: number; openCircuitVoltageV: number; internalResistanceOhm: number; remainingCapacityCoulombs: number; ambientTemperatureC: number; modelTemperatureC: number; temperatureWasClamped: boolean; } export declare const BATTERY_PROFILES_BY_CATALOG_UID: Readonly>; export declare function resolveBatteryProfile(input?: ResolveBatteryProfileInput): BatteryProfileResolution; export declare function batteryOpenCircuitVoltageV(profile: BatteryPhysicsProfile, socInput: number): number; /** * The resistance a battery starts from before depletion and temperature act * on it: the authored reference when it is finite and non-negative, else the * profile's fresh value. Split out of batteryInternalResistanceOhm so a * compiler can read the same `rBase` the engine multiplies, not a copy. */ export declare function batteryBaseResistanceOhm(profile: BatteryPhysicsProfile, referenceInternalResistanceOhm?: number): number; /** * The temperature multiplier of batteryInternalResistanceOhm, which is * constant while the ambient is. Split out for the same reason as * batteryBaseResistanceOhm. */ export declare function batteryTemperatureFactor(profile: BatteryPhysicsProfile, ambientTemperatureC?: number): number; export declare function batteryInternalResistanceOhm(profile: BatteryPhysicsProfile, socInput: number, ambientTemperatureC?: number, referenceInternalResistanceOhm?: number): number; export declare function createBatteryState(initialSoc?: number): BatteryDynamicState; export declare function advancePrimaryBatteryState(profile: BatteryPhysicsProfile, previous: BatteryDynamicState, input: BatteryStateStepInput): BatteryStateStepResult; export declare function batteryOperatingPoint(profile: BatteryPhysicsProfile, input: BatteryOperatingPointInput): BatteryOperatingPoint; export declare function batteryTerminalVoltageV(point: Pick, dischargeCurrentA: number): number;