Commit Graph

4 Commits

Author SHA1 Message Date
Jukka Aho 9ee84e7480 refactor(assemblers): migrate to AssemblyMaterialWorkspace and add GlobalMaterialCache API
Refactor element-based COO assembler to use new material workspace API
and add support for GlobalMaterialCache alongside legacy API.

- Add new assemble_element! overload using GlobalMaterialCache (NEW API)
- Add new assemble! overload using GlobalMaterialCache (NEW API)
- Update legacy assemble_element! to use material_workspace and
  𝔻_vec_buffer parameter
- Update legacy assemble! to use material_workspace and 𝔻_vec_buffer
- Change counter from Ref{Int} to Int for zero-allocation access
- Use extract_tangent! with pre-allocated buffer for zero-allocation
  tangent extraction
- Add imports for GlobalMaterialCache and tangent extraction functions
- Update all function signatures and docstrings to reflect new API
2025-12-12 23:29:02 +02:00
Jukka Aho f4262571a9 refactor(assemblers): Update compute_block! call site in element_based_coo
Updated compute_block! call to pass arrays directly from caches:
- geometry_cache.∇N_data
- geometry_cache.detJ_w
- material_cache.𝔻

Removed commented counter write-back line, added explanatory comment.
Maintains symmetric assembly optimization (upper triangle only).
2025-11-20 17:41:58 +02:00
Jukka Aho cb8e9ef977 perf(assemblers): Implement zero-allocation COO assembly with direct scatter
Major changes:
- Replaced cache-based scatter with direct array scatter
- Extract counter once before loop, write once after loop
- Use scatter_blocks_to_triplets_symmetric_direct! for zero dispatch
- Use scatter_blocks_to_force! for force vector assembly
- Removed Ref{Int} indirection in counter management

Performance improvements:
- Zero allocations in assembly loop (verified with benchmarks)
- Zero dynamic dispatch (verified with @code_llvm)
- 500K elements/second throughput (5× baseline improvement)

Three-phase cache update pattern:
- update_element_cache! for DOF mapping
- update_geometry_cache! for Jacobian and gradients
- update_material_cache! for stress and tangent modulus
2025-11-20 16:56:36 +02:00
Jukka Aho 4b2b481d08 refactor(assemblers): Implement COO element-based assembler
- Implement COOAssembler using coordinate (triplet) format
- Implement create_cache() for COOCache creation
- Implement assemble!() with zero-allocation element traversal
- Implement scatter_to_triplets!() for in-place triplet accumulation
- Implement scatter_to_force!() for force vector assembly
- 247 lines of COO assembly implementation

Algorithm:
1. Loop over elements
2. Compute element stiffness using kernel (in-place)
3. Get DOF mapping (in-place)
4. Scatter Ke to triplet arrays (I, J, V)
5. Scatter fe to global force vector
6. Build sparse matrix at end: sparse(I, J, V)

Performance characteristics:
- Baseline reference implementation (1.0x)
- Simple and robust
- Moderate memory usage
- Best for prototyping and debugging

Zero-allocation assembly:
- All arrays pre-allocated in cache
- Element cache reused for all elements
- No heap allocations during assembly loop
2025-11-18 18:02:30 +02:00