Commit Graph

1186 Commits

Author SHA1 Message Date
Jukka Aho 1f07f3f7aa test: Add comprehensive deformation gradient computation validation
- Tests compute_deformation_gradient() for both FiniteStrain and SmallStrain formulations
- Identity case: u=0 → F=I, det(F)=1
- Pure translation: constant u → ∇u=0 → F=I (rigid body motion)
- Pure stretch: uniaxial extension (10%, 20%) → diagonal F
- Simple shear: u_x = γ·y → off-diagonal F components
- Validates F = I + ∇u (finite strain) vs F = I (small strain approximation)
- Physical constraint: det(F) > 0 (orientation preservation)
- Incompressibility check: det(F) ≈ 1 for volume-preserving deformation
- Symmetry verification for Right Cauchy-Green tensor C = F^T·F
- Type stability and zero allocation checks
- Integration with new API: get_basis_derivatives(Hexahedron(), Lagrange{}, ξ)
- Tests Hex8 elements with various deformation patterns
- 393 lines validating fundamental kinematics with Tensors.jl
2025-11-12 00:07:40 +02:00
Jukka Aho 7b875dd117 test: Add nodal assembly data structures validation
- Tests NodeToElementsMap inverse connectivity (node → elements touching it)
- Validates "spider" pattern: set of nodes coupled to given node via shared elements
- Simple Tet4 mesh: 2 elements sharing face, tests node-element relationships
- Spider coupling patterns: corner nodes (1 element), shared nodes (2 elements)
- NodalStiffnessContribution storage: K_blocks (3×3 tensors), f_int, f_ext (Vec{3})
- Matrix-vector product: w_i = ∑_j K_ij ⊡ u_j (nodal assembly operation)
- Spider efficiency check: 2×2×2 hex mesh shows sparse coupling
  - Corner node: 8 couplings
  - Center node: 27 couplings (max for structured mesh)
  - Key insight: only compute non-zero blocks (not full 81×81 matrix)
