circuit-json-to-spice 0.0.30 → 0.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,6 +3,7 @@ import { SpiceComponent } from "./spice-classes/SpiceComponent"
|
|
|
3
3
|
import { ResistorCommand } from "./spice-commands/ResistorCommand"
|
|
4
4
|
import { CapacitorCommand } from "./spice-commands/CapacitorCommand"
|
|
5
5
|
import { VoltageSourceCommand } from "./spice-commands/VoltageSourceCommand"
|
|
6
|
+
import { CurrentSourceCommand } from "./spice-commands/CurrentSourceCommand"
|
|
6
7
|
import { BJTCommand } from "./spice-commands/BJTCommand"
|
|
7
8
|
import { DiodeCommand } from "./spice-commands/DiodeCommand"
|
|
8
9
|
import { InductorCommand } from "./spice-commands/InductorCommand"
|
|
@@ -565,6 +566,94 @@ export function circuitJsonToSpice(
|
|
|
565
566
|
}
|
|
566
567
|
}
|
|
567
568
|
|
|
569
|
+
// Process simulation current sources
|
|
570
|
+
for (const simSource of su(circuitJson).simulation_current_source.list()) {
|
|
571
|
+
if (simSource.type !== "simulation_current_source") continue
|
|
572
|
+
|
|
573
|
+
if ((simSource as any).is_dc_source === false) {
|
|
574
|
+
// AC/PULSE Source
|
|
575
|
+
const positivePortId = (simSource as any).terminal1_source_port_id
|
|
576
|
+
const negativePortId = (simSource as any).terminal2_source_port_id
|
|
577
|
+
|
|
578
|
+
if (positivePortId && negativePortId) {
|
|
579
|
+
const positiveNode = nodeMap.get(positivePortId) || "0"
|
|
580
|
+
const negativeNode = nodeMap.get(negativePortId) || "0"
|
|
581
|
+
|
|
582
|
+
let value = ""
|
|
583
|
+
const wave_shape = (simSource as any).wave_shape
|
|
584
|
+
if (wave_shape === "sinewave") {
|
|
585
|
+
const i_offset = 0 // not provided
|
|
586
|
+
const i_peak = ((simSource as any).peak_to_peak_current ?? 0) / 2
|
|
587
|
+
const freq = (simSource as any).frequency ?? 0
|
|
588
|
+
const delay = 0
|
|
589
|
+
const damping_factor = 0
|
|
590
|
+
const phase = (simSource as any).phase ?? 0
|
|
591
|
+
if (freq > 0) {
|
|
592
|
+
value = `SIN(${i_offset} ${i_peak} ${freq} ${delay} ${damping_factor} ${phase})`
|
|
593
|
+
} else {
|
|
594
|
+
value = `DC ${i_peak}`
|
|
595
|
+
}
|
|
596
|
+
} else if (wave_shape === "square") {
|
|
597
|
+
const i_initial = 0
|
|
598
|
+
const i_pulsed = (simSource as any).peak_to_peak_current ?? 0
|
|
599
|
+
const freq = (simSource as any).frequency ?? 0
|
|
600
|
+
const period_from_freq = freq === 0 ? Infinity : 1 / freq
|
|
601
|
+
const period = (simSource as any).period ?? period_from_freq
|
|
602
|
+
const duty_cycle = (simSource as any).duty_cycle ?? 0.5
|
|
603
|
+
const pulse_width = period * duty_cycle
|
|
604
|
+
const delay = 0
|
|
605
|
+
const rise_time = "1n"
|
|
606
|
+
const fall_time = "1n"
|
|
607
|
+
value = `PULSE(${i_initial} ${i_pulsed} ${delay} ${rise_time} ${fall_time} ${pulse_width} ${period})`
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
if (value) {
|
|
611
|
+
const currentSourceCmd = new CurrentSourceCommand({
|
|
612
|
+
name: simSource.simulation_current_source_id,
|
|
613
|
+
positiveNode,
|
|
614
|
+
negativeNode,
|
|
615
|
+
value,
|
|
616
|
+
})
|
|
617
|
+
|
|
618
|
+
const spiceComponent = new SpiceComponent(
|
|
619
|
+
simSource.simulation_current_source_id,
|
|
620
|
+
currentSourceCmd,
|
|
621
|
+
[positiveNode, negativeNode],
|
|
622
|
+
)
|
|
623
|
+
netlist.addComponent(spiceComponent)
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
} else {
|
|
627
|
+
// DC Source
|
|
628
|
+
const positivePortId = (simSource as any).positive_source_port_id
|
|
629
|
+
const negativePortId = (simSource as any).negative_source_port_id
|
|
630
|
+
|
|
631
|
+
if (
|
|
632
|
+
positivePortId &&
|
|
633
|
+
negativePortId &&
|
|
634
|
+
"current" in simSource &&
|
|
635
|
+
(simSource as any).current !== undefined
|
|
636
|
+
) {
|
|
637
|
+
const positiveNode = nodeMap.get(positivePortId) || "0"
|
|
638
|
+
const negativeNode = nodeMap.get(negativePortId) || "0"
|
|
639
|
+
|
|
640
|
+
const currentSourceCmd = new CurrentSourceCommand({
|
|
641
|
+
name: simSource.simulation_current_source_id,
|
|
642
|
+
positiveNode,
|
|
643
|
+
negativeNode,
|
|
644
|
+
value: `DC ${(simSource as any).current}`,
|
|
645
|
+
})
|
|
646
|
+
|
|
647
|
+
const spiceComponent = new SpiceComponent(
|
|
648
|
+
simSource.simulation_current_source_id,
|
|
649
|
+
currentSourceCmd,
|
|
650
|
+
[positiveNode, negativeNode],
|
|
651
|
+
)
|
|
652
|
+
netlist.addComponent(spiceComponent)
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
568
657
|
const simExperiment = circuitJson.find(
|
|
569
658
|
(elm) => elm.type === "simulation_experiment",
|
|
570
659
|
)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "circuit-json-to-spice",
|
|
3
3
|
"main": "dist/index.js",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.31",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsup-node ./lib/index.ts --dts --format esm --sourcemap inline -d dist",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@tscircuit/circuit-json-util": "^0.0.72",
|
|
17
17
|
"@types/bun": "^1.2.15",
|
|
18
18
|
"bun-match-svg": "^0.0.13",
|
|
19
|
-
"circuit-json": "^0.0.
|
|
19
|
+
"circuit-json": "^0.0.350",
|
|
20
20
|
"eecircuit-engine": "^1.5.2",
|
|
21
21
|
"tscircuit": "^0.0.936",
|
|
22
22
|
"tsup": "^8.4.0"
|