Skip to content

API Reference

The solver is a headless function compiled to WebAssembly: JSON model in, JSON results out. It runs entirely client-side (no server), which makes it usable as an embeddable solver, in headless/CI scripts, or programmatically by agents.

Loading the module

The WASM bundle is built to web_demo/fem_wasm.js (+ fem_wasm_bg.wasm) and is an ES module:

js
import init, {
  solve_model,
  solve_model_pdelta,
  solve_model_buckling,
  solve_model_modal,
} from './fem_wasm.js'

await init()                       // load the wasm binary once
const out = JSON.parse(solve_model(JSON.stringify(model)))

Entry points

FunctionSignatureReturns
solve_model(json) -> jsonLinear static
solve_model_pdelta(json, maxIters, tol) -> jsonSecond-order (P-Delta)
solve_model_buckling(json, loadCaseId, nModes) -> jsonBuckling load factors + modes
solve_model_modal(json, nModes) -> jsonNatural frequencies + mode shapes

All take the same model JSON; the input string and output string are both JSON. On error the result is { "error": "..." }.

Units & conventions

  • SI throughout: N, m, Pa, rad. (The Studio UI converts to kN / mm for display - the API is raw SI.)
  • Y is vertical (up positive); right-handed axes.
  • Tension is positive for axial forces.
  • Backward-compatible result fields use serde(default), so older consumers that ignore new fields keep working.

Minimal example

A 5 m cantilever with a 12 kN downward tip load:

js
const model = {
  nodes: [
    { id: 1, x: 0, y: 0, z: 0, restraint_flags: 63 },   // fixed
    { id: 2, x: 5, y: 0, z: 0, restraint_flags: 28 },   // free (out-of-plane locked)
  ],
  members: [{ id: 1, node_a: 1, node_b: 2, material_id: 1, section_id: 1, member_type: 0, beta: 0 }],
  materials: [{ id: 1, e: 200e9, g: 80e9 }],
  sections: [{ id: 1, a: 0.01, iyy: 1e-4, izz: 1e-4, j: 2e-4 }],
  load_cases: [{ id: 1, name: 'LC1' }],
  nodal_loads: [{ node_id: 2, load_case_id: 1, fx: 0, fy: -12000, fz: 0 }],
  member_loads: [],
}
const r = JSON.parse(solve_model(JSON.stringify(model)))
r.load_cases[0].displacements   // tip uy = -PL^3/3EI

See Model JSON schema and Results JSON schema.

Public API

This is the surface that could be published as a supported public API / npm package. It is documented here for internal use today; public stability / versioning is a separate decision.