- Diagnostic output showing spider structure and coupling patterns
- 208 lines validating nodal assembly infrastructure with Tensors.jl
2025-11-12 00:07:01 +02:00
Jukka Aho 5ec6dda0dd test: Add new API element construction validation
- Tests Element construction with explicit Topology + Basis separation
- Validates 2D elements: Triangle (P1=3 nodes, P2=6 nodes), Quadrilateral (Q1=4, Q2=9)
- Validates 3D elements: Tetrahedron (P1=4, P2=10), Hexahedron (Q1=8, Q2=27)
- Backward compatibility: Tet4, Tri3, Quad4, Hex8 aliases verified
- Topology properties independent of basis: dim(), reference_coordinates(), edges(), faces()
- Type-stable fields using NamedTuple (E, ν, thickness)
- Integration points as element property with integration_points(scheme, topology)
- Demonstrates separation of concerns: Geometry ≠ Interpolation ≠ Integration ≠ Fields
- Compile-time known sizes: NTuple connectivity, type parameters encode dimensions
- Zero allocation verification for field access and element queries
- 344 lines validating new immutable Element architecture with clear responsibilities
2025-11-12 00:06:34 +02:00
Jukka Aho 49bb196e68 test: Add new API basis function evaluation validation
- Demonstrates correct new API usage: Topology + Basis + IntegrationPoint separation
- Mock BasisValues struct with shape functions N and derivatives dN_dξ (SVector)
- Tests linear tetrahedron (P1, 4 nodes) evaluation at center and corner nodes
- Tests linear triangle (P1, 3 nodes) evaluation and partition of unity
- Validates constant derivatives for linear elements
- Integration with Gauss quadrature: evaluate_basis at all integration points
- Complete FEM workflow demonstration: Topology → Integration → Basis → Assembly
- Multiple element types from same topology (P1 vs P2 with same integration points)
- Type stability and zero allocation verification with StaticArrays
- 291 lines demonstrating separation of concerns: Topology ≠ Basis ≠ Integration
2025-11-12 00:05:56 +02:00
Jukka Aho 1b8da3465c test: Add comprehensive neo-Hookean hyperelastic material validation
- Tests NeoHookean construction with both Lamé parameters and engineering constants
- Strain energy computation: reference state (ψ=0), uniaxial extension, invalid deformations
- Stress computation: small deformation, large deformation (50% extension), pure shear
- Second Piola-Kirchhoff stress: S = 2·∂ψ/∂C computed via automatic differentiation
- Tangent modulus validation: 4th-order symmetric tensor, finite difference consistency
- Verifies stress-energy relationship: S = 2·gradient(strain_energy, C)
- Small strain limit: Neo-Hookean → linear elasticity as ε → 0
- Incompressibility check for nearly incompressible materials (ν → 0.5)
- Automatic differentiation accuracy verification
- Zero allocation and type stability checks
- 295 lines validating finite deformation hyperelasticity with Tensors.jl
2025-11-12 00:01:18 +02:00
Jukka Aho e9ead51f24 test: Add comprehensive linear elastic material validation
- Tests LinearElastic material construction with parameter validation
- Validates Lamé parameter computation (λ and μ from E and ν)
- Stress computation tests: uniaxial extension, pure shear, hydrostatic pressure, general strain
- Verifies Hooke's law: σ = λ·tr(ε)·I + 2μ·ε
- Tangent modulus validation: 𝔻 = λ·I⊗I + 2μ·𝕀ˢʸᵐ (4th-order tensor)
- Double contraction consistency: σ = 𝔻 ⊡ ε
- Symmetry and isotropy property verification
- Tests both full and simplified compute_stress() interfaces
- Zero allocation and type stability checks
- 279 lines validating fundamental elasticity operations with Tensors.jl
2025-11-12 00:00:59 +02:00
Jukka Aho 1952f9c6cb test: Add comprehensive Jacobian computation validation
- Tests compute_jacobian() for 2D triangles and 3D tetrahedra
- Validates identity, scaling, and rotation transformations
- Tests physical_derivatives() conversion from reference to physical coordinates
- Verifies constant strain condition (∑ dNᵢ/dx = 0)
- Element quality checks via determinant (positive = proper orientation)
- Detects degenerate elements (det ≈ 0)
- Type stability and zero allocation verification
- Manual calculation consistency checks for known Jacobians
- Tests both tuple and vector interfaces
- 261 lines covering fundamental isoparametric mapping operations
2025-11-12 00:00:41 +02:00
Jukka Aho b6b5ea4b1a test: Add zero-allocation integration points API validation
- Tests get_gauss_points!() for 5 topology types (Segment, Triangle, Tetrahedron, Quadrilateral, Hexahedron)
- Validates zero allocation property for all quadrature orders
- Verifies return type: NTuple of (Float64, Vec{D}) pairs
- Tests weight summation equals reference element area/volume
- Demonstrates usage in assembly loop with zero allocations
- Includes performance comparison benchmarking
- 151 lines of comprehensive integration points validation
2025-11-11 23:59:32 +02:00
Jukka Aho d47eed8ed3 test: Add finite strain plasticity material model validation
Unit tests for FiniteStrainPlasticity with multiplicative decomposition.

Test coverage:
- Material construction with validation (E, ν, σ_y, H parameters)
- State initialization (F_p, α_bar, κ)
- Small strain limit verification
- Identity and pure rotation deformation (frame indifference)
- Uniaxial extension (elastic and plastic regimes)
- Simple shear deformation
- Incremental loading with state persistence
- Plastic incompressibility constraint (det(F_p) ≈ 1)
- Kinematic hardening behavior (backstress evolution)
- State persistence across load steps
- Type stability verification
2025-11-11 23:54:22 +02:00
Jukka Aho c9f951ef16 test: Add traditional element assembly structures validation
Tests for element-by-element assembly approach with sparse matrix operations.

Test coverage:
- ElementAssemblyData construction and initialization
- DOF indexing for sequential and non-sequential nodes
- Element contribution structures (K_local, f_int, f_ext)
- Scatter operation to global arrays
- Overlapping element accumulation
- Residual computation (f_ext - f_int)
- Matrix-vector product
- Dirichlet BC application (penalty method)
- Symmetry preservation
- Reset functionality
- Assembly statistics printing
2025-11-11 23:53:02 +02:00
Jukka Aho 0ccc29976c test: Add single-element patch test for elasticity assembly
Validates core assembly implementation by solving single Tet10 element
under uniaxial tension and comparing to analytical solution.

