spicemapper
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

介绍

SpiceMapper是一个专门为了生成SPICE语句的JS库。SpiceMapper提供了一个电路的数据结构,并提供了方便的API用来构建电路,和生成SPICE的Netlist语句。

使用方法

快速开始

使用npm来下载spicemapper

npm install spicemapper

之后在你的文件里面引入spicemapper,其中Circuit是电路类,Components包含常用的电路元件,Types包含电路元件的类型和单位。

import { Circuit, Resistor, VoltageSource, UnitType } from 'spicemapper';

使用SpiceMapper的一步要创建一个电路对象:

const cir = new Circuit();

再调用相关API创建元件,搭建电路:

cir.add(new Resistor(1, 100, UnitType.K));
cir.add(new VoltageSource(1, 10, UnitType.None));
cir.add(new Resistor(2, 1000, UnitType.None));

cir.connectGround('R1', 0);
cir.connectGround('V1', 1);
cir.connect('R1', 1, 'V1', 0);
cir.connect('R2', 1, 'R1', 1);
cir.connect('R2', 0, 'R1', 0);

最后调用电路generate()输出SPICE Netlist:

console.log(cir.generate()); 
//output:
// R1 0 1 100K
// V1 1 0 10
// R2 0 1 1000 

Component

通过此类创建一个Component

const comp = new ComponentBase(obj);
//obj满足以下形式
obj = {
  type, //ComponentType
  name, //string | number
  value, //number
  unit, //UnitType
  maxDegree, //number
}

实际上,这个objIComponent的一个实例。

UnitTypeComponentType

UnitTypeComponentType分别是两个枚举值,其中UnitType表示诸如K,M,P...的倍率单位,ComponentType表示I电流源,R电阻...之类的元件类型。

Circuit

circuit是一个表示电路的数据结构,他是一个图。通过调用API可以构建起一个电路。首先我们创建电路实例:

const cir = new Circuit();
  1. 在电路中加入/删除元件
     cir.add(component); //传入component实例
     cir.delete(component); //传入component实例或元件全名
  2. 将元件接地
    cir.connectGround(component);//传入component实例或元件全名
  3. 将两个元件接通/断开链接
     cir.connect(compA,AIndex,compB,BIndex); //分别为component实例和对应元件端口,对于二端元件为0,1
     cir.disconnect(compA,AIndex,compB,BIndex);//分别为component实例和对应元件端口
  4. 输出SPICE Netlist
     cir.generate(); //返回SPICE Netlist字符串
  5. 输出节点电压方程
      cir.generateFomula(); //返回latex格式的节点电压方程

不足与目标

不足

  1. 本项目暂不支持多端元件
  2. 本项目各方面还未完善
  3. 本项目采用的算法并不高效

目标

  1. 在未来版本中将完善元件,API易用性--已完成 50%
  2. 将支持多端元件,支持元件自定义
  • 1.1.0新增:
    1. 输出节点电压方程
    2. 增加电容、电感、电流源
    3. 增加交流输出

Readme

Keywords

Package Sidebar

Install

npm i spicemapper

Weekly Downloads

5

Version

1.1.2

License

ISC

Unpacked Size

77.1 kB

Total Files

45

Last publish

Collaborators

  • shdancer