feat: electrical simulation via ngspice-WASM (eecircuit-engine)
Adds full SPICE-accurate electrical simulation to Velxio, behind a lazy-
loaded ⚡ toolbar toggle. Arduino / ESP32 / RP2040 sketches now co-simulate
with real analog behaviour: correct voltages on wires, real I–V curves on
LEDs, working potentiometers, NTC thermistors read by analogRead(), PWM
driving RC filters, transistors, op-amps, diodes, MOSFETs, etc.
Engine: eecircuit-engine (ngspice compiled to WebAssembly). Main bundle
stays at 2.4 MB; the 20 MB SPICE chunk only loads when the user activates
electrical mode. Disabled at build time via VITE_ELECTRICAL_SIM=false.
Frontend additions:
- simulation/spice/: SpiceEngine wrapper + lazy entry, NetlistBuilder with
UnionFind over wires, componentToSpice mapping (24 metadataIds incl.
real part numbers: 2N2222, 2N3055, BC547, IRF540, 2N7000, 1N4148,
1N4007, 1N4733, LEDs, NTC, op-amp ideal), CircuitScheduler with
debounced coalescing, AVRSpiceBridge for quasi-static co-simulation.
- store/useElectricalStore: Zustand slice, feature-flag aware.
- components/analog-ui/: ⚡ toolbar toggle + SVG voltage overlay.
- components/components-instruments/: Voltmeter, Ammeter probes.
- 62 tests (spice-*, netlist-builder, component-to-spice, instruments).
Sandbox (test/test_circuit/): 47-test validation sandbox that proved
the approach (hand-rolled MNA baseline + ngspice pipeline) before
porting to the app. Kept as reference.
Docs: docs/wiki/circuit-emulation-*.md (13 engineering pages covering
architecture, solvers, components, AVR bridge, gotchas, performance,
integration plan, API reference, appendix) + electrical-simulation-
user-guide.md (end-user facing).
Reference plan: test/test_circuit/plan/phase_8_velxio_implementation.md
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 19:11:54 +07:00
|
|
|
import { describe, it, expect } from 'vitest';
|
|
|
|
|
import { buildNetlist } from '../simulation/spice/NetlistBuilder';
|
|
|
|
|
import { runNetlist } from '../simulation/spice/SpiceEngine';
|
|
|
|
|
import { UnionFind } from '../simulation/spice/unionFind';
|
|
|
|
|
import { parseValueWithUnits } from '../simulation/spice/valueParser';
|
|
|
|
|
|
|
|
|
|
describe('UnionFind', () => {
|
|
|
|
|
it('unions transitively', () => {
|
|
|
|
|
const uf = new UnionFind();
|
|
|
|
|
uf.union('a', 'b');
|
|
|
|
|
uf.union('b', 'c');
|
|
|
|
|
expect(uf.find('a')).toBe(uf.find('c'));
|
|
|
|
|
});
|
|
|
|
|
it('canonical name propagates on union', () => {
|
|
|
|
|
const uf = new UnionFind();
|
|
|
|
|
uf.union('gnd_pin_x', 'r1_pin2');
|
|
|
|
|
uf.setCanonical('gnd_pin_x', '0');
|
|
|
|
|
expect(uf.find('r1_pin2')).toBe('0');
|
|
|
|
|
});
|
|
|
|
|
it('ground wins over vcc when both canonicals collide', () => {
|
|
|
|
|
const uf = new UnionFind();
|
|
|
|
|
uf.setCanonical('node_a', 'vcc_rail');
|
|
|
|
|
uf.setCanonical('node_b', '0');
|
|
|
|
|
uf.union('node_a', 'node_b');
|
|
|
|
|
expect(uf.find('node_a')).toBe('0');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('parseValueWithUnits', () => {
|
|
|
|
|
it('parses SPICE SI suffixes', () => {
|
|
|
|
|
expect(parseValueWithUnits('4.7k')).toBe(4700);
|
|
|
|
|
expect(parseValueWithUnits('220')).toBe(220);
|
|
|
|
|
expect(parseValueWithUnits('1Meg')).toBe(1_000_000);
|
|
|
|
|
expect(parseValueWithUnits('10u')).toBeCloseTo(1e-5);
|
|
|
|
|
expect(parseValueWithUnits('100n')).toBeCloseTo(1e-7);
|
|
|
|
|
expect(parseValueWithUnits('22p')).toBeCloseTo(2.2e-11);
|
|
|
|
|
expect(parseValueWithUnits('10mH')).toBeCloseTo(0.01);
|
|
|
|
|
expect(parseValueWithUnits('1.5H')).toBe(1.5);
|
|
|
|
|
expect(parseValueWithUnits('0.1u')).toBeCloseTo(1e-7);
|
|
|
|
|
});
|
|
|
|
|
it('passes numbers through', () => {
|
|
|
|
|
expect(parseValueWithUnits(1000)).toBe(1000);
|
|
|
|
|
});
|
|
|
|
|
it('returns fallback for garbage', () => {
|
|
|
|
|
expect(parseValueWithUnits('banana', 42)).toBe(42);
|
|
|
|
|
expect(parseValueWithUnits(undefined, 99)).toBe(99);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('NetlistBuilder — simple cases', () => {
|
|
|
|
|
it('emits a voltage divider and ngspice gets 6V', { timeout: 30_000 }, async () => {
|
2026-04-18 05:27:18 +07:00
|
|
|
const { netlist } = buildNetlist({
|
feat: electrical simulation via ngspice-WASM (eecircuit-engine)
Adds full SPICE-accurate electrical simulation to Velxio, behind a lazy-
loaded ⚡ toolbar toggle. Arduino / ESP32 / RP2040 sketches now co-simulate
with real analog behaviour: correct voltages on wires, real I–V curves on
LEDs, working potentiometers, NTC thermistors read by analogRead(), PWM
driving RC filters, transistors, op-amps, diodes, MOSFETs, etc.
Engine: eecircuit-engine (ngspice compiled to WebAssembly). Main bundle
stays at 2.4 MB; the 20 MB SPICE chunk only loads when the user activates
electrical mode. Disabled at build time via VITE_ELECTRICAL_SIM=false.
Frontend additions:
- simulation/spice/: SpiceEngine wrapper + lazy entry, NetlistBuilder with
UnionFind over wires, componentToSpice mapping (24 metadataIds incl.
real part numbers: 2N2222, 2N3055, BC547, IRF540, 2N7000, 1N4148,
1N4007, 1N4733, LEDs, NTC, op-amp ideal), CircuitScheduler with
debounced coalescing, AVRSpiceBridge for quasi-static co-simulation.
- store/useElectricalStore: Zustand slice, feature-flag aware.
- components/analog-ui/: ⚡ toolbar toggle + SVG voltage overlay.
- components/components-instruments/: Voltmeter, Ammeter probes.
- 62 tests (spice-*, netlist-builder, component-to-spice, instruments).
Sandbox (test/test_circuit/): 47-test validation sandbox that proved
the approach (hand-rolled MNA baseline + ngspice pipeline) before
porting to the app. Kept as reference.
Docs: docs/wiki/circuit-emulation-*.md (13 engineering pages covering
architecture, solvers, components, AVR bridge, gotchas, performance,
integration plan, API reference, appendix) + electrical-simulation-
user-guide.md (end-user facing).
Reference plan: test/test_circuit/plan/phase_8_velxio_implementation.md
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 19:11:54 +07:00
|
|
|
components: [
|
|
|
|
|
{ id: 'r1', metadataId: 'resistor', properties: { value: '1k' } },
|
|
|
|
|
{ id: 'r2', metadataId: 'resistor', properties: { value: '2k' } },
|
|
|
|
|
],
|
|
|
|
|
wires: [
|
2026-04-22 02:45:45 +07:00
|
|
|
{
|
|
|
|
|
id: 'w1',
|
|
|
|
|
start: { componentId: 'arduino', pinName: '5V' },
|
|
|
|
|
end: { componentId: 'r1', pinName: '1' },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'w2',
|
|
|
|
|
start: { componentId: 'r1', pinName: '2' },
|
|
|
|
|
end: { componentId: 'r2', pinName: '1' },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'w3',
|
|
|
|
|
start: { componentId: 'r2', pinName: '2' },
|
|
|
|
|
end: { componentId: 'arduino', pinName: 'GND' },
|
|
|
|
|
},
|
feat: electrical simulation via ngspice-WASM (eecircuit-engine)
Adds full SPICE-accurate electrical simulation to Velxio, behind a lazy-
loaded ⚡ toolbar toggle. Arduino / ESP32 / RP2040 sketches now co-simulate
with real analog behaviour: correct voltages on wires, real I–V curves on
LEDs, working potentiometers, NTC thermistors read by analogRead(), PWM
driving RC filters, transistors, op-amps, diodes, MOSFETs, etc.
Engine: eecircuit-engine (ngspice compiled to WebAssembly). Main bundle
stays at 2.4 MB; the 20 MB SPICE chunk only loads when the user activates
electrical mode. Disabled at build time via VITE_ELECTRICAL_SIM=false.
Frontend additions:
- simulation/spice/: SpiceEngine wrapper + lazy entry, NetlistBuilder with
UnionFind over wires, componentToSpice mapping (24 metadataIds incl.
real part numbers: 2N2222, 2N3055, BC547, IRF540, 2N7000, 1N4148,
1N4007, 1N4733, LEDs, NTC, op-amp ideal), CircuitScheduler with
debounced coalescing, AVRSpiceBridge for quasi-static co-simulation.
- store/useElectricalStore: Zustand slice, feature-flag aware.
- components/analog-ui/: ⚡ toolbar toggle + SVG voltage overlay.
- components/components-instruments/: Voltmeter, Ammeter probes.
- 62 tests (spice-*, netlist-builder, component-to-spice, instruments).
Sandbox (test/test_circuit/): 47-test validation sandbox that proved
the approach (hand-rolled MNA baseline + ngspice pipeline) before
porting to the app. Kept as reference.
Docs: docs/wiki/circuit-emulation-*.md (13 engineering pages covering
architecture, solvers, components, AVR bridge, gotchas, performance,
integration plan, API reference, appendix) + electrical-simulation-
user-guide.md (end-user facing).
Reference plan: test/test_circuit/plan/phase_8_velxio_implementation.md
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 19:11:54 +07:00
|
|
|
],
|
|
|
|
|
boards: [
|
|
|
|
|
{
|
|
|
|
|
id: 'arduino',
|
|
|
|
|
vcc: 5,
|
|
|
|
|
pins: { '5V': { type: 'digital', v: 5 }, GND: { type: 'digital', v: 0 } },
|
|
|
|
|
groundPinNames: ['GND'],
|
|
|
|
|
vccPinNames: ['5V'],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
analysis: { kind: 'op' },
|
|
|
|
|
});
|
|
|
|
|
// Netlist should include two resistors and a vcc rail source
|
|
|
|
|
expect(netlist).toMatch(/R_r1/);
|
|
|
|
|
expect(netlist).toMatch(/R_r2/);
|
|
|
|
|
expect(netlist).toMatch(/V_VCC_RAIL vcc_rail 0 DC 5/);
|
|
|
|
|
expect(netlist).toMatch(/\.op/);
|
|
|
|
|
expect(netlist).toMatch(/\.end/);
|
|
|
|
|
|
|
|
|
|
// But critically: ngspice should accept it and return 10/3 V at midpoint
|
|
|
|
|
// (5V · 2k / 3k = 3.333V)
|
|
|
|
|
const result = await runNetlist(netlist);
|
|
|
|
|
// Find the middle net name — it's auto-generated as "n0" or similar
|
|
|
|
|
const midV = result.vec('v(n0)') as number[];
|
|
|
|
|
expect(midV[0]).toBeCloseTo((5 * 2) / 3, 2);
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-22 02:45:45 +07:00
|
|
|
it(
|
|
|
|
|
'emits an LED + resistor from 5V rail and ngspice solves non-linear',
|
|
|
|
|
{ timeout: 30_000 },
|
|
|
|
|
async () => {
|
|
|
|
|
const { netlist } = buildNetlist({
|
|
|
|
|
components: [
|
|
|
|
|
{ id: 'r1', metadataId: 'resistor', properties: { value: '220' } },
|
|
|
|
|
{ id: 'led1', metadataId: 'led', properties: { color: 'red' } },
|
|
|
|
|
],
|
|
|
|
|
wires: [
|
|
|
|
|
{
|
|
|
|
|
id: 'w1',
|
|
|
|
|
start: { componentId: 'board', pinName: 'VCC' },
|
|
|
|
|
end: { componentId: 'r1', pinName: '1' },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'w2',
|
|
|
|
|
start: { componentId: 'r1', pinName: '2' },
|
|
|
|
|
end: { componentId: 'led1', pinName: 'A' },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'w3',
|
|
|
|
|
start: { componentId: 'led1', pinName: 'C' },
|
|
|
|
|
end: { componentId: 'board', pinName: 'GND' },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
boards: [
|
|
|
|
|
{
|
|
|
|
|
id: 'board',
|
|
|
|
|
vcc: 5,
|
|
|
|
|
pins: {},
|
|
|
|
|
groundPinNames: ['GND'],
|
|
|
|
|
vccPinNames: ['VCC'],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
analysis: { kind: 'op' },
|
|
|
|
|
});
|
|
|
|
|
expect(netlist).toMatch(/D_led1 \S+ 0 LED_RED/);
|
|
|
|
|
expect(netlist).toMatch(/\.model LED_RED D\(Is=1e-20 N=1\.7\)/);
|
|
|
|
|
|
|
|
|
|
const result = await runNetlist(netlist);
|
|
|
|
|
// Forward voltage on the anode should be ≈ 2.0 V for a red LED
|
|
|
|
|
const anodeNet = netlist.match(/D_led1 (\S+) 0 LED_RED/)?.[1];
|
|
|
|
|
expect(anodeNet).toBeTruthy();
|
|
|
|
|
const Vf = (result.vec(`v(${anodeNet})`) as number[])[0];
|
|
|
|
|
expect(Vf).toBeGreaterThan(1.7);
|
|
|
|
|
expect(Vf).toBeLessThan(2.3);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
it('NTC divider: T=25°C produces V(a0) ≈ 2.5V', { timeout: 30_000 }, async () => {
|
2026-04-18 05:27:18 +07:00
|
|
|
const { netlist } = buildNetlist({
|
feat: electrical simulation via ngspice-WASM (eecircuit-engine)
Adds full SPICE-accurate electrical simulation to Velxio, behind a lazy-
loaded ⚡ toolbar toggle. Arduino / ESP32 / RP2040 sketches now co-simulate
with real analog behaviour: correct voltages on wires, real I–V curves on
LEDs, working potentiometers, NTC thermistors read by analogRead(), PWM
driving RC filters, transistors, op-amps, diodes, MOSFETs, etc.
Engine: eecircuit-engine (ngspice compiled to WebAssembly). Main bundle
stays at 2.4 MB; the 20 MB SPICE chunk only loads when the user activates
electrical mode. Disabled at build time via VITE_ELECTRICAL_SIM=false.
Frontend additions:
- simulation/spice/: SpiceEngine wrapper + lazy entry, NetlistBuilder with
UnionFind over wires, componentToSpice mapping (24 metadataIds incl.
real part numbers: 2N2222, 2N3055, BC547, IRF540, 2N7000, 1N4148,
1N4007, 1N4733, LEDs, NTC, op-amp ideal), CircuitScheduler with
debounced coalescing, AVRSpiceBridge for quasi-static co-simulation.
- store/useElectricalStore: Zustand slice, feature-flag aware.
- components/analog-ui/: ⚡ toolbar toggle + SVG voltage overlay.
- components/components-instruments/: Voltmeter, Ammeter probes.
- 62 tests (spice-*, netlist-builder, component-to-spice, instruments).
Sandbox (test/test_circuit/): 47-test validation sandbox that proved
the approach (hand-rolled MNA baseline + ngspice pipeline) before
porting to the app. Kept as reference.
Docs: docs/wiki/circuit-emulation-*.md (13 engineering pages covering
architecture, solvers, components, AVR bridge, gotchas, performance,
integration plan, API reference, appendix) + electrical-simulation-
user-guide.md (end-user facing).
Reference plan: test/test_circuit/plan/phase_8_velxio_implementation.md
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 19:11:54 +07:00
|
|
|
components: [
|
2026-04-22 02:45:45 +07:00
|
|
|
{ id: 'r1', metadataId: 'resistor', properties: { value: '10k' } },
|
|
|
|
|
{ id: 'ntc1', metadataId: 'ntc-temperature-sensor', properties: { temperature: 25 } },
|
feat: electrical simulation via ngspice-WASM (eecircuit-engine)
Adds full SPICE-accurate electrical simulation to Velxio, behind a lazy-
loaded ⚡ toolbar toggle. Arduino / ESP32 / RP2040 sketches now co-simulate
with real analog behaviour: correct voltages on wires, real I–V curves on
LEDs, working potentiometers, NTC thermistors read by analogRead(), PWM
driving RC filters, transistors, op-amps, diodes, MOSFETs, etc.
Engine: eecircuit-engine (ngspice compiled to WebAssembly). Main bundle
stays at 2.4 MB; the 20 MB SPICE chunk only loads when the user activates
electrical mode. Disabled at build time via VITE_ELECTRICAL_SIM=false.
Frontend additions:
- simulation/spice/: SpiceEngine wrapper + lazy entry, NetlistBuilder with
UnionFind over wires, componentToSpice mapping (24 metadataIds incl.
real part numbers: 2N2222, 2N3055, BC547, IRF540, 2N7000, 1N4148,
1N4007, 1N4733, LEDs, NTC, op-amp ideal), CircuitScheduler with
debounced coalescing, AVRSpiceBridge for quasi-static co-simulation.
- store/useElectricalStore: Zustand slice, feature-flag aware.
- components/analog-ui/: ⚡ toolbar toggle + SVG voltage overlay.
- components/components-instruments/: Voltmeter, Ammeter probes.
- 62 tests (spice-*, netlist-builder, component-to-spice, instruments).
Sandbox (test/test_circuit/): 47-test validation sandbox that proved
the approach (hand-rolled MNA baseline + ngspice pipeline) before
porting to the app. Kept as reference.
Docs: docs/wiki/circuit-emulation-*.md (13 engineering pages covering
architecture, solvers, components, AVR bridge, gotchas, performance,
integration plan, API reference, appendix) + electrical-simulation-
user-guide.md (end-user facing).
Reference plan: test/test_circuit/plan/phase_8_velxio_implementation.md
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 19:11:54 +07:00
|
|
|
],
|
|
|
|
|
wires: [
|
2026-04-22 02:45:45 +07:00
|
|
|
{
|
|
|
|
|
id: 'w1',
|
|
|
|
|
start: { componentId: 'uno', pinName: '5V' },
|
|
|
|
|
end: { componentId: 'r1', pinName: '1' },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'w2',
|
|
|
|
|
start: { componentId: 'r1', pinName: '2' },
|
|
|
|
|
end: { componentId: 'ntc1', pinName: '1' },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'w3',
|
|
|
|
|
start: { componentId: 'ntc1', pinName: '2' },
|
|
|
|
|
end: { componentId: 'uno', pinName: 'GND' },
|
|
|
|
|
},
|
feat: electrical simulation via ngspice-WASM (eecircuit-engine)
Adds full SPICE-accurate electrical simulation to Velxio, behind a lazy-
loaded ⚡ toolbar toggle. Arduino / ESP32 / RP2040 sketches now co-simulate
with real analog behaviour: correct voltages on wires, real I–V curves on
LEDs, working potentiometers, NTC thermistors read by analogRead(), PWM
driving RC filters, transistors, op-amps, diodes, MOSFETs, etc.
Engine: eecircuit-engine (ngspice compiled to WebAssembly). Main bundle
stays at 2.4 MB; the 20 MB SPICE chunk only loads when the user activates
electrical mode. Disabled at build time via VITE_ELECTRICAL_SIM=false.
Frontend additions:
- simulation/spice/: SpiceEngine wrapper + lazy entry, NetlistBuilder with
UnionFind over wires, componentToSpice mapping (24 metadataIds incl.
real part numbers: 2N2222, 2N3055, BC547, IRF540, 2N7000, 1N4148,
1N4007, 1N4733, LEDs, NTC, op-amp ideal), CircuitScheduler with
debounced coalescing, AVRSpiceBridge for quasi-static co-simulation.
- store/useElectricalStore: Zustand slice, feature-flag aware.
- components/analog-ui/: ⚡ toolbar toggle + SVG voltage overlay.
- components/components-instruments/: Voltmeter, Ammeter probes.
- 62 tests (spice-*, netlist-builder, component-to-spice, instruments).
Sandbox (test/test_circuit/): 47-test validation sandbox that proved
the approach (hand-rolled MNA baseline + ngspice pipeline) before
porting to the app. Kept as reference.
Docs: docs/wiki/circuit-emulation-*.md (13 engineering pages covering
architecture, solvers, components, AVR bridge, gotchas, performance,
integration plan, API reference, appendix) + electrical-simulation-
user-guide.md (end-user facing).
Reference plan: test/test_circuit/plan/phase_8_velxio_implementation.md
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 19:11:54 +07:00
|
|
|
],
|
|
|
|
|
boards: [
|
|
|
|
|
{
|
2026-04-22 02:45:45 +07:00
|
|
|
id: 'uno',
|
feat: electrical simulation via ngspice-WASM (eecircuit-engine)
Adds full SPICE-accurate electrical simulation to Velxio, behind a lazy-
loaded ⚡ toolbar toggle. Arduino / ESP32 / RP2040 sketches now co-simulate
with real analog behaviour: correct voltages on wires, real I–V curves on
LEDs, working potentiometers, NTC thermistors read by analogRead(), PWM
driving RC filters, transistors, op-amps, diodes, MOSFETs, etc.
Engine: eecircuit-engine (ngspice compiled to WebAssembly). Main bundle
stays at 2.4 MB; the 20 MB SPICE chunk only loads when the user activates
electrical mode. Disabled at build time via VITE_ELECTRICAL_SIM=false.
Frontend additions:
- simulation/spice/: SpiceEngine wrapper + lazy entry, NetlistBuilder with
UnionFind over wires, componentToSpice mapping (24 metadataIds incl.
real part numbers: 2N2222, 2N3055, BC547, IRF540, 2N7000, 1N4148,
1N4007, 1N4733, LEDs, NTC, op-amp ideal), CircuitScheduler with
debounced coalescing, AVRSpiceBridge for quasi-static co-simulation.
- store/useElectricalStore: Zustand slice, feature-flag aware.
- components/analog-ui/: ⚡ toolbar toggle + SVG voltage overlay.
- components/components-instruments/: Voltmeter, Ammeter probes.
- 62 tests (spice-*, netlist-builder, component-to-spice, instruments).
Sandbox (test/test_circuit/): 47-test validation sandbox that proved
the approach (hand-rolled MNA baseline + ngspice pipeline) before
porting to the app. Kept as reference.
Docs: docs/wiki/circuit-emulation-*.md (13 engineering pages covering
architecture, solvers, components, AVR bridge, gotchas, performance,
integration plan, API reference, appendix) + electrical-simulation-
user-guide.md (end-user facing).
Reference plan: test/test_circuit/plan/phase_8_velxio_implementation.md
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 19:11:54 +07:00
|
|
|
vcc: 5,
|
|
|
|
|
pins: {},
|
|
|
|
|
groundPinNames: ['GND'],
|
2026-04-22 02:45:45 +07:00
|
|
|
vccPinNames: ['5V'],
|
feat: electrical simulation via ngspice-WASM (eecircuit-engine)
Adds full SPICE-accurate electrical simulation to Velxio, behind a lazy-
loaded ⚡ toolbar toggle. Arduino / ESP32 / RP2040 sketches now co-simulate
with real analog behaviour: correct voltages on wires, real I–V curves on
LEDs, working potentiometers, NTC thermistors read by analogRead(), PWM
driving RC filters, transistors, op-amps, diodes, MOSFETs, etc.
Engine: eecircuit-engine (ngspice compiled to WebAssembly). Main bundle
stays at 2.4 MB; the 20 MB SPICE chunk only loads when the user activates
electrical mode. Disabled at build time via VITE_ELECTRICAL_SIM=false.
Frontend additions:
- simulation/spice/: SpiceEngine wrapper + lazy entry, NetlistBuilder with
UnionFind over wires, componentToSpice mapping (24 metadataIds incl.
real part numbers: 2N2222, 2N3055, BC547, IRF540, 2N7000, 1N4148,
1N4007, 1N4733, LEDs, NTC, op-amp ideal), CircuitScheduler with
debounced coalescing, AVRSpiceBridge for quasi-static co-simulation.
- store/useElectricalStore: Zustand slice, feature-flag aware.
- components/analog-ui/: ⚡ toolbar toggle + SVG voltage overlay.
- components/components-instruments/: Voltmeter, Ammeter probes.
- 62 tests (spice-*, netlist-builder, component-to-spice, instruments).
Sandbox (test/test_circuit/): 47-test validation sandbox that proved
the approach (hand-rolled MNA baseline + ngspice pipeline) before
porting to the app. Kept as reference.
Docs: docs/wiki/circuit-emulation-*.md (13 engineering pages covering
architecture, solvers, components, AVR bridge, gotchas, performance,
integration plan, API reference, appendix) + electrical-simulation-
user-guide.md (end-user facing).
Reference plan: test/test_circuit/plan/phase_8_velxio_implementation.md
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 19:11:54 +07:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
analysis: { kind: 'op' },
|
|
|
|
|
});
|
|
|
|
|
const result = await runNetlist(netlist);
|
|
|
|
|
// Net between R1 and NTC is auto-named; find it.
|
|
|
|
|
const midNet = netlist.match(/R_r1 vcc_rail (\S+) /)?.[1];
|
|
|
|
|
expect(midNet).toBeTruthy();
|
|
|
|
|
const v = (result.vec(`v(${midNet})`) as number[])[0];
|
|
|
|
|
expect(v).toBeCloseTo(2.5, 1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('adds auto pull-down on floating cap-only node', () => {
|
|
|
|
|
// Two caps share a node (net x) that only touches capacitors → DC-floating.
|
2026-04-18 05:27:18 +07:00
|
|
|
const { netlist } = buildNetlist({
|
feat: electrical simulation via ngspice-WASM (eecircuit-engine)
Adds full SPICE-accurate electrical simulation to Velxio, behind a lazy-
loaded ⚡ toolbar toggle. Arduino / ESP32 / RP2040 sketches now co-simulate
with real analog behaviour: correct voltages on wires, real I–V curves on
LEDs, working potentiometers, NTC thermistors read by analogRead(), PWM
driving RC filters, transistors, op-amps, diodes, MOSFETs, etc.
Engine: eecircuit-engine (ngspice compiled to WebAssembly). Main bundle
stays at 2.4 MB; the 20 MB SPICE chunk only loads when the user activates
electrical mode. Disabled at build time via VITE_ELECTRICAL_SIM=false.
Frontend additions:
- simulation/spice/: SpiceEngine wrapper + lazy entry, NetlistBuilder with
UnionFind over wires, componentToSpice mapping (24 metadataIds incl.
real part numbers: 2N2222, 2N3055, BC547, IRF540, 2N7000, 1N4148,
1N4007, 1N4733, LEDs, NTC, op-amp ideal), CircuitScheduler with
debounced coalescing, AVRSpiceBridge for quasi-static co-simulation.
- store/useElectricalStore: Zustand slice, feature-flag aware.
- components/analog-ui/: ⚡ toolbar toggle + SVG voltage overlay.
- components/components-instruments/: Voltmeter, Ammeter probes.
- 62 tests (spice-*, netlist-builder, component-to-spice, instruments).
Sandbox (test/test_circuit/): 47-test validation sandbox that proved
the approach (hand-rolled MNA baseline + ngspice pipeline) before
porting to the app. Kept as reference.
Docs: docs/wiki/circuit-emulation-*.md (13 engineering pages covering
architecture, solvers, components, AVR bridge, gotchas, performance,
integration plan, API reference, appendix) + electrical-simulation-
user-guide.md (end-user facing).
Reference plan: test/test_circuit/plan/phase_8_velxio_implementation.md
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 19:11:54 +07:00
|
|
|
components: [
|
|
|
|
|
{ id: 'c1', metadataId: 'capacitor', properties: { value: '1u' } },
|
|
|
|
|
{ id: 'c2', metadataId: 'capacitor', properties: { value: '1u' } },
|
|
|
|
|
],
|
|
|
|
|
wires: [
|
2026-04-22 02:45:45 +07:00
|
|
|
{
|
|
|
|
|
id: 'w_share',
|
|
|
|
|
start: { componentId: 'c1', pinName: '1' },
|
|
|
|
|
end: { componentId: 'c2', pinName: '1' },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'w1',
|
|
|
|
|
start: { componentId: 'c1', pinName: '2' },
|
|
|
|
|
end: { componentId: 'board', pinName: 'GND' },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'w2',
|
|
|
|
|
start: { componentId: 'c2', pinName: '2' },
|
|
|
|
|
end: { componentId: 'board', pinName: 'GND' },
|
|
|
|
|
},
|
feat: electrical simulation via ngspice-WASM (eecircuit-engine)
Adds full SPICE-accurate electrical simulation to Velxio, behind a lazy-
loaded ⚡ toolbar toggle. Arduino / ESP32 / RP2040 sketches now co-simulate
with real analog behaviour: correct voltages on wires, real I–V curves on
LEDs, working potentiometers, NTC thermistors read by analogRead(), PWM
driving RC filters, transistors, op-amps, diodes, MOSFETs, etc.
Engine: eecircuit-engine (ngspice compiled to WebAssembly). Main bundle
stays at 2.4 MB; the 20 MB SPICE chunk only loads when the user activates
electrical mode. Disabled at build time via VITE_ELECTRICAL_SIM=false.
Frontend additions:
- simulation/spice/: SpiceEngine wrapper + lazy entry, NetlistBuilder with
UnionFind over wires, componentToSpice mapping (24 metadataIds incl.
real part numbers: 2N2222, 2N3055, BC547, IRF540, 2N7000, 1N4148,
1N4007, 1N4733, LEDs, NTC, op-amp ideal), CircuitScheduler with
debounced coalescing, AVRSpiceBridge for quasi-static co-simulation.
- store/useElectricalStore: Zustand slice, feature-flag aware.
- components/analog-ui/: ⚡ toolbar toggle + SVG voltage overlay.
- components/components-instruments/: Voltmeter, Ammeter probes.
- 62 tests (spice-*, netlist-builder, component-to-spice, instruments).
Sandbox (test/test_circuit/): 47-test validation sandbox that proved
the approach (hand-rolled MNA baseline + ngspice pipeline) before
porting to the app. Kept as reference.
Docs: docs/wiki/circuit-emulation-*.md (13 engineering pages covering
architecture, solvers, components, AVR bridge, gotchas, performance,
integration plan, API reference, appendix) + electrical-simulation-
user-guide.md (end-user facing).
Reference plan: test/test_circuit/plan/phase_8_velxio_implementation.md
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 19:11:54 +07:00
|
|
|
],
|
|
|
|
|
boards: [{ id: 'board', vcc: 5, pins: {}, groundPinNames: ['GND'] }],
|
|
|
|
|
analysis: { kind: 'op' },
|
|
|
|
|
});
|
|
|
|
|
expect(netlist).toMatch(/R_autopull_/);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('PWM pin emits DC-equivalent voltage source', () => {
|
2026-04-18 05:27:18 +07:00
|
|
|
const { netlist } = buildNetlist({
|
feat: electrical simulation via ngspice-WASM (eecircuit-engine)
Adds full SPICE-accurate electrical simulation to Velxio, behind a lazy-
loaded ⚡ toolbar toggle. Arduino / ESP32 / RP2040 sketches now co-simulate
with real analog behaviour: correct voltages on wires, real I–V curves on
LEDs, working potentiometers, NTC thermistors read by analogRead(), PWM
driving RC filters, transistors, op-amps, diodes, MOSFETs, etc.
Engine: eecircuit-engine (ngspice compiled to WebAssembly). Main bundle
stays at 2.4 MB; the 20 MB SPICE chunk only loads when the user activates
electrical mode. Disabled at build time via VITE_ELECTRICAL_SIM=false.
Frontend additions:
- simulation/spice/: SpiceEngine wrapper + lazy entry, NetlistBuilder with
UnionFind over wires, componentToSpice mapping (24 metadataIds incl.
real part numbers: 2N2222, 2N3055, BC547, IRF540, 2N7000, 1N4148,
1N4007, 1N4733, LEDs, NTC, op-amp ideal), CircuitScheduler with
debounced coalescing, AVRSpiceBridge for quasi-static co-simulation.
- store/useElectricalStore: Zustand slice, feature-flag aware.
- components/analog-ui/: ⚡ toolbar toggle + SVG voltage overlay.
- components/components-instruments/: Voltmeter, Ammeter probes.
- 62 tests (spice-*, netlist-builder, component-to-spice, instruments).
Sandbox (test/test_circuit/): 47-test validation sandbox that proved
the approach (hand-rolled MNA baseline + ngspice pipeline) before
porting to the app. Kept as reference.
Docs: docs/wiki/circuit-emulation-*.md (13 engineering pages covering
architecture, solvers, components, AVR bridge, gotchas, performance,
integration plan, API reference, appendix) + electrical-simulation-
user-guide.md (end-user facing).
Reference plan: test/test_circuit/plan/phase_8_velxio_implementation.md
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 19:11:54 +07:00
|
|
|
components: [],
|
|
|
|
|
wires: [
|
2026-04-22 02:45:45 +07:00
|
|
|
{
|
|
|
|
|
id: 'w1',
|
|
|
|
|
start: { componentId: 'uno', pinName: 'D9' },
|
|
|
|
|
end: { componentId: 'uno', pinName: 'GND' },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
boards: [
|
|
|
|
|
{
|
|
|
|
|
id: 'uno',
|
|
|
|
|
vcc: 5,
|
|
|
|
|
pins: { D9: { type: 'pwm', duty: 0.5 } },
|
|
|
|
|
groundPinNames: ['GND'],
|
|
|
|
|
},
|
feat: electrical simulation via ngspice-WASM (eecircuit-engine)
Adds full SPICE-accurate electrical simulation to Velxio, behind a lazy-
loaded ⚡ toolbar toggle. Arduino / ESP32 / RP2040 sketches now co-simulate
with real analog behaviour: correct voltages on wires, real I–V curves on
LEDs, working potentiometers, NTC thermistors read by analogRead(), PWM
driving RC filters, transistors, op-amps, diodes, MOSFETs, etc.
Engine: eecircuit-engine (ngspice compiled to WebAssembly). Main bundle
stays at 2.4 MB; the 20 MB SPICE chunk only loads when the user activates
electrical mode. Disabled at build time via VITE_ELECTRICAL_SIM=false.
Frontend additions:
- simulation/spice/: SpiceEngine wrapper + lazy entry, NetlistBuilder with
UnionFind over wires, componentToSpice mapping (24 metadataIds incl.
real part numbers: 2N2222, 2N3055, BC547, IRF540, 2N7000, 1N4148,
1N4007, 1N4733, LEDs, NTC, op-amp ideal), CircuitScheduler with
debounced coalescing, AVRSpiceBridge for quasi-static co-simulation.
- store/useElectricalStore: Zustand slice, feature-flag aware.
- components/analog-ui/: ⚡ toolbar toggle + SVG voltage overlay.
- components/components-instruments/: Voltmeter, Ammeter probes.
- 62 tests (spice-*, netlist-builder, component-to-spice, instruments).
Sandbox (test/test_circuit/): 47-test validation sandbox that proved
the approach (hand-rolled MNA baseline + ngspice pipeline) before
porting to the app. Kept as reference.
Docs: docs/wiki/circuit-emulation-*.md (13 engineering pages covering
architecture, solvers, components, AVR bridge, gotchas, performance,
integration plan, API reference, appendix) + electrical-simulation-
user-guide.md (end-user facing).
Reference plan: test/test_circuit/plan/phase_8_velxio_implementation.md
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 19:11:54 +07:00
|
|
|
],
|
|
|
|
|
analysis: { kind: 'op' },
|
|
|
|
|
});
|
|
|
|
|
// D9 is wired directly to GND → same net as ground → no source emitted
|
|
|
|
|
// (this is a degenerate case; just ensure we don't crash)
|
|
|
|
|
expect(netlist).toMatch(/\.end/);
|
|
|
|
|
});
|
|
|
|
|
});
|