Test coverage:
- Linear elastic material model validation
- Strain computation from gradients (uniaxial extension)
- Assembly helpers zero allocation verification
- Type stability verification
- Stiffness matrix properties (symmetry, positive definiteness)
- Internal forces accumulation

Validates complete assembly infrastructure works correctly.
2025-11-11 23:52:32 +02:00
Jukka Aho 280f42bbf8 test: Add standalone elasticity assembly helpers validation
Tests core assembly helper functions (strain computation, stiffness
accumulation) without requiring full Element/BasisInfo infrastructure.
Uses Tensors.jl types directly for validation.

Test coverage:
- Material model integration (LinearElastic)
- Strain computation from shape function gradients
- Stiffness matrix accumulation
- Zero allocation verification
- Type stability verification
- Stiffness matrix properties (symmetry, eigenvalues)
2025-11-11 23:52:05 +02:00
Jukka Aho 650e442a37 docs(examples): Fix formatting in gmsh_heat_equation QUICK_START
- Add blank line after 'This example shows:' for markdown lint compliance
- Minor formatting fix only, no content changes
2025-11-10 22:26:55 +02:00
Jukka Aho 269fa9a4ad feat(basis): Add dual-API basis function support (modern + legacy)
- New API: get_basis_functions() returns tuple of functions
- New API: get_basis_derivatives() returns tuple of gradient functions
- basis_api.jl: 210 lines implementing modern functional API
- Re-generated lagrange_generated.jl with 242 new lines
- abstract.jl: Add nnodes() method for Lagrange type
- Backward compatible: old eval_basis! API unchanged
- See ADR-003 for design rationale
2025-11-10 22:26:23 +02:00
Jukka Aho 30ca3de56a feat(elements): Add immutable update() function for elements
- Implement update() that returns new element (immutable pattern)
- Supports keyword arguments for ergonomic field updates
- Preserves backward compatibility with update!() (legacy)
- Dual-API approach: modern immutable + legacy mutable both supported
- 82 lines including documentation and examples
- See docs/book/fundamentals_element_creation.md for usage guide
2025-11-10 22:25:59 +02:00
Jukka Aho 7ffecf73e7 refactor(core): Update JuliaFEM.jl exports for new APIs
- Add new basis API exports: get_basis_functions, get_basis_derivatives
- Export both update() (immutable) and update!() (legacy)
- Re-enable assemble! and postprocess! exports
- Document new basis API with ADR-003 reference
- Include basis_api.jl for dual-API support (modern + legacy)
2025-11-10 22:25:41 +02:00
Jukka Aho 5823a8ec97 demo: Add interactive cantilever beam demo
- Complete working demo of GPU elasticity solver
- Includes mesh generation with Gmsh.jl
- Step-by-step workflow from mesh to solution
- Visualization code for results
- Material: Steel (E=200 GPa, ν=0.3)
- Load: 10 MPa pressure on free end
- Output: Displacement field, validation results
- 145 lines with detailed comments
2025-11-10 22:25:15 +02:00
Jukka Aho 2b1fa89684 test(gpu): Add GPU elasticity solver test with cantilever beam
- Complete test suite for ElasticityPhysics solver
- Cantilever beam mesh: 190 nodes, 434 Tet4 elements
- Gmsh-generated mesh file (cantilever_beam.msh)
- Material: Steel (E=200 GPa, ν=0.3)
- Boundary conditions: Fixed end, pressure load on free end
- Validates convergence and displacement field
- Test passes: 430 CG iterations, max displacement 4.1 cm
2025-11-10 22:24:52 +02:00
Jukka Aho c3ba765447 feat(gpu): Add complete GPU-resident elasticity solver
- Implement ElasticityPhysics struct with nodal assembly
- Two-phase assembly: element contributions then nodal accumulation
- Matrix-free CG solver using IterativeSolvers.jl
- Support for pressure boundary conditions
- Complete test: 190 nodes, 434 elements, converges in 430 iterations
- Max displacement 4.1 cm (cantilever beam validation)
- 476 lines including full documentation
2025-11-10 22:24:23 +02:00
Jukka Aho 4e872a1765 deps: Update Manifest.toml for IterativeSolvers
- Lock IterativeSolvers.jl v0.9.4
- Update dependency tree after Project.toml changes
2025-11-10 22:23:49 +02:00
Jukka Aho ddaba3ee29 deps: Add IterativeSolvers.jl dependency
- Add IterativeSolvers v0.9.4 for CG solver
- Required for GPU elasticity solver implementation
- Provides matrix-free iterative solver framework
2025-11-10 22:23:39 +02:00
Jukka Aho 3d5a3d8c1a docs: Remove old blog/ and design/ directories
- Delete docs/blog/ directory (files moved to docs/src/book/blog/)
- Delete docs/design/ directory (files moved to docs/src/book/design/)
- Cleanup after three-tier documentation reorganization
- Old locations no longer needed after migration to docs/src/ structure
2025-11-10 22:22:29 +02:00
Jukka Aho 8c1be1b5a8 docs: Move user manual to docs/src/user/
- Relocate docs/user/ to docs/src/user/
- Contains user-facing documentation:
  - README.md (user manual index)
  - system_architecture.md (system overview)
