@ferscloud/fers-calculation-web

中文文档
0.2.83发布于 2026/11/03SEE LICENSE IN LICENSETypeScriptES Module零依赖近 30 天下载 2539

从Rust到Web Assembly编译的FEM解析器,用于光束,帧和出轨. 在浏览器或节点中运行,没有服务器回路. 包括Eurocode EN 1993-1-1钢检查.

中文使用文档
文档目录17 节
  1. 安装
  2. Bundler 设置( 浏览器构建)
  3. 快速启动——免费等级(非商业性,最多100个成员)
  4. 响应形状
  5. 认证级别——专业(最多10 000名成员)
  6. 如何运作
  7. 1. 获取 API 密钥
  8. 2. 后端: 获取解析符
  9. 3. 前端: 给求解者打电话
  10. 等级比较
  11. 几个核心: 部分解决
  12. 安全说明
  13. 类型脚本
  14. 外形( 可选)
  15. 归属
  16. 许可证
  17. 链接

@ ferscloud/ fers- 计算

FERS的引擎:结构有限元素分析(3D帧,短跑,板块,Eurocode 3 checks),面向工程师和AI代理,由Rust到WebAssembly编译. 它完全运行在浏览器或Node.js中——每个计算时不进行服务器回路.

这个 README 覆盖两个已发布的软件包 : @ferscloud/fers-calculation (节点.js/服务器侧, --target nodejs和 @ferscloud/fers-calculation-web (浏览器/捆绑器, --target bundler) (中文(简体) ). API是相同的;只有安装和捆绑设置不同.

安装

# Browser apps (Vite, Next.js, webpack):
npm install @ferscloud/fers-calculation-web
# Node.js / server-side:
npm install @ferscloud/fers-calculation

Bundler 设置( 浏览器构建)

@ferscloud/fers-calculation-web 是一个通过顶层设置的 WASM ES 模块 await。大多数捆绑者需要一次性配置:

维特

npm i -D vite-plugin-wasm
// vite.config.ts
import wasm from "vite-plugin-wasm";

// The package initialises with a top-level await, so the build target has to
// be one that supports it. `esnext` needs no second plugin.
export default {
  plugins: [wasm()],
  build: { target: "esnext" },
};

esnext 在输出中保持顶层等待, 需要 Chrome、 Edge 或 Firefox 89+,或称Safari 15+. 如果你还有 vite-plugin-top-level-await 内 您的配置来自此 README 的早期版本, 请放弃它 —— 最近 @swc/core 释放使其失败 vite build。 。 。 .

Next.js / 网页包

// next.config.js
module.exports = {
  transpilePackages: ["@ferscloud/fers-calculation-web"],
  webpack(config) {
    config.experiments = { ...config.experiments, asyncWebAssembly: true };
    config.output.environment = { ...config.output.environment, asyncFunction: true };
    return config;
  },
};

解析器是同步和CPU绑定的;对于大型模型在Web Worker内部运行,因此UI线程保持响应. 节点.js软件包(@ferscloud/fers-calculation)不需要捆绑配置.

快速启动——免费等级(非商业性,最多100个成员)

import { calculate_from_json } from "@ferscloud/fers-calculation";

// No init() call needed — the nodejs and bundler builds initialise the
// WASM module automatically on import.
const res = JSON.parse(calculate_from_json(JSON.stringify(myModel)));
if (res.ok) {
  const data = res.result; // displacements, member_results, unity_checks, …
} else {
  console.error(res.error.code, res.error.message);
}

不需要 API 密钥 。 为任何拥有最多100名成员的模型工作.

响应形状

每个解答者呼叫返回一个 JSON 信封这么说你 JSON.parse 一次和两次 ok ——你从不用嗅出返回的字符串是否"看起来像"出错:

// success
{ "ok": true,  "result": { /* the full result document */ } }
// failure (invalid model, over the member limit, malformed JSON, …)
{ "ok": false, "error": { "code": "LimitExceeded",
                          "message": "Number of members (250) exceeds allowed maximum of 100" } }

error.code 这是其中之一 InvalidJson, (中文(简体) ), LimitExceeded, (中文(简体) ), SolveError, (中文(简体) ), InternalPanic, (中文(简体) ), InternalSerialization返回值为 永远 无效的 JSON.

认证级别——专业(最多10 000名成员)

Pro限制通过通过由FERS Cloud服务器所发出的一个短寿命的签名符来解锁. 信使在WASM内部通过使用被烤入二进制的Ed25519公钥进行验证——它不能被伪造.

如何运作

Your server  →  POST https://ferscloud.com/api/solver/token  →  signed 30-min token
                (X-API-Key: <your-api-key>)

Browser  →  calculate_from_json_with_token(model, token)  →  Pro limits unlocked

1. 获取 API 密钥

登录时间 ferscloud.com (中文(简体) ),转到 配置 ~ API 密钥键。 将其作为环境变量存储在您的服务器上——从不在浏览器代码中.

2. 后端: 获取解析符

您的服务器获取并缓存了该符号 。 Next.js API 路由示例 :

// pages/api/solve-token.ts
const FERS_API_KEY = process.env.FERS_API_KEY!;

let cached: { token: string; expiresAt: number } | null = null;

export default async function handler(req, res) {
  const now = Date.now();

  // Re-use if more than 5 minutes remain
  if (cached && cached.expiresAt - now > 5 * 60 * 1000) {
    return res.json({ token: cached.token });
  }

  const resp = await fetch("https://ferscloud.com/api/solver/token", {
    method: "POST",
    headers: { "X-API-Key": FERS_API_KEY },
  });

  if (!resp.ok) return res.status(502).json({ error: "Token fetch failed" });

  const { token, expiresAt } = await resp.json();
  cached = { token, expiresAt: new Date(expiresAt).getTime() };
  return res.json({ token });
}

同样的模式适用于快递,德诺,邦克,克云弗拉尔工人,或者任何服务器侧运行时间.

3. 前端: 给求解者打电话

import { calculate_from_json_with_token } from "@ferscloud/fers-calculation";

const { token } = await fetch("/api/solve-token").then(r => r.json());

const res = JSON.parse(calculate_from_json_with_token(JSON.stringify(myModel), token));
if (!res.ok) throw new Error(`${res.error.code}: ${res.error.message}`);
const data = res.result;

如果信使缺失,过期或无效,解析器会回落到免费的100名成员限额——它永远不会抛出(一个真正的解析失败会回落为 { ok: false, error },并非例外).

等级比较

特性免费赞成企业
使用非商业性商业和非商业商业和非商业协议
最大成员100个10 000人1 000 000 个
WASM 函数calculate_from_jsoncalculate_from_json_with_tokencalculate_from_json_with_token
需要符号没有对对
托肯 TTL—— 说30分钟30分钟

企业代号是Pro代号,也带有 "plan":"enterprise";0.2.78前的引擎读作Pro. 在浏览器中,内存早在1000 000名成员之前就已耗尽:WASM架构有4GB和一线程.

几个核心: 部分解决

一个WASM案例解决在一个线上。 将模型的负载组合分散到几个工人身上(浏览器中的Web Workers, worker_threads 在节点中,给每个工人一个相同的模型字符串和它自己的部分,并合并他们返回的东西:

// worker.js: one per core
import { calculate_part_from_json } from "@ferscloud/fers-calculation-web";

self.onmessage = ({ data: { model, index, count } }) => {
  self.postMessage(calculate_part_from_json(model, index, count));
};
// main thread
import { merge_parts_from_json } from "@ferscloud/fers-calculation-web";

const model = JSON.stringify(myModel); // one string, the same bytes everywhere
const count = workers.length;
const parts = await Promise.all(
  workers.map((worker, index) => solveIn(worker, { model, index, count })) // resolves with the worker's string
);
const res = JSON.parse(merge_parts_from_json(model, parts)); // what calculate_from_json returns
  • 合并的信封是字节 calculate_from_json 返回同一模式。 如果一个部分失败, 合并返回该部分的错误信封, 一个单一的解析会停止 .
  • 将未打开的部分按索引顺序递出。 合并会自己读取它们; 在 JavaScript 中解析它们只花费时间.
  • 只有组合是分开的。 每个部分都读取整个模型,每当一个解决方案解决时,就会解决负载案例,所以每个组合都从一个解决方案开始;第0部分还报告负载案例,并运行模式,击打和地震分析. 拥有同一名称的组合总是在同一部分.
  • 每个工人都持有自己的模型及其解题副本,因此记忆会随着工人数量的增长而增长.
  • 带有解析符号, 使用 calculate_part_from_json_with_token(model, token, index, count) 在工人和 merge_parts_from_json_with_token(model, token, parts) 合并.

安全说明

留着吧 FERS_API_KEY 只有服务器侧。 它所获取的解析符可以安全地传递到浏览器上——它是短寿命和密码签名. 只有"FERS Cloud"可以发行有效的符;浏览器WASM只能验证.

类型脚本

浏览器包船与函数签名一起生成模型类型 :

import type { FERS, ResultsBundle } from "@ferscloud/fers-calculation-web/fers-models";

FERS 是输入模型; ResultsBundle 这是 result 成功的信封的有效载荷。 两者都是由引擎的OpenAPI schema所生成的,因此它们跟踪已发布的版本.

外形( 可选)

设定 include_member_deflected_shape 在模型的分析选项中获取 准备就绪, 装入精确 每个成员偏转形状——成员的全球 而不是自己重建曲线:

const model = {
  /* … model + load cases … */
  analysis: { /* … */ options: { /* … */ include_member_deflected_shape: true } },
};

const res = JSON.parse(calculate_from_json(JSON.stringify(model)));
const mr = res.result.results.loadcases["…"].member_results["1"];
// mr.member_displacements: [{ x_frac, displacement: [dx, dy, dz] }, …]
//   x_frac 0→1 along the member; displacement in the global input frame.

默认关闭使有效载荷保持倾斜;省去 member_results 当没有要求时.

归属

免费结果包含 attribution 对象在解析器内计温. 高级结果( 用有效的解析符解决) 不, 所以相同的代码 fERS 免费等级和 Pro 白标签:

import { fersAttributionHtml } from "@ferscloud/fers-calculation-web/badge";

// "" when the result came back from a Pro solve.
const credit = fersAttributionHtml(res);

getFersAttribution, (中文(简体) ), fersAttributionText 财务报告和审定财务报表 createFersBadge 也为 导出。 他们都接受信封 解析模型或结果 捆绑, 全部不返回 Pro 结果或错误信封 .

0.2.61年,这一次路径只在捆绑器下解决;纯节点无害环境管理需要 /badge.js. 从0.2.62起,货包装有 exports 映射和两种窗体的工作 到处都是.

在非商业应用程序中使用自由级? 请显示 信贷.

许可证

从0.2.70开始,该引擎根据PolyForm严格许可证 1.0.0获得许可 (见 LICENSE) (中文(简体) ). 任何非商业性目的:学习、教学、, 研究、兴趣爱好项目以及学校、慈善机构和公共机构的使用. 100多名会员的模型需要Pro解码符.

商业用途,无论型号大小,都需要付费 FERS云计划,包括商业 许可证。 许可证不允许修改或再分配包裹.

版本与发布记录

@ferscloud/fers-calculation-web 共发布 97 个版本,首次发布于 2026/03/12;过去 12 个月发布了 97 个版本。

版本发布日期距今
0.2.83latest2026/11/0311 天前
0.2.822026/11/0311 天前
0.2.812026/11/0311 天前
0.2.802026/11/0212 天前
0.2.792026/11/0113 天前
0.2.782026/11/0113 天前

关于 @ferscloud/fers-calculation-web 的常见问题

@ferscloud/fers-calculation-web 是什么?

从Rust到Web Assembly编译的FEM解析器,用于光束,帧和出轨. 在浏览器或节点中运行,没有服务器回路. 包括Eurocode EN 1993-1-1钢检查.

如何安装 @ferscloud/fers-calculation-web?

在项目目录运行 npm install @ferscloud/fers-calculation-web,或使用 pnpm add / yarn add / bun add。

@ferscloud/fers-calculation-web 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ferscloud/fers-calculation-web 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@ferscloud/fers-calculation-web 可以商用吗?

@ferscloud/fers-calculation-web 使用 SEE LICENSE IN LICENSE 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@ferscloud/fers-calculation-web 的下载量有多少?

根据 npm 官方下载统计,@ferscloud/fers-calculation-web 在 2026/10/15 – 2026/11/13 这 30 天内被下载 2,539 次,日均约 85 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ferscloud/fers-calculation-web 还在维护吗?

最新版本 0.2.83 发布于 2026/11/03(11 天前);至今共发布 97 个版本,其中过去 12 个月发布了 97 个;首次发布于 2026/03/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。