The Finite Element Method: First Principles / Implementing a small FEM solver
Validate inputs and assemble the system
Follow a complete axial solver from physical inputs to a reproducible verification record.
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 notesBy the end of this lesson you should be able to
- Trace validation, assembly, constraints, solution and recovery in an executable solver
- Run independent benchmarks and intentional failure cases
- Document what the implementation verifies and what it does not model
What you should already know
- Modules 1–13, especially assembly, constraints and convergence
- Basic TypeScript or equivalent programming experience
Define a small, inspectable problem
The axial solver implements straight two-node members with one displacement coordinate per node, constant E and A within each member, constant member line loads and prescribed nodal displacements. All input is in SI units. It can represent a non-uniform chain or a collinear branched network with explicit connectivity. It has no bending, geometric nonlinearity, plasticity, contact or thermal strain.
The model contains a list of physical coordinates x, element records {a,b,E,A,q}, a global nodal load vector and a dictionary of prescribed displacements. Each element must point from smaller to larger physical x; node numbers themselves may be permuted. A shared coordinate does not connect two members unless the connectivity uses the same node. This convention makes the meaning of every array entry inspectable.
Validate before assembly
Reject non-finite inputs, mismatched vector sizes, invalid node indices, zero or negative physical member lengths, non-positive E or A, and invalid prescribed-node keys. The dense teaching implementation allows 2–129 nodes. That bound keeps the demonstrator manageable; it is not a statement about what FEM can solve.
A valid input shape can still describe an unsupported mechanism or a disconnected component. Restraints are part of the mathematical model. The solver detects singular or very poorly scaled pivots during elimination and reports a failure instead of adding an arbitrary spring. An excessively large stiffness contrast can also trigger this guard, so the message is a diagnostic prompt rather than a unique diagnosis of missing restraints.
Assemble one contribution at a time
For each element, compute L=x[b]−x[a], k=EA/L and the two-by-two matrix k[1,−1;−1,1]. Add these four terms at the global indices a and b. Add qL/2 to each corresponding load entry, then include global nodal forces once. Preserve this full K and f. The reduced matrix alone cannot recover restrained-node reactions.
Next, collect free indices. Copy prescribed values into the full displacement vector. Form Kff and ff−Kfc dc, then solve for free values. The implementation uses dense Gaussian elimination with partial pivoting; it does not form an explicit inverse. Each pivot is compared with 10⁻¹³ times the largest original matrix magnitude. That fixed guard is deliberately conservative and is not a condition-number estimator.
What it calculates: Constrained solve, original-equation residual and element stress recovery.
Continue with recover results and verify the solver.
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.