- Part of three-tier docs reorganization following Documenter.jl standard
- Completes migration to docs/src/ structure
2025-11-10 22:22:00 +02:00
Jukka Aho fb732efd1b docs: Move contributor manual to docs/src/contributor/
- Relocate docs/contributor/ to docs/src/contributor/
- Add three GPU quickstart guides (renamed from UPPERCASE to snake_case):
  - gpu_elasticity_quickstart.md
  - gpu_nodal_assembly_quickstart.md
  - quick_reference_gpu.md
- Part of three-tier docs reorganization following Documenter.jl standard
- All files now under docs/src/ for automatic rendering
2025-11-10 22:21:43 +02:00
Jukka Aho edc4d5f63e docs: Move immutability blog post to docs/src/book/blog/
- Relocate docs/blog/immutability_performance.md to docs/src/book/blog/
- Comprehensive guide on immutable material models with Tensors.jl
- Covers LinearElastic, NeoHookean, PerfectPlasticity implementations
- Includes full benchmarks: 5× speedup for linear, 21× for plasticity
- Zero allocation performance validated
- Part of three-tier docs reorganization under standard docs/src/ structure
2025-11-10 22:21:15 +02:00
Jukka Aho 5bfd30e9a9 docs: Move book README to docs/src/book/ following Documenter.jl standard
- Relocate docs/book/README.md to docs/src/book/README.md
- Follows standard Julia documentation structure where all source files live under docs/src/
- File contains YAML header and book philosophy/structure overview
- Part of three-tier documentation reorganization (user/contributor/book)
2025-11-10 22:20:40 +02:00
GitHub Copilot c3cda77f08 feat(examples): Actually solve K*u=f and show solution
Enhanced academic_example.jl to compute actual solution:
- Construct explicit 5×5 Laplacian system (tridiagonal stiffness matrix)
- Solve K * u = f directly to get solution vector
- Verify solution with residual check (||K*u - f|| < 1e-15)
- Display solution: u = [-2.5, -4.0, -4.5, -4.0, -2.5]

This fully demonstrates Issue #183 requirement (c): extract matrices
and get solution vector for use with external solvers.

Added imports: LinearAlgebra, SparseArrays
Changes: 211 lines → 256 lines (actual working solver)
2025-11-10 00:53:23 +02:00
Jukka Aho 4603b9ff47 feat(examples): Add working academic matrix extraction example (Issue #183)
Created new example demonstrating the three requirements from Issue #183:
- a) Discretize space (mesh generation shown)
- b) Assemble stiffness matrix (API demonstrated)
- c) Extract matrices for external solvers (working code)

New files:
- examples/academic_matrix_extraction/academic_example.jl (211 lines)
- examples/academic_matrix_extraction/README.md (123 lines)

This is a WORKING example using Dirichlet BC to demonstrate the matrix
extraction workflow. Shows integration with DifferentialEquations.jl,
LinearSolve.jl, Krylov.jl, and custom solvers.

Also updated gmsh_heat_equation.jl to be honest about demonstration status:
- Added clear NOTE that Heat problem is pending Phase 2
- Explains workflow structure vs actual functionality
- References architecture refactoring progress
2025-11-10 00:38:26 +02:00
Jukka Aho 621c861cd6 style(examples): Apply Julia formatter to gmsh_heat_equation.jl
Formatting changes only (no functional changes):
- Remove trailing whitespace after closing braces (lines 33, 75, 81)
- Add spaces around operators in Dict type parameters:
  * Dict{Int, Vector{Float64}} → Dict{Int,Vector{Float64}}
  * Dict{String, Vector{Int}} → Dict{String,Vector{Int}}
  * Tuple{Symbol, Vector{Int}} → Tuple{Symbol,Vector{Int}}
