From 6ee2a3b3ffa5fea01d81408ef17c664f08ce5e05 Mon Sep 17 00:00:00 2001 From: Jukka Aho Date: Tue, 18 Nov 2025 15:09:27 +0200 Subject: [PATCH] feat(basis): Add `ndofs` interface to query DOF counts for basis types - Add `ndofs(::AbstractBasis)` / `ndofs(::Type{<:AbstractBasis})` with docstring and examples - Default implementation: `ndofs == nnodes` for standard Lagrange bases - Export `ndofs` alongside `Lagrange` and `nnodes` This provides a stable API for callers to preallocate element-local buffers and supports plate elements that have multiple DOFs per node. --- src/basis/abstract.jl | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/basis/abstract.jl b/src/basis/abstract.jl index a0545de..42208e1 100644 --- a/src/basis/abstract.jl +++ b/src/basis/abstract.jl @@ -298,5 +298,33 @@ nnodes(::Type{Pyr5}) = 5 nnodes(::Type{Wedge6}) = 6 nnodes(::Type{Wedge15}) = 15 -# Export the new parametric type and node count function -export Lagrange, nnodes +# ============================================================================ +# Additional Interface Methods +# ============================================================================ + +""" + ndofs(basis::AbstractBasis) -> Int + ndofs(::Type{<:AbstractBasis}) -> Int + +Number of degrees of freedom for this basis. + +For standard nodal elements (Lagrange), ndofs == nnodes. +For plate elements and others with multiple DOFs per node, ndofs > nnodes. + +# Example + +```julia +ndofs(Lagrange{Triangle, 1}()) # → 3 (same as nnodes) +ndofs(DKT()) # → 9 (3 nodes × 3 DOFs/node) +``` + +See also: [`nnodes`](@ref), [`AbstractPlateBasis`](@ref) +""" +function ndofs end + +# Default: For standard elements, ndofs == nnodes +ndofs(B::AbstractBasis) = nnodes(B) +ndofs(B::Type{<:AbstractBasis}) = nnodes(B) + +# Export the new parametric type and interface functions +export Lagrange, nnodes, ndofs