# @ferscloud/fers-calculation 中文文档

规范地址：https://npmcn.com/package/%40ferscloud/fers-calculation/

版本：0\.2\.83
npm 元数据更新时间：2026-11-03T12:20:16.028Z
中文译文更新时间：2026-11-14T14:59:11.311Z
软件包许可：SEE LICENSE IN LICENSE

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40ferscloud/fers-calculation
原文对照：https://npmcn.com/package/%40ferscloud/fers-calculation/?lang=original
项目主页：https://ferscloud.com/structural-analysis-javascript
源码仓库：https://github.com/Jeroen124/FERS_calculations

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：3.3 MB，6 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2026-01-15T11:47:36.388Z
- 最新版本发布：2026-11-03T12:20:15.638Z
- 近 30 天下载量：2669（2026-10-15 至 2026-11-13，npm 官方下载统计）
- 已发布版本数：105（近 12 个月 105 个）

## 中文简介

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

## 安装

```sh
npm install @ferscloud/fers-calculation
```

也可以使用：`pnpm add @ferscloud/fers-calculation`、`yarn add @ferscloud/fers-calculation`、`bun add @ferscloud/fers-calculation`

## README

# @ 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是相同的;只有安装和捆绑设置不同.

## 安装

```bash
# 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`。大多数捆绑者需要一次性配置:

**维特**

```bash
npm i -D vite-plugin-wasm
```

```ts
// 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 / 网页包**

```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个成员)

```ts
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` ——你从不用嗅出返回的字符串是否"看起来像"出错:

```jsonc
// 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 (中文(简体) )](https://ferscloud.com/),转到 **配置 ~ API 密钥**键。 将其作为环境变量存储在您的服务器上——从不在浏览器代码中.

### 2\. 后端: 获取解析符

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

```ts
// 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\. 前端: 给求解者打电话

```ts
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_json` | `calculate_from_json_with_token` | `calculate_from_json_with_token` |
| 需要符号 | 没有 | 对 | 对 |
| 托肯 TTL | —— 说 | 30分钟 | 30分钟 |

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

## 几个核心: 部分解决

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

```js
// 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));
};
```

```js
// 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只能验证.

## 类型脚本

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

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

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

## 外形( 可选)

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

```ts
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 白标签:

```ts
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云计划](https://ferscloud.com/pricing),包括商业 许可证。 许可证不允许修改或再分配包裹.

## 链接

-   [JavaScript 的结构分析](https://ferscloud.com/structural-analysis-javascript) ——为什么运行解析器客户端
-   [Java脚本文档](https://ferscloud.com/docs/javascript) ——捆绑器设置,出错代码,类型,解析符
-   [完整文档](https://ferscloud.com/getting-started) 所有进入FERS的路线
-   [llms- full.txt (英语)](https://ferscloud.com/llms-full.txt) - 一份完整的文件 给特工们
-   [风云](https://ferscloud.com/)
-   [FERS Python 软件包](https://pypi.org/project/fers/) —— 说 `pip install FERS`

## 常见问题

### @ferscloud/fers-calculation 是什么？

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

### 如何安装 @ferscloud/fers-calculation？

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

### @ferscloud/fers-calculation 支持 TypeScript 吗？

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

### @ferscloud/fers-calculation 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @ferscloud/fers-calculation 可以商用吗？

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

### @ferscloud/fers-calculation 的下载量有多少？

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

### @ferscloud/fers-calculation 还在维护吗？

最新版本 0\.2\.83 发布于 2026/11/03（11 天前）；至今共发布 105 个版本，其中过去 12 个月发布了 105 个；首次发布于 2026/01/15。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