- Add spaces around arithmetic operators:
  * (j-1)*(n+1) → (j - 1) * (n + 1)
  * Similar for all node index calculations
- Remove trailing space after comment text (line 172)

Improves code consistency with Julia style guide
2025-11-09 23:31:21 +02:00
Jukka Aho 46b0cd3927 docs(book): Add comprehensive Gmsh to physics tutorial
New file: docs/book/gmsh_tutorial.md (544 lines)

Complete educational resource addressing Issue #183:

Step 1: Mesh Generation with Gmsh
- Why Gmsh (features, academic adoption)
- .geo file syntax and concepts
- Mesh generation commands
- Understanding .msh format

Step 2: Weak Formulation (Theory)
- Strong form → weak form derivation
- Galerkin approximation
- M du/dt + K u = f system

Step 3: FEM Assembly in JuliaFEM
- Loading meshes
- Creating problems and elements
- Boundary conditions (Dirichlet, Neumann)
- Assembly process internals

Step 4: Extracting Matrices (Issue #183 core answer)
- How to get K, M, f after assembly
- Why extract (5 use cases)
- Integration with DifferentialEquations.jl
- Complete working example

Step 5: Method of Lines
- PDE → ODE spatial discretization strategy
- Separation of space/time concerns
- Modularity benefits

Plus: Comparison (built-in vs external), Extensions (nonlinear, 3D,
parallel, GPU), Troubleshooting, References

Demonstrates 'laboratory not fortress' philosophy
2025-11-09 23:24:15 +02:00
Jukka Aho 50851e878b docs(examples): Add quick start guide for gmsh example
New file: examples/gmsh_heat_equation/QUICK_START.md (34 lines)

Minimal quick-reference document:
- Links to main files (example, geometry, tutorial)
- 5-point workflow summary
- Academic usage code snippet (Issue #183)
- Matrix extraction pattern for external solvers

Complements README.md with even shorter entry point
2025-11-09 23:23:38 +02:00
Jukka Aho bf6bfc2c7b docs(examples): Add README for gmsh heat equation example
New file: examples/gmsh_heat_equation/README.md (74 lines)

Quick-start documentation covering:
- Problem statement (heat equation with BCs)
- Quick start commands (mesh generation, run example)
- What you get (assembly workflow, matrix extraction)
- Academic usage section directly addressing Issue #183
- Code snippet showing K, M, f extraction for external solvers
- File listing and links to comprehensive tutorial

Provides immediate context for users discovering this example
2025-11-09 23:23:18 +02:00
Jukka Aho d6babcdaea feat(examples): Add complete heat equation example addressing Issue #183
New file: examples/gmsh_heat_equation/gmsh_heat_equation.jl (225 lines)

Complete workflow demonstration:
- Step 1: Mesh generation (10×10 structured grid, 200 Tri3 elements)
- Step 2: Element creation with thermal conductivity property
- Step 3: FEM assembly (stiffness matrix K)
- Step 4: Matrix extraction for external solvers (DifferentialEquations.jl)
- Step 5: Solver configuration

Problem: ∂u/∂t = α∇²u on unit square
BC: u=0 on left edge, natural BC elsewhere
Shows exactly what Chris Rackauckas requested in Issue #183:
  a) Spatial discretization
  b) Stiffness matrix assembly
  c) Extracting K, M, f for external ODE solvers

Academic usage: demonstrates JuliaFEM as discretization engine
2025-11-09 23:22:57 +02:00
Jukka Aho d7939551fb feat(examples): Add Gmsh geometry file for unit square mesh
New file: examples/gmsh_heat_equation/unit_square.geo (32 lines)

Defines unit square [0,1]×[0,1] with:
- 4 corner points with mesh size lc=0.1
- 4 boundary edges (bottom, right, top, left)
- Plane surface for 2D heat equation
- Physical groups labeled for boundary conditions
- Triangular elements (Tri3, ElementOrder=1)
- Frontal-Delaunay meshing algorithm

