1- import type { AnyCircuitElement } from "circuit-json"
1+ import type { AnyCircuitElement , SimulationVoltageSource } from "circuit-json"
22import { SpiceComponent } from "lib/spice-classes/SpiceComponent"
33import type { SpiceNetlist } from "lib/spice-classes/SpiceNetlist"
44import { VoltageSourceCommand } from "lib/spice-commands"
55
66export const processSimulationVoltageSources = (
77 netlist : SpiceNetlist ,
8- simulationVoltageSources : AnyCircuitElement [ ] ,
8+ simulationVoltageSources : SimulationVoltageSource [ ] ,
99 nodeMap : Map < string , string > ,
1010) => {
1111 for ( const simSource of simulationVoltageSources ) {
1212 if ( simSource . type !== "simulation_voltage_source" ) continue
1313
14- if ( ( simSource as any ) . is_dc_source === false ) {
14+ if ( simSource . is_dc_source === false ) {
1515 // AC Source
1616 if (
1717 "terminal1_source_port_id" in simSource &&
1818 "terminal2_source_port_id" in simSource &&
19- ( simSource as any ) . terminal1_source_port_id &&
20- ( simSource as any ) . terminal2_source_port_id
19+ simSource . terminal1_source_port_id &&
20+ simSource . terminal2_source_port_id
2121 ) {
2222 const positiveNode =
23- nodeMap . get ( ( simSource as any ) . terminal1_source_port_id ) || "0"
23+ nodeMap . get ( simSource . terminal1_source_port_id ) || "0"
2424 const negativeNode =
25- nodeMap . get ( ( simSource as any ) . terminal2_source_port_id ) || "0"
25+ nodeMap . get ( simSource . terminal2_source_port_id ) || "0"
2626
2727 let value = ""
28- const wave_shape = ( simSource as any ) . wave_shape
28+ const wave_shape = simSource . wave_shape
2929 if ( wave_shape === "sinewave" ) {
3030 const v_offset = 0 // not provided in circuitJson
31- const v_peak = ( simSource as any ) . voltage ?? 0
32- const freq = ( simSource as any ) . frequency ?? 0
31+ const v_peak = simSource . voltage ?? 0
32+ const freq = simSource . frequency ?? 0
3333 const delay = 0 // not provided in circuitJson
3434 const damping_factor = 0 // not provided in circuitJson
35- const phase = ( simSource as any ) . phase ?? 0
35+ const phase = simSource . phase ?? 0
3636 if ( freq > 0 ) {
3737 value = `SIN(${ v_offset } ${ v_peak } ${ freq } ${ delay } ${ damping_factor } ${ phase } )`
3838 } else {
39- value = `DC ${ ( simSource as any ) . voltage ?? 0 } `
39+ value = `DC ${ simSource . voltage ?? 0 } `
4040 }
4141 } else if ( wave_shape === "square" ) {
4242 const v_initial = 0
43- const v_pulsed = ( simSource as any ) . voltage ?? 0
44- const freq = ( simSource as any ) . frequency ?? 0
43+ const v_pulsed = simSource . voltage ?? 0
44+ const freq = simSource . frequency ?? 0
4545 const period_from_freq = freq === 0 ? Infinity : 1 / freq
46- const period = ( simSource as any ) . period ?? period_from_freq
47- const duty_cycle = ( simSource as any ) . duty_cycle ?? 0.5
46+ const period = period_from_freq
47+ const duty_cycle = simSource . duty_cycle ?? 0.5
4848 const pulse_width = period * duty_cycle
4949 const delay = 0
5050 const rise_time = "1n"
5151 const fall_time = "1n"
5252 value = `PULSE(${ v_initial } ${ v_pulsed } ${ delay } ${ rise_time } ${ fall_time } ${ pulse_width } ${ period } )`
53- } else if ( ( simSource as any ) . voltage !== undefined ) {
54- value = `DC ${ ( simSource as any ) . voltage } `
53+ } else if ( simSource . voltage !== undefined ) {
54+ value = `DC ${ simSource . voltage } `
5555 }
5656
5757 if ( value ) {
@@ -72,18 +72,14 @@ export const processSimulationVoltageSources = (
7272 }
7373 } else {
7474 // DC Source (is_dc_source is true or undefined)
75- const positivePortId =
76- ( simSource as any ) . positive_source_port_id ??
77- ( simSource as any ) . terminal1_source_port_id
78- const negativePortId =
79- ( simSource as any ) . negative_source_port_id ??
80- ( simSource as any ) . terminal2_source_port_id
75+ const positivePortId = simSource . positive_source_port_id
76+ const negativePortId = simSource . negative_source_port_id
8177
8278 if (
8379 positivePortId &&
8480 negativePortId &&
8581 "voltage" in simSource &&
86- ( simSource as any ) . voltage !== undefined
82+ simSource . voltage !== undefined
8783 ) {
8884 const positiveNode = nodeMap . get ( positivePortId ) || "0"
8985 const negativeNode = nodeMap . get ( negativePortId ) || "0"
0 commit comments