From b4a2caa31e0cdf942059c1f29b06dc4c29a6ae27 Mon Sep 17 00:00:00 2001 From: Jukka Aho Date: Sat, 9 May 2026 16:04:40 +0300 Subject: [PATCH] docs(snippet): Add minimal elasticity quickstart source MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Runnable 4×4×4 Hex8 linear elasticity assembly used as the Documenter/README minimal example source of truth; returns (; ndofs, nnz_stiffness). - Intended for @literalinclude, test/docs, and scripts/verify_docs_quickstart.jl --- .../snippets/minimal_elasticity_quickstart.jl | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 docs/src/snippets/minimal_elasticity_quickstart.jl diff --git a/docs/src/snippets/minimal_elasticity_quickstart.jl b/docs/src/snippets/minimal_elasticity_quickstart.jl new file mode 100644 index 0000000..30892fc --- /dev/null +++ b/docs/src/snippets/minimal_elasticity_quickstart.jl @@ -0,0 +1,34 @@ +# Source of truth for the package Documenter home page "minimal elasticity" demo. +# The README.md block under "A modern minimal example" must match this assembly +# pipeline; `test/docs/runtests.jl` runs both this file and the README fence. +# Executed by `scripts/verify_docs_quickstart.jl`, `test/docs/runtests.jl`, and +# (via Documenter) shown on `docs/src/index.md` with `@literalinclude`. +using JuliaFEM +using SparseArrays + +function minimal_elasticity_quickstart() + mesh = create_structured_box_mesh(Hex8; + xmin = 0.0, xmax = 1.0, nx = 4, + ymin = 0.0, ymax = 1.0, ny = 4, + zmin = 0.0, zmax = 1.0, nz = 4, + ) + S = @DOFSet{u::DOF{Displacement{3}, Vertex}} + ET = Element{Hex8, Lagrange{1}, S} + elements, handler = create_elements!(mesh, ET) + + material = LinearElastic(E = 210e9, ν = 0.3) + kernel = ContinuumKernel(ContinuumFormulation{FullThreeD}(), + material, Displacement{3}()) + + asm = DOFBasedCOOAssembler() + cache = create_cache(asm, elements, handler, mesh, kernel) + assemble!(cache, asm, kernel, mesh) + K, f = extract_system(cache) + + nd = size(K, 1) + @assert nd > 0 + @assert size(K, 2) == nd + @assert nnz(K) > 0 + @assert length(f) == nd + return (; ndofs = nd, nnz_stiffness = nnz(K)) +end