Generate mesh with: gmsh -2 unit_square.geo -o unit_square.msh
2025-11-09 23:22:18 +02:00
Jukka Aho 358f7701d4 style(test): Add spacing in division operator for consistency
Changes to test/test_elasticity_1d.jl:
- Changed sqrt(3)/2 to sqrt(3) / 2 (added spaces around /)
- Improves code readability and follows Julia style conventions
- No functional change, formatting only
2025-11-09 21:03:59 +02:00
Jukka Aho a332d79736 fix(elements): Update Poi1 to non-parametric AbstractBasis
Changes to src/elements/elements_lagrange.jl:
- Changed Poi1 from AbstractBasis{0} to AbstractBasis (non-parametric)
- Added nnodes(::Type{Poi1}) = 1 method
- Added nnodes(::Poi1) = 1 instance method
- Added comment explaining Poi1 as 0D point element
- Resolves type parameter mismatch with new AbstractBasis definition
2025-11-09 21:03:39 +02:00
Jukka Aho a6c692d074 refactor(core): Uncomment Dirichlet, aster_read_mesh, and lagrange elements
Changes to src/JuliaFEM.jl:
- Uncommented problems_dirichlet.jl include and Dirichlet export (lines 288-289)
- Uncommented elements_lagrange.jl include (line 261)
- Uncommented aster_read_mesh export (line 340)
- Fixed indentation in jacobian function (spaces → consistent spacing)
- Fixed spacing in J_data array indexing (J_data[i,j] → J_data[i, j])

Purpose: Enable more problem types and mesh readers for testing
2025-11-09 21:03:12 +02:00
Jukka Aho 5f10390a01 docs(design): Add YAML frontmatter to IMMUTABILITY.md
- Converted header metadata to YAML frontmatter format
- Added categories and tags for documentation site compatibility
- Preserved all existing content (only header format changed)
- Status: IMPLEMENTED, Phase: Phase 1B
- Links to benchmark: element_immutability_benchmark.jl
2025-11-09 21:02:49 +02:00
Jukka Aho 7370863806 docs(blog): Add TL;DR version of immutability performance article
New 139-line quick-reference article covering:
- Side-by-side code comparisons (mutable vs immutable)
- 130x speedup summary with key metrics
- Type stability explanation with timing breakdown
- Compiler optimization differences
- Real-world impact table (2.4s → 0.02s)
- Mental model shift (1990s C++ → 2025 modern compilers)
- Quick command to run benchmark
- Links to full article for details
2025-11-09 21:02:21 +02:00
Jukka Aho ad80533334 docs(blog): Add O(n) vs O(1) scaling analysis to immutability article
- Comprehensive section on struct size scaling (1-5000 fields)
- Confirms crossover at 100 fields (800 bytes) for updates
- Shows immutable wins for access/iteration at ALL sizes
- Explains why constants matter more than Big-O
- Typical FEM elements (5-50 fields) well below crossover
- Updated FAQ with scaling questions
- Added references to struct_size_scaling.jl benchmark
- System: Intel Xeon Gold 6326, 32 cores, 503 GB RAM
2025-11-09 21:01:12 +02:00
Jukka Aho 2cbb382ca8 feat(benchmark): Validate O(n) vs O(1) struct scaling hypothesis
- Tests 1 to 5000 fields to find crossover point
- Confirms stack copying is O(n) at 0.16 ns/field
- Confirms Dict mutation is O(1) at 7 ns constant
- Crossover at 100 fields (800 bytes) for updates
- Typical FEM elements (20-60 fields) well below crossover
- Immutable wins for access and iteration at ALL sizes
- Generates 5 publication-quality plots
- Exports JSON + CSV with system specs
- System: Intel Xeon Gold 6326, 32 cores, 503 GB RAM
2025-11-09 21:00:51 +02:00
Jukka Aho aab8b7d6ce feat(test): First test rewritten for immutable elements (test_elasticity_1d)
Rewrote test_elasticity_1d.jl to follow immutable element pattern.
This is the first fully working test with the new architecture!

Changes:
1. test/test_elasticity_1d.jl:
   - Convert Dict node data to element-local tuple format
   - Wrap data in DVTI field objects (Discrete, Variable, Time-Invariant)
   - Create element with fields at construction: Element(Seg2, conn; fields=(...))
   - Fix Jacobian shape expectation (3×1 not 1×3 for 1D in 3D)

