npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tongleen/modelforge-2d

v0.1.0

Published

TypeScript 库,用于生成 TCAD 模型生成脚本,支持多后端(SILVACO / Sentaurus)与 SVG 预览

Downloads

16

Readme

modelforge-2d

TypeScript 库,用于生成 TCAD(Technology Computer-Aided Design)模型生成脚本。支持多 TCAD 后端(SILVACO / Sentaurus),并可生成 SVG 可视化预览。

特性

  • 多后端支持:SILVACO(已实现)、Sentaurus(开发中)、Preview(SVG 可视化)
  • 类型安全:完整的 TypeScript 泛型支持,确保材料和掺杂剂类型的一致性
  • 自动区域处理:基于 clipper2-ts 的多边形布尔运算,自动处理区域重叠与裁剪
  • SVG 预览:生成可交互的 HTML 页面,支持缩放和平移
  • 模块化 API:清晰的 draw、electrode、doping、mesh 模块

安装

作为依赖安装

npm install @tongleen/modelforge-2d
# 或
pnpm add @tongleen/modelforge-2d
# 或
yarn add @tongleen/modelforge-2d

快速开始

import Structure2D from "@tongleen/modelforge-2d";
import { writeFileSync } from "node:fs";

type Material = "Si" | "Oxide" | "Metal";
type Dopant = "Boron" | "Phosphorus";

// 创建结构定义,指定目标后端,解包各模块
// 使用 "Preview" 后端可生成 SVG 预览;切换为 "SILVACO" 则输出命令脚本
const { draw, electrode, doping, mesh, gen, meta } = Structure2D<
    Material,
    Dopant
>("Preview", "meshed.str", "bnd.str");

// 坐标系约定:y 正方向向下(顶部 y 小,底部 y 大),单位 μm

// 绘制衬底矩形(最底部)
const substrate = draw.rectangle({
    name: "substrate",
    material: "Si",
    p0: { x: 0, y: 4 },
    p1: { x: 10, y: 9 },
});

// 绘制栅氧层多边形(衬底上方)
const gate_oxide = draw.polygon({
    name: "gate_oxide",
    material: "Oxide",
    positions: [
        { x: 0, y: 3 },
        { x: 10, y: 3 },
        { x: 10, y: 4 },
        { x: 0, y: 4 },
    ],
});

// 绘制栅极金属区域(最顶部)
const gate_metal = draw.rectangle({
    name: "gate_metal",
    material: "Metal",
    p0: { x: 4, y: 2 },
    p1: { x: 6, y: 3 },
});

// 设置电极(栅极金属作为电极)
electrode.add({
    name: "Gate",
    regions: [gate_metal],
});

// 添加均匀掺杂
doping.constant({
    name: "sub_doping",
    dopant: "Boron",
    concentration: 1e16,
    kind: "region",
    region: substrate,
});

// 添加高斯掺杂(从衬底表面向下注入)
doping.gaussian({
    name: "source_implant",
    start: { x: 2, y: 4 },
    end: { x: 2, y: 9 },
    dopant: "Phosphorus",
    kind: "conc",
    peak_conc: 1e20,
    another_conc: 1e18,
    another_depth: 1,
    polar: "Both",
});

// 网格细化(按区域选择,作用于栅氧层)
mesh.refineUniform({
    name: "fine_mesh",
    kind: "region",
    region: gate_oxide,
    max_size: 0.1,
});

// 生成 SVG 预览 HTML 并保存
const html = gen();
writeFileSync("output.html", html);
writeFileSync("meta.json", meta());

运行后在浏览器中打开 output.html 即可查看器件结构预览。

API 文档

Structure2D<M, D>(target, mesh_file, boundary_file)

创建一个结构定义实例。

| 参数 | 类型 | 说明 | | --------------- | --------------------------------------- | ---------------- | | target | "SILVACO" \| "Sentaurus" \| "Preview" | 目标 TCAD 后端 | | mesh_file | string | 网格输出文件路径 | | boundary_file | string | 边界文件路径 |

返回对象包含以下模块:

draw

  • rectangle(rect) - 绘制矩形区域
  • polygon(polygon) - 绘制多边形区域(至少 3 个顶点)
  • setNewLayerPosition("top" \| "bottom") - 设置新区域的层级位置

electrode

  • add(electrode) - 添加电极定义

doping

  • constant(doping) - 添加均匀掺杂
  • gaussian(doping) - 添加高斯掺杂

mesh

  • refineUniform(refine) - 均匀网格细化
  • refineInterface(refine) - 界面网格细化
  • refineDoping(refine) - 掺杂浓度自适应细化

gen()

根据目标后端生成脚本字符串。

meta()

返回区域映射的 JSON 字符串(用于调试)。

类型定义

选择器 (Selector)

掺杂和网格细化操作可通过以下方式选择区域:

  • kind: "region" - 按区域名称
  • kind: "material" - 按材料类型
  • kind: "position" - 按坐标矩形

掺杂方式

  • Constant:在指定区域/坐标内均匀掺杂
  • Gaussian:沿指定方向的高斯分布掺杂
    • 支持浓度参数(conc)或剂量参数(dose)
    • 支持横向衰减(lateral)

网格细化

  • Uniform:均匀细化
  • Interface:界面处细化
  • Doping:掺杂浓度梯度处细化

后端说明

| 后端 | 状态 | 输出格式 | | --------- | --------- | -------------------------------------- | | SILVACO | ✅ 已实现 | Victory Device / Victory Mesh 命令脚本 | | Sentaurus | 🚧 开发中 | Sentaurus 命令脚本 | | Preview | ✅ 已实现 | 可交互 HTML/SVG 页面 |

项目结构

modelforge-2d/
├── src/
│   ├── api/                    # 用户 API 接口
│   │   ├── index.ts            # Structure2D 主入口
│   │   ├── types.ts            # API 类型定义
│   │   ├── draw.ts             # 绘图模块
│   │   ├── electrode.ts        # 电极模块
│   │   ├── doping.ts           # 掺杂模块
│   │   └── mesh.ts             # 网格模块
│   ├── backend/                # 后端实现
│   │   ├── bk_1/               # SILVACO 后端
│   │   ├── bk_2/               # Sentaurus 后端
│   │   └── preview/            # SVG 预览后端
│   ├── core/                   # 核心处理逻辑
│   │   ├── context.ts          # 结构上下文与区域处理
│   │   ├── dataprovider.ts     # 数据提供者接口
│   │   └── types.ts            # 核心类型定义
│   └── utils/                  # 工具函数
│       └── isfloatequal.ts
├── package.json
└── tsconfig.json

依赖

许可证

本项目采用 Apache License 2.0 开源协议。