The Chartership Forum

The Finite Element Method: First Principles / Implementing a small FEM solver

Recover results and verify the solver

Run independent benchmarks and intentional failure cases. Document what the implementation verifies and what it does not model.

Lesson review: expert verification remains open

This lesson has received a full-context editorial review and a check of its technical explanations. Selected arithmetic has been checked separately. This is not independent engineering sign-off.

Checks needed for project use

  • Independent software/FEM reviewer: solver failure policy, conditioning limits, benchmark independence and instructional completeness; the axial routine is not design software.
  • Actual browser zoom at 125%, 150% and 200% remains unqualified.

These are educational models and exercises. Check their assumptions before using the results. The full technical content and every diagram have not yet been independently verified.

Concrete and steel calculations retain their stated first-generation Eurocode teaching basis. Use the standards and amendments specified for your project; do not mix generations without an appropriate design basis.

Read the lesson register and outstanding review notes

What you should already know

Recover quantities with separate checks

Insert the free solution into d and evaluate the residual in every original row. Restrained rows are reactions; free rows should be small compared with the relevant force scale. Sum reactions and external loads to check equilibrium. Calculate strain energy directly as ΣEA(db−da)²/(2L) and compare with ½dᵀKd. When prescribed movement is non-zero, ½dᵀf alone omits boundary work; use ½dᵀ(f+r).

Stress is constant in each linear element. The continuous stress for a distributed line load is generally not constant, so show the difference rather than presenting element values as exact everywhere. An acceptable residual and energy identity can both hold for an incorrectly connected model. Independent physical references remain essential.

Worked example

A stepped-bar acceptance benchmark

Given

  • Two 1 m elements; E=200 GPa
  • Areas 200 and 400 mm²; q=0
  • Left node fixed; right force 20 kN

Find

Displacements, stresses, reaction and energy before running the program.

    Axial displacement along the bar
    Solid blue: FEM interpolationDashed orange: continuous solution

    Vertical range: ±0.75 mm. Positive displacement is towards the right.

    0 mPosition x2 m
    Right-end displacement
    0.75 mm
    Left reaction
    -40 kN
    Strain energy
    11.56 J
    Free-node residual
    0 N

    Reactions act on the bar. Positive force points right. The end load at a prescribed right node changes that support reaction, not the prescribed displacement. Stress is the constant strain-recovery value in each linear element.

    Displacements, reactions and element stresses
    Nodal results in SI-derived display units
    Nodex (m)u (mm)Reaction (kN)
    100-40
    210.4375Free node
    320.75Free node
    Constant element stress
    ElementStress (MPa)
    187.5
    262.5
    Element and global stiffness, loads and constraints

    Each element has k = EA / h = 8.000e+7 N/m, with the 2 × 2 pattern [1, −1; −1, 1]. The assembled matrix below includes restrained nodes. The reduced solve uses only free nodes and transfers prescribed-displacement terms to its right-hand side.

    Global stiffness K (N/m) and consistent load f (N)
    RowK·1K·2K·3f
    18.00e+7-8.00e+705,000
    2-8.00e+71.60e+8-8.00e+710,000
    30-8.00e+78.00e+725,000

    Small axial strain, linear elasticity, constant area and modulus, uniform axial line load. No bending, buckling, thermal strain or material nonlinearity. The plotted curve is displacement against position, not the deformed physical outline.

    Run the downloadable benchmark script

    Save fem-bar1d.ts and fem-benchmarks.ts in the same folder. In a TypeScript-capable Node environment, run node fem-benchmarks.ts. The script imports the solver and checks analytical references for a stepped bar, a distributed-load mesh, imposed movement, free rigid-body behaviour and invalid geometry. It throws if a result is outside its stated tolerance. It requires no package downloads.

    The browser laboratory exercises the same solver but does not replace the benchmark script. Keep input data, units, expected values, tolerances and software revision together. A regression test should fail when a known defect is reintroduced. A test that copies the implementation formula without an independent reference is weaker evidence.

    A practical verification sequence

    Begin with zero loading and a restrained model, then test a pure constant-strain field. Add an end force and compare series compliance. Add uniform line load and compare integrated continuous displacement and reactions. Impose both end movements and check boundary work. Permute node indices to expose indexing assumptions. Finally remove supports, reverse a member and insert a non-finite property to confirm that invalid models fail visibly.

    For the distributed benchmark L=2 m, EA=80 MN, P=20 kN, q=10 kN/m and two equal elements, expect d=[0,0.4375,0.75] mm, reaction −40 kN and stored energy 11.5625 J. Under two prescribed ends with Δ=1 mm, q=10 kN/m and an external 20 kN at the right, reactions are −50 and 10 kN. The nodal force at the prescribed right coordinate affects the reaction even though its displacement is fixed.

    What completing First Principles establishes

    You have derived displacement interpolation, virtual work, element stiffness, assembly, constraints and error checks, then followed a working axial implementation. These foundations support the next course on linear structural element families. They do not establish competence to approve a design, validate a commercial model or choose constitutive laws for a real structure.

    Independent specialist review is still required for the course derivations and teaching sequence. Higher-dimensional meshes, curved geometry, severe conditioning, locking control, nonlinear formulations and design-code compliance remain outside the qualified scope of this small solver. Return to the course map to revisit a formulation or benchmark.

    Sources and review limits

    The solver and benchmark cases are original. Bathe (1996), §3.3.4 and §3.4.1, inspected in the earlier waves, provide weak-form and constraint context. The separate analytical references are recorded alongside executable tests; no numerical test is described as an independent professional sign-off. These examples and implementations are original teaching material. Independent FEM specialist review remains open; the numerical checks establish only the stated benchmark results.