@tscircuit/ngspice-spice-engine 0.0.8 → 0.0.9
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.
- package/dist/index.d.ts +5 -2
- package/dist/index.js +31 -4
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -15,7 +15,10 @@ interface VoltageGraph {
|
|
|
15
15
|
time: number[];
|
|
16
16
|
voltage: number[];
|
|
17
17
|
}
|
|
18
|
+
interface NgspiceSpiceEngineOptions {
|
|
19
|
+
pspiceCompatibility?: boolean;
|
|
20
|
+
}
|
|
18
21
|
declare const eecircuitResultToVGraphs: (result: ResultType, spiceString: string) => VoltageGraph[];
|
|
19
|
-
declare const createNgspiceSpiceEngine: () => Promise<SpiceEngine>;
|
|
22
|
+
declare const createNgspiceSpiceEngine: (options?: NgspiceSpiceEngineOptions) => Promise<SpiceEngine>;
|
|
20
23
|
|
|
21
|
-
export { type TranParams, createNgspiceSpiceEngine, createNgspiceSpiceEngine as default, eecircuitResultToVGraphs, parseTranParams };
|
|
24
|
+
export { type NgspiceSpiceEngineOptions, type TranParams, createNgspiceSpiceEngine, createNgspiceSpiceEngine as default, eecircuitResultToVGraphs, parseTranParams };
|
package/dist/index.js
CHANGED
|
@@ -240,9 +240,31 @@ var voltageGraphsToCircuitJson = (graphs, spiceString) => {
|
|
|
240
240
|
end_time_ms: (tranParams?.tstop ?? 0) * 1e3
|
|
241
241
|
}));
|
|
242
242
|
};
|
|
243
|
-
var
|
|
243
|
+
var configureNgBehavior = (simulation, pspiceCompatibility) => {
|
|
244
|
+
const simulationWithCommandList = simulation;
|
|
245
|
+
const commandList = simulationWithCommandList.commandList;
|
|
246
|
+
if (!Array.isArray(commandList)) {
|
|
247
|
+
if (pspiceCompatibility) {
|
|
248
|
+
throw new Error(
|
|
249
|
+
"Unable to enable PSPICE compatibility: eecircuit-engine commandList is not accessible"
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const ngBehaviorCommand = pspiceCompatibility ? "set ngbehavior=psa" : "unset ngbehavior";
|
|
255
|
+
const sourceCommandIndex = commandList.findIndex(
|
|
256
|
+
(command) => /^\s*source\s+test\.cir\s*$/i.test(command)
|
|
257
|
+
);
|
|
258
|
+
if (sourceCommandIndex === -1) {
|
|
259
|
+
commandList.unshift(ngBehaviorCommand);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
commandList.splice(sourceCommandIndex, 0, ngBehaviorCommand);
|
|
263
|
+
};
|
|
264
|
+
var simulate = async (spiceString, options) => {
|
|
244
265
|
const simulation = await getSimulation();
|
|
245
266
|
simulation.setNetList(spiceString);
|
|
267
|
+
configureNgBehavior(simulation, options.pspiceCompatibility);
|
|
246
268
|
let result;
|
|
247
269
|
try {
|
|
248
270
|
result = await simulation.runSim();
|
|
@@ -261,9 +283,14 @@ var simulate = async (spiceString) => {
|
|
|
261
283
|
)
|
|
262
284
|
};
|
|
263
285
|
};
|
|
264
|
-
var createNgspiceSpiceEngine = async () =>
|
|
265
|
-
|
|
266
|
-
|
|
286
|
+
var createNgspiceSpiceEngine = async (options = {}) => {
|
|
287
|
+
const resolvedOptions = {
|
|
288
|
+
pspiceCompatibility: options.pspiceCompatibility ?? false
|
|
289
|
+
};
|
|
290
|
+
return {
|
|
291
|
+
simulate: (spiceString) => simulate(spiceString, resolvedOptions)
|
|
292
|
+
};
|
|
293
|
+
};
|
|
267
294
|
var index_default = createNgspiceSpiceEngine;
|
|
268
295
|
export {
|
|
269
296
|
createNgspiceSpiceEngine,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscircuit/ngspice-spice-engine",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "A tscircuit-compatible SPICE engine using ngspice.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"typecheck": "tsc --noEmit"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"eecircuit-engine": "^1.
|
|
20
|
+
"eecircuit-engine": "^1.7.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@tscircuit/props": "^0.0.374",
|