/** * Compiles the W1f source kinds (`battery_pack`, `bench_psu`, `clock`, * `clock_gen`, `pulse_source`, `pulse_gen` — codes 20-25) and the synthetic * `section_anchor` records (code 26) into v3 program records, exactly per * core/README.md's "Source records", "Battery record", "Bench PSU record", * "Waveform source records" and "Section anchor record". The compiler does * no physics: every resolved value is classic's own, or a rule the README * states, and the waveform and PSU records only carry what classic reads * from `comp.params` (no catalog default is ever applied, spec §8.8). * * PINS. Codes 21-25 read `pins[0]` (+) and `pins[1]` (-) BY POSITION, as * classic's `stampIndependentVoltageSource` and the bench_psu stamp do; code * 20 reads `pos` and `neg` BY ID (SO:146-150). A source with fewer than two * declared pins is declined `malformed::too-few-pins`: classic stamps * nothing for it but still allocates an all-zero branch row (§8.1.1, Q-W17), * a split the core does not reproduce. A battery that has two pins but lacks * `pos` or `neg` is declined `malformed::missing-pin`, unlike every other * by-id kind, because classic maps the absent pin to its reference node and * stamps a shorted battery. * * DECLINES. The circuit then runs on classic, which is what the user would * see anyway: a non-finite resolved value (`non-finite-`, named by the * record's own param, or by classic's param for the PSU), a negative pulse * width or ramp, a pulse cycle cut short (`truncated-pulse`), and a battery * profile classic knows that the record's `profileCode` does not. A net that * no existing component owns (a wire naming a component the circuit does not * hold) declines too, since an anchor record needs a component to name * (`unknownComponentIds`), and so does a component id carried by two * components (`duplicateComponentIds`). * * SLOTS. A clock or pulse source owns one digital slot keyed by the bare * component id (classic's `ds[comp.id]`); slot allocation is compile/index.ts's * job, as for every other kind, so these functions only name the key. */ import type { SimCircuit } from "../../sim/engine/sim-engine.js"; import type { ProgramPinInput } from "../format.js"; import { type CoreNodeBuild } from "./topology.js"; type SimComponent = SimCircuit["components"][number]; /** * What the facade's `getBatteryState` needs beyond the device state Rust * returns (core/README.md, Readouts): the profile's id and label, and the two * temperature fields, all constant per load. Computed here from classic's own * operating-point function, never from the record. */ export interface CompiledBatteryInfo { profileId: string; label: string; modelTemperatureC: number; temperatureWasClamped: boolean; } export type BatteryCompileResult = { ok: true; pins: readonly ProgramPinInput[]; /** The 9 battery params, in `CORE_BATTERY_PARAM` order. */ params: readonly number[]; /** The OCV table `[n, soc_0, v_0, ...]`, the profile's curve before `ocvScale`. */ blob: readonly number[]; info: CompiledBatteryInfo; } | { ok: false; reason: string; }; export type SourceCompileResult = { ok: true; pins: readonly ProgramPinInput[]; params: readonly number[]; /** The digital slot keys the record claims, in slot order: one for a clock or pulse source, none otherwise. */ digitalSlotKeys: readonly string[]; } | { ok: false; reason: string; }; /** * `battery_pack`: the 9 params and the OCV table blob, resolved through the * model classic itself builds (`batteryModelForComponent`, which * `SimEngine._batteryModel` calls), so the identity rules cannot drift: * catalog defaults only for an exact `catalogUid`, the generic fallback * otherwise, and no legacy alias (Q-O38). * * `ambientC` is the load's ambient (`AMBIENT_C`), constant per load. `rBase` * and `tempFactor` come from the two factors `batteryInternalResistanceOhm` * itself multiplies, so Rust's `(rBase * dep) * tempFactor` is classic's * expression operand for operand. */ export declare function compileBatteryPack(built: CoreNodeBuild, openKeys: ReadonlySet, component: SimComponent, ambientC: number): BatteryCompileResult; /** * `bench_psu`: `[V, iLimit]` from `comp.params` only. A `supply-var` part's * catalog `iLimit` is never read, so a PSU authored without one is an ideal * source, as in classic (Q-W18). An `iLimit` that is not `> 0` (negative, * zero, NaN) is emitted as 0, classic's ideal path (`iLimitPsu > 0` false, * SO:274-283); `+Infinity` is declined, since it is `> 0` in classic but no * finite limit. */ export declare function compileBenchPsu(built: CoreNodeBuild, openKeys: ReadonlySet, component: SimComponent): SourceCompileResult; /** * `clock` and `clock_gen`: `[freq, duty, vHigh, vLow, delay]`, classic's * expressions at SO:360-364 and SE:6188-6197 verbatim (`freq` floored at * 1e-6). Any non-finite value declines: a NaN `duty` would make classic's * level LOW forever and an infinite `freq` or `delay` has no edge to * schedule, so the core never has to define them. */ export declare function compileClock(built: CoreNodeBuild, openKeys: ReadonlySet, component: SimComponent): SourceCompileResult; /** * `pulse_source` and `pulse_gen`: `[v1, v2, td, tr, tf, pw, per]`, classic's * expressions at SO:386-392 and SE:6200-6211. * - `per` is the one value that may be non-finite: a period that is not * finite and positive selects classic's one-shot (WF:51), emitted as 0. * Every other non-finite value declines. * - A negative `tr`, `tf` or `pw` declines (`negative-`): the ramps * and the flat top are lengths. * - `truncated-pulse` declines a cycle cut short (`per > 0` and `per < * (tr + pw) + tf`, WF:52-56): classic then never finishes its fall, and the * edge model of Sources point 3 has no cycle to place its edges in. */ export declare function compilePulseSource(built: CoreNodeBuild, openKeys: ReadonlySet, component: SimComponent): SourceCompileResult; /** * The ids of components that wires name but `circuit.components` does not * hold, on nets none of whose pins belongs to a component that exists (an * ownerless net). Classic loads such a circuit and anchors the net as an * isolated section, but an anchor record needs a `componentIndex` to name, * so the compiler declines them * (`malformed::unknown-component`, core/README.md, "Section * anchor record") rather than throw: it never throws on a user circuit. * * Only an ownerless net matters: a ghost pin on a net that also holds a real * component's pin changes no stamp and has an owner for the anchor. */ export declare function unknownComponentIds(circuit: SimCircuit, built: CoreNodeBuild): string[]; /** * The ids that more than one component of the circuit carries, each once, in * circuit order of their second appearance. The compiler declines them * (`malformed::duplicate-id`): the core is not given a program * it could run as classic does. Classic keys its load by component id * (`_componentById`, `_pinNodeByComp`, `vsrcIdx`, every per-id state map), so * two components with one id share their pins and their state; and each * source kind's branch row is claimed per id by `vsrcIdx.set`, which the * second source overwrites, leaving the first one's row allocated and never * stamped. The matrix is singular and `lastConverged` is false for every * source kind this file compiles (probed per kind in compile-sources.test.ts). * The core's own tables are id-keyed too (`pinNode`, the digital slot keys, * `batteries`, `elementIKeys`), so there is nothing to mirror. The circuit * runs on classic, which is what the user would see anyway. */ export declare function duplicateComponentIds(circuit: SimCircuit): string[]; /** One isolated section's anchor: the node Rust fixes at 0 V, and the pin the record carries. */ export interface SectionAnchor { /** The anchor's node (classic's anchor row + 1: node 0 is the datum, classic's ground). */ node: number; /** Index in `circuit.components` of the component owning `pinId`. */ componentIndex: number; componentId: string; kind: string; pinId: string; } /** * Classic's isolated sections and their anchors, as `_compileIsolatedSection * Anchors` computes them (SE:4690-4735), in core node numbers. A section is a * union over each component's declared pins (no kind the core implements * declares `galvanicGroups`, so every component is one group), with node 0, * the reference net, as ground. Each section that does not contain node 0 * gets one anchor: the return pin (`sourceReturnPinId`, GR:56-59) of the * first source in circuit order that has one in the section, else the * section's lowest node. Classic's net row `r` is core node `r + 1` in both * datum cases (a synthetic datum takes node 0 and pins nothing), so classic's * ascending-row sort is an ascending-node sort here. * * `componentIndex` and the pin are the anchor node's owner: the source * component for a return pin, else the first component in circuit order with * a pin on the lowest node's net. */ export declare function findSectionAnchors(circuit: SimCircuit, built: CoreNodeBuild): SectionAnchor[]; export {};