2. src/JuliaFEM.jl:
   - Add minimal jacobian() function for AbstractBasis (non-parametric)
   - Handles embedding (1D element in 3D space) correctly
   - Returns Matrix instead of Tensor for flexibility

3. src/elements/elements.jl:
   - Fix Jacobian computation to handle both Tuple and IntegrationPoint
   - Fix detJ calculation logic for embedded elements (check m not size(JT,2))
   - Correctly handle 1D elements: detJ = ||∂X/∂ξ||

Result: test_elasticity_1d.jl passes! ✓

This validates the immutable architecture:
- Element created with fields at construction
- No mutation needed during test
- Field system integration working (DVTI fields)
- Jacobian computation working for embedded elements
2025-11-09 18:42:56 +02:00
Jukka Aho 41e09b2c92 feat(compat): Add compatibility shim for old mutable field API
Implements compatibility layer to allow old test code to run with new
immutable element design (though fields won't actually update).

src/elements/elements.jl:
- Replaced has_dfield/get_dfield to work with new fields API
- Fixed get_sfield/get_dfield to handle empty Tuple{} fields
- All dfield functions now map to element.fields (immutable NamedTuple)

src/topology/*.jl (seg2, tri3, quad4, tet4, hex8):
- Added nnodes() implementation for each topology type
- Returns corner node count (backwards compatibility)
- Example: nnodes(::Triangle) = 3, nnodes(::Hexahedron) = 8
- Note: Actual node count depends on basis degree in new architecture

Test Results:
- test_topology_standalone.jl: 36/36 tests passing ✓
- Full test suite: 43 errors (same as before)
- Error breakdown:
  * 40+ tests: Problem types not defined (Elasticity, Heat, Mortar)
  * 2 tests: Mesh readers not defined (aster_read_mesh)
  * 1 test: Tries to mutate empty element (test_elasticity_1d)

Next Steps:
- Tests that create empty elements then mutate need rewriting
- Pattern: Element(Seg2, (1,2)) + update!() → not compatible
- New pattern: Element(..., fields=(geometry=X, displacement=u))
- See docs/design/IMMUTABILITY.md for migration guide
2025-11-09 18:08:39 +02:00
Jukka Aho 32451ed978 docs(design): Add immutability design doc with comprehensive benchmark
Created comprehensive documentation and benchmark demonstrating why immutable
elements with type-stable fields are 40-130x faster than mutable Dict-based
elements.

benchmarks/element_immutability_benchmark.jl:
- Compares mutable (Dict) vs immutable (NamedTuple) implementations
- Measures field access, updates, assembly loops, large-scale meshes
- Results: 40x faster field access, 130x faster assembly, zero allocations

docs/design/IMMUTABILITY.md:
- Explains counterintuitive API change: element = update(element, ...)
- Benchmarks show 40-130x speedup despite 'copying' elements
- Key insight: Type stability >> mutation, compiler optimizes away copies
- Migration guide: old mutable API → new immutable API
- GPU/HPC rationale: Only bits types work on GPU (no pointers)

Key Results:
- Field access: 1ns vs 45ns (40x faster)
- Assembly: 9ns vs 1124ns per element (130x faster)
- Large mesh: 0.01ms vs 1.2ms for 1000 elements (120x faster)
- Memory: 0 allocations vs 70,000 allocations
- GPU: Compatible (bits types) vs Incompatible (pointers)

This documents a fundamental architectural decision for JuliaFEM 1.0.
2025-11-09 17:51:34 +02:00
Jukka Aho 7ed8d003c6 style(basis): Clean up whitespace in lagrange_generator.jl
- Remove trailing whitespace
- Fix spacing in Dict type annotation: Dict{String, Tuple{...}} → Dict{String,Tuple{...}}

No functional changes.
2025-11-09 17:36:30 +02:00
Jukka Aho 41b8a4c98c feat(basis): Enable Lagrange{T,P} basis functions in main module
- Uncommented include for lagrange_generated.jl
- Added exports: AbstractBasis, Lagrange, Serendipity
- Updated comments to reflect new parametric architecture

Package now loads successfully with new basis system.
All 15 element types available:
  Lagrange{Segment, 1}, Lagrange{Segment, 2}
  Lagrange{Triangle, 1}, Lagrange{Triangle, 2}
  Lagrange{Quadrilateral, 1}, Lagrange{Quadrilateral, 2} (×2 variants)
  Lagrange{Tetrahedron, 1}, Lagrange{Tetrahedron, 2}
  Lagrange{Hexahedron, 1}, Lagrange{Hexahedron, 2} (×2 variants)
  Lagrange{Pyramid, 1}
  Lagrange{Wedge, 1}, Lagrange{Wedge, 2}
2025-11-09 17:30:37 +02:00
Jukka Aho 4f8f85c895 chore(basis): Regenerate basis functions for Lagrange{T,P} architecture
Generated by: julia --project=. src/basis/lagrange_generator.jl

Changes:
- All 15 element types now use Lagrange{T,P} parametric type
- Functions: get_reference_element_coordinates(), eval_basis!(), eval_dbasis!()
- Reference coordinates now return tuples (zero-allocation)
- Removed old Seg2Basis, Tri3Basis, Quad4Basis, etc. struct definitions
- All methods work with both Type{Lagrange{T,P}} and Lagrange{T,P} instances

Validated:
- Triangle: Kronecker delta property holds (N_i(x_j) = δ_ij)
- Quadrilateral, Tetrahedron, Hexahedron: First node evaluates to (1,0,0,...)
- Derivatives: Correct gradients at reference coordinates
2025-11-09 17:30:07 +02:00
Jukka Aho 6fd99fa323 feat(basis): Update generator for parametric Lagrange{T,P} architecture
- Changed create_basis() signature from (name, desc, X, ...) to (topology_type, poly_degree, desc, X, ...)
- Generator now produces methods for Lagrange{Segment,1}, Lagrange{Triangle,1}, etc.
- Added ELEMENT_TO_LAGRANGE mapping dict (old names → topology_type + poly_degree)
- Fixed reference coordinates to return tuples instead of vectors
- Removed struct definitions (now use parametric Lagrange{T,P} type)
- Removed Base.size(), Base.length() methods (use nnodes() instead)
- Fixed typo: 'antsatz' → 'ansatz'

All 15 element types regenerate successfully:
  Segment (1,2), Triangle (1,2), Quadrilateral (1,2,2), Tetrahedron (1,2),
  Hexahedron (1,2,2), Pyramid (1), Wedge (1,2)

Tests pass for all element types.
2025-11-09 17:29:35 +02:00
Jukka Aho 626cc49780 refactor: Comment out old basis and problem files incompatible with new API
Commented out files using AbstractBasis{dim}:
- basis/lagrange_generated.jl (449 lines, uses AbstractBasis{1/2/3})
- basis/nurbs_segment.jl (NSeg <: AbstractBasis{1})
- basis/nurbs_surface.jl (NSurf <: AbstractBasis{2})
- basis/nurbs_solid.jl (NSolid <: AbstractBasis{3})
- basis/math.jl (jacobian, grad functions use AbstractBasis{dim})
- elements/elements_lagrange.jl (Poi1 <: AbstractBasis{0})
- elements/integrate.jl (references NSeg, Poi1, old basis types)

Commented out problem files using old Element API:
- problems_heat.jl (uses Seg2, Tri3, Quad4, element.sfields)
- problems_truss.jl (uses Seg2, Poi1, element.sfields)
- problems_elasticity.jl (uses old element types, element.sfields)
- problems_dirichlet.jl (uses old API)
- problems_mortar.jl (uses old API)
- problems_mortar_3d.jl (uses old API)

Status after this commit:
- Package loads successfully ✓
- ~70% of functionality removed (intentional)
- All 43 tests fail (expected - old API incompatible)
- Next: Regenerate basis functions for Lagrange{T,P}
- Then: Rewrite math.jl, integrate.jl, rebuild problems

Rationale: Clean break from old Dict-based, type-unstable architecture.
New GPU-ready Element requires complete rebuild of dependent code.
2025-11-09 17:09:48 +02:00
Jukka Aho f89d48a112 refactor(deprecated): Remove old getproperty redirection for new Element API
- Comment out Base.getproperty(element::Element, :fields) redirection
- Old code redirected element.fields → element.dfields (Dict-based fields)
- New Element has fields::F directly (type-stable NamedTuple or struct)
- No redirection needed with new architecture
- Rationale: New Element{N,NIP,F,B} has fields as direct struct member
2025-11-09 17:09:27 +02:00