/** * Operating-point snapshot builder. * * WHY a pure module (no React/zustand): * The same function is called from the UI (click-once capture), the PDF * builder (export time), and unit tests. Keeping it free of framework * dependencies lets all three paths share a single implementation. * * WHY power only for resolvable two-pin resistive kinds: * For multi-terminal components (transistors, op-amps, multi-pin ICs) "power" * has no single honest figure — we would need per-pin breakdown. For two-pin * resistive loads we can compute |ΔV| * |I| precisely because elementI is * pin0→pin1 and we know both terminal nets. Emitting a power figure for every * component would silently mislead students about parts we cannot compute it * for; it is better to omit and let them derive it manually. * * WHY natural net sorting: * "gnd" first because it is the reference node (voltage 0) and students * should see it anchored at the top. Numeric net IDs then follow numeric * order ("n0", "n1", ...) so the table reads left-to-right the same way * the schematic does. Remaining non-standard IDs are lexicographic. */ import type { Net } from "../sim/engine/graph.js"; import type { SimFailure } from "../sim/engine/sim-engine.js"; import type { PhysicsCurrentTelemetry, PhysicsPowerTelemetry, PhysicsTelemetrySnapshot } from "../sim/messages.js"; export interface OperatingPointInput { nets: Net[]; netV: Record; elementI: Record; elementChannelI: Record; digitalState: Record; failures: Record; converged: boolean; simTime: number; /** Minimal component metadata from circuit-store. Catalog identity is used * to reject telemetry that belongs to a replaced same-id component. */ components: Array<{ id: string; kind: string; label?: string; catalogUid?: string; }>; /** User-assigned net labels from circuit-store (netId → display name) */ netLabels: Record; /** Structured worker readout. When present, its identity-matched electrical * values are authoritative over the legacy scalar maps. */ physicsTelemetry?: PhysicsTelemetrySnapshot | null; } export interface OperatingPointNet { id: string; label: string; /** Undefined when the solver has not produced a value for this net. */ voltage?: number; } export interface OperatingPointComponent { id: string; kind: string; label: string; /** Current readout in amperes. Its reference and sign are defined by * currentTelemetry when structured telemetry is available; a legacy * scalar deliberately carries no implied sign convention. */ current?: number; /** Direction, aggregation, and provenance for a structured current value. * Absent on the legacy scalar fallback, whose sign is not qualified. */ currentTelemetry?: PhysicsCurrentTelemetry; /** Per-channel currents for rgb_led / bicolor_led. */ channelCurrents?: number[]; /** Power readout in watts. Structured values are signed according to * powerTelemetry; the legacy passive fallback is a magnitude only. */ power?: number; /** Sign convention, terminal pair, and provenance for structured power. * Absent on the legacy passive fallback, which is magnitude-only. */ powerTelemetry?: PhysicsPowerTelemetry; /** Why this snapshot has no aggregate power value. "not-exposed" means the * simulator may model the device, but this readout does not publish a * trustworthy aggregate; "unavailable" means no valid solved value was * available for this exact component identity. */ powerUnavailableReason?: "not-exposed" | "unavailable"; /** Digital output state (0 or 1) for clocks/gates/DFFs. */ digitalState?: number; /** True when a simulated failure is latched on this component. */ failed?: boolean; /** True when its supply went past its chip's absolute maximum rating * (supply_overvoltage): damage is likely and correct operation is not * guaranteed, but the simulator keeps running it, so it is not failed. */ overRated?: boolean; } export interface OperatingPoint { simTime: number; converged: boolean; nets: OperatingPointNet[]; components: OperatingPointComponent[]; warnings: string[]; } /** User-facing label for an omitted aggregate power value. Absence is about * this readout's evidence, not a claim that the device itself is unmodeled. */ export declare function operatingPointPowerUnavailableLabel(reason: OperatingPointComponent["powerUnavailableReason"]): "Not exposed" | "Unavailable"; /** Human-readable current semantics for tables and reports. */ export declare function operatingPointCurrentMeaning(comp: OperatingPointComponent): string; /** Human-readable power semantics for tables and reports. */ export declare function operatingPointPowerMeaning(comp: OperatingPointComponent): string; export declare function buildOperatingPoint(input: OperatingPointInput): OperatingPoint; /** * Produce a simple two-section CSV for the operating point. * * Section 1: Nets — netId, label, voltage_V * Section 2: Components — values plus explicit sign/reference/aggregation and * provenance columns. A legacy value is labelled as unqualified rather than * silently borrowing the convention of an incompatible component model. * * WHY two sections in one file: * The alternative (two separate files) would complicate the download UX for * a small benefit. A blank separator row between sections is unambiguous for * most spreadsheet tools and clearly communicates the two tables. */ export declare function operatingPointToCsv(op: OperatingPoint): string;