Getting started

@edubeam/fem is the finite element solver behind EduBeam: every diagram, reaction and deflection the app shows comes from it. Use it to solve plane beams, frames and trusses from your own code, in the browser or in Node: generate exercises with their answers, check homework, run parametric studies, or put a solver behind a web page.

It is written in TypeScript, ships its own types, and is free software under the GPL-3.0. It was created by Bořek Patzák and is developed with Jan Voříšek and contributors.

Install

Terminal
npm install @edubeam/fem

It works with import and require, in the browser and in Node 18 or later, and brings one dependency, mathjs. Until version 0.3.0 it was installed from GitHub as ts-fem: if you used that, change your imports to @edubeam/fem. Nothing else changed.

To try the example below from an empty folder, make it a project that uses import, then install:

Terminal
npm init -y
npm pkg set type=module
npm install @edubeam/fem

Without "type": "module" in package.json the example still runs, but Node prints a warning first.

Your first beam

A 6 m steel beam, an IPE 200, on a pin and a roller under 12 kN/m:

beam.ts
import { DofID, LinearStaticSolver } from '@edubeam/fem'

const solver = new LinearStaticSolver()
const { domain } = solver

// SI units throughout: m, N, Pa. Steel and an IPE 200.
domain.createMaterial('steel', { e: 210e9, g: 81e9 })
domain.createCrossSection('IPE200', { a: 28.5e-4, iy: 1943e-8, k: 5 / 6 })

// Nodes at [x, y, z] in metres, with the DOFs their support holds
domain.createNode('A', [0, 0, 0], [DofID.Dx, DofID.Dz]) // pin
domain.createNode('B', [6, 0, 0], [DofID.Dz]) // roller
const beam = domain.createBeam2D(1, ['A', 'B'], 'steel', 'IPE200')

// 12 kN/m along the member's local z: down on a beam drawn left to right
const lc = solver.loadCases[0]
lc.createBeamElementUniformEdgeLoad(1, [0, 12e3], true)

solver.solve()

console.log(beam.computeBendingMomentAt(lc, 3)) // N·m at midspan
console.log(beam.computeShearForceAt(lc, 0)) // N at A
console.log(beam.computeLocalDefl(lc, 2).w[1]) // m at midspan

Save it as beam.ts and run node beam.ts: Node 22.18 and later run TypeScript as it is. The file has no type annotations, so on an older Node save it as beam.mjs instead. It prints:

Output
54000
36000
0.04990940552616746

Those are the textbook values, kNm and kN. Here is the same beam, solved in your browser by the same solver:

The beam above: 6 m, IPE 200, 12 kN/m54q = 12 kN/m3636AB
The beam above: 6 m, IPE 200, 12 kN/mOpen in EduBeam

The deflection, 49.91 mm, is 0.28 mm more than Euler–Bernoulli's mm. That is no error: the member is a Timoshenko beam, and 0.28 mm is , the shear deformation of this beam. Make k huge, such as 1e32, and it disappears: see Shear deformation.

What the code does

Make a solver

new LinearStaticSolver() comes with an empty domain, which holds the model, and one load case, solver.loadCases[0].

Describe the model

Materials and cross sections, nodes with their supports, then members between the nodes. Everything has a label, a string or a number, by which the rest of the model refers to it. See Nodes and supports, Materials and sections and Members and hinges.

Load it

Loads belong to a load case: forces at nodes, loads along members, temperature and settlements. See Loads.

Solve

solver.solve() assembles and solves every load case. See Solving.

Read the results

Internal forces anywhere along a member, deflections, end forces, nodal displacements and reactions. See Reading results, and Drawing the results for diagrams.

Units and signs in brief

SI units in, SI units out. The model lies in the x–z plane with z pointing down, so a positive fz pushes down and the top of a 4 m column is at . Positions along a member are metres from its first node. A sagging moment is positive. Units and signs has the full list.

Six things that trip people up

  1. z points down. Gravity loads are positive, and anything above the supports has a negative z. See Axes.
  2. A member's direction sets the sign of M and w. Define beams left to right and columns bottom to top, and the signs read as in a textbook. See Member direction.
  3. A missing parameter gives NaN or nonsense, not an error. A section needs a, iy and k; a material needs e, and g unless k is huge. See Materials and sections.
  4. After adding nodes or members, or changing supports, set solver.codeNumberGenerated = false before solving again. See Solving again after a change.
  5. Reactions come back as a mathjs matrix or as an array, in the order the support's DOFs were given. See Reactions.
  6. A mechanism does not always throw. A displacement of m means the structure can move freely. See When solving fails.

Where to next