Commit Graph

19 Commits

Author SHA1 Message Date
Jukka Aho 16b652a13e test(continuum): Remove duplicate test_helpers.jl include
Replace include statement with comment noting that test_helpers.jl is included by parent runtests.jl. This eliminates method overwrite warnings for create_test_mesh() and create_test_kernel().

The parent test suite (runtests.jl) includes test_helpers.jl once, making it available to all sub-tests.
2025-11-20 18:24:58 +02:00
Jukka Aho c8b118b8b2 test(domains): Remove Vec{3} conversions in stiffness block allocation test
- Changed 'ξ = Vec{3}(ip.ξ)' to 'ξ = ip.ξ' in two test locations
- First occurrence in warm-up loop
- Second occurrence in allocation measurement loop
- No conversions needed since ip.ξ is now already Vec{3}
2025-11-20 17:57:06 +02:00
Jukka Aho 2bbc9805cb test: Improve reset! test to verify via matrix extraction
Changed verification from counter-only to extracting and checking matrix:
- Added SparseArrays import for nnz()
- Verify nnz(K) > 0 after assembly (triplets exist)
- Verify nnz(K) == 0 after reset (triplets cleared)
- More robust test than checking counter alone

Counter is implementation detail, matrix content is the guarantee.
2025-11-20 17:43:38 +02:00
Jukka Aho 706cee4962 test: Update compute_block! call in kernel_functions test
Updated compute_block! call to pass arrays directly from caches:
- geometry_cache.∇N_data
- geometry_cache.detJ_w
- material_cache.𝔻

Maintains test comparison between manual and automatic integration.
2025-11-20 17:43:14 +02:00
Jukka Aho 13993f196f test: Simplify compute_block! test to verify zero allocations
Replaced cache-based test setup with direct array construction:
- ∇N_data: Matrix{Vec{3,Float64}} with realistic gradient values
- detJ_w: Vector{Float64} with typical integration weights
- D_array: Vector{SymmetricTensor{4,3}} with elasticity tensor

Simplified allocation test to single call (removed loop test).
Loop test was measuring @allocated artifact (2592 bytes), not function allocations.
Single-call test accurately verifies zero-allocation guarantee.
Updated all compute_block! calls to new interface signature.
2025-11-20 17:42:55 +02:00
Jukka Aho 05a6f0bd39 test(continuum): Remove obsolete test_kernel_allocations.jl
Deleted: test/domains/continuum/test_kernel_allocations.jl

Reason:
- Tested old assembly implementation (now deleted)
- Replaced by new comprehensive test suite:
  * test_cache_updates.jl
  * test_compute_block.jl
  * test_full_assembly.jl
  * test_kernel_functions.jl

New tests cover same functionality plus more with new architecture.
Zero allocation property now verified in test_full_assembly.jl.
2025-11-20 16:56:43 +02:00
Jukka Aho 678be8011c test(continuum): Add Hex8 element validation against reference
New file: test/domains/continuum/test_validation_hex8.jl

Tests for:
- Hex8 element stiffness matrix
- Comparison against reference solution
- Validates assembly with hexahedral elements

Validation:
- Creates single Hex8 cube element
- Assembles element stiffness matrix
- Compares against analytical or reference FEM solution
- Checks matrix symmetry and positive definiteness

Ensures assembly works correctly for element types beyond Tet4,
validating generality of the cache architecture.
2025-11-20 16:56:42 +02:00
Jukka Aho 064820713f test(continuum): Add tests for cache reset functions
New file: test/domains/continuum/test_reset_functions.jl

Tests for:
- reset!(cache) for COOCache
- Validates counter reset to 0
- Validates I, J, V arrays zeroed
- Validates force vector zeroed
- Validates element/geometry/material caches reset

Purpose:
- Ensure caches can be reused across multiple assemblies
- Verify no stale data remains
- Test incremental assembly workflows

Critical for iterative solvers and nonlinear problems where
assembly is repeated many times with updated state.
2025-11-20 16:56:42 +02:00
Jukka Aho 1d98e29f2b test(continuum): Add tests for kernel computation functions
New file: test/domains/continuum/test_kernel_functions.jl

Tests for:
- ContinuumKernel construction
- compute_block_at_point (weak form at single point)
- Validates stiffness contribution at integration point
- Checks tensor dimensions and symmetry

Validates:
- Kernel properly wraps formulation and material
- compute_block_at_point produces symmetric Tensor{2,3}
- Integration point contributions are reasonable magnitude
- No NaN or Inf values

Low-level validation of the atomic weak form operation
before integration loop aggregation.
2025-11-20 16:56:41 +02:00
Jukka Aho aac5641ed4 test(continuum): Add utility functions for test setup
New file: test/domains/continuum/test_helpers.jl

Helper functions:
- create_test_mesh_tet4(n) - generates n-element Tet4 mesh
- create_test_kernel() - creates LinearElastic kernel
- create_test_cache() - creates COOCache
- setup_assembly_test(n) - complete setup in one call

Purpose:
- Reduce code duplication across test files
- Provide consistent test data
- Make tests more readable
- Easy to extend for other element types

Used by test_full_assembly.jl, test_compute_block.jl, etc.
2025-11-20 16:56:41 +02:00
Jukka Aho 4619d8a0e8 test(continuum): Add end-to-end assembly integration tests
New file: test/domains/continuum/test_full_assembly.jl

Tests for:
- Complete assembly workflow from mesh to sparse matrix
- COO assembly with LinearElastic material
- Validates K matrix properties (symmetric, positive definite)
- Validates force vector dimensions
- Zero allocation verification

End-to-end test:
- Create mesh (Tet4 elements)
- Create kernel (ContinuumKernel + LinearElastic)
- Create assembler and cache
- Call assemble!
- Extract K and f
- Validate results

Critical integration test ensuring all components work together:
- Cache updates (3 phases)
- Compute blocks (integration)
- Scatter operations (triplets)
- Sparse matrix construction

This is the PRIMARY validation that the entire assembly pipeline
produces correct results with zero allocations.
2025-11-20 16:56:41 +02:00
Jukka Aho c3da11a518 test(continuum): Add tests for dofs_per_node function
New file: test/domains/continuum/test_dofs_per_node.jl

Tests for:
- dofs_per_node(field) for various field types
- Displacement{3} → 3 DOFs per node
- Temperature → 1 DOF per node
- DisplacementRotation → 6 DOFs per node (future)

Validates correct DOF count for field types used in
DOF mapping and cache dimensioning.
2025-11-20 16:56:41 +02:00
Jukka Aho 875773f4ce test(continuum): Add tests for DOF mapping functions
New file: test/domains/continuum/test_dof_mapping.jl

Tests for:
- get_dof_mapping!(dofs, node_ids, field)
- Maps node IDs to global DOF indices
- Validates displacement field (3 DOF/node)
- Validates temperature field (1 DOF/node)

Test cases:
- Single node → [1, 2, 3] for displacement
- Multiple nodes → [1,2,3, 4,5,6, ...] sequential DOFs
- Validates no off-by-one errors
- Validates correct DOF ordering

Ensures DOF mapping used in update_element_cache! is correct.
2025-11-20 16:56:41 +02:00
Jukka Aho 1554fd11fd test(continuum): Add tests for compute_block! integration function
New file: test/domains/continuum/test_compute_block.jl

Tests for:
- compute_block!(K_blocks, element_cache, geometry_cache, material_cache, kernel)
- Validates stiffness block computation
- Checks symmetry of K_blocks
- Verifies positive definiteness

Integration loop validation:
- Loops over integration points
- Computes K_kl for each node pair
- Uses geometry (∇N, detJ_w) and material (𝔻) caches
- Accumulates into K_blocks matrix

Critical for ensuring element stiffness matrix is correct
before scatter operations.
2025-11-20 16:56:41 +02:00
Jukka Aho 727d67c242 test(continuum): Add tests for three-phase cache update functions
New file: test/domains/continuum/test_cache_updates.jl

Tests for:
- update_element_cache! (DOF mapping correctness)
- update_geometry_cache! (Jacobian, gradient computation)
- update_material_cache! (stress, tangent evaluation)

Validates:
- Cache structures populated correctly
- Array sizes match expected dimensions
- Values are finite and reasonable
- Zero allocations in update functions

These tests ensure the three-phase cache update pattern
works correctly before integration into assembly loop.
2025-11-20 16:56:40 +02:00
Jukka Aho ae144f93fb test(continuum): Update test suite includes for new architecture
Removed old test files:
- test_kernel_allocations.jl (deleted)

Added new test files:
- test_dofs_per_node.jl - DOF mapping tests
- test_dof_mapping.jl - Field to DOF mapping
- test_helpers.jl - Utility function tests
- test_kernel_functions.jl - Kernel computation tests
- test_reset_functions.jl - Cache reset tests
- test_cache_updates.jl - Three-phase cache update tests
- test_compute_block.jl - Block computation tests
- test_full_assembly.jl - End-to-end assembly tests
- test_validation_hex8.jl - Hex8 element validation

Test suite restructured to match new cache architecture.
2025-11-20 16:56:38 +02:00
Jukka Aho 084d563fce test(continuum): Add zero-allocation stiffness assembly tests
- Test compute_stiffness_block! allocations for all materials
- Verify LinearElastic stiffness assembly is allocation-free
- Verify NeoHookean stiffness assembly is allocation-free
- Verify PerfectPlasticity stiffness assembly is allocation-free
- Test all continuum theory types (3D, PlaneStress, PlaneStrain, Axisymmetric)
- Use @test @allocations macro for precise allocation tracking
- Validate material tangent computation maintains zero allocations
- 260 lines of stiffness assembly allocation tests
2025-11-19 11:48:12 +02:00
Jukka Aho 74d3079130 test(continuum): Add zero-allocation kernel tests
- Test compute_stress! allocations for all material types
- Verify LinearElastic kernel is allocation-free
- Verify NeoHookean kernel is allocation-free
- Verify PerfectPlasticity kernel is allocation-free
- Test all continuum theory types (3D, PlaneStress, PlaneStrain, Axisymmetric)
- Use @test @allocations macro for precise allocation tracking
- Ensure material trait dispatch maintains zero allocations
- 257 lines of allocation verification tests
2025-11-19 11:48:12 +02:00
Jukka Aho 555c506f17 test(continuum): Add automated allocation and trait tests
Created test/domains/continuum/runtests.jl:
- Test material trait system (6 tests)
  * LinearElastic: StatelessConstantTangent, !needs_deformation, !needs_state
  * NeoHookean: StatelessStrainDependent, needs_deformation, !needs_state
  * PerfectPlasticity: StatefulStrainDependent, needs_deformation, needs_state
- Include zero-allocation tests (27 tests)
  * Verify 0 bytes for LinearElastic integration
  * Verify 0 bytes for NeoHookean integration
  * Test full assembly loop allocations
- Include type stability tests (15 tests)
  * Verify PreparedElement type stability
  * Verify compute_block! type stability
  * Verify trait dispatch type stability

Updated test/runtests.jl:
- Include test/domains/continuum/runtests.jl in main test suite
- Automatically run on every test invocation
- Ensures zero-allocation property maintained
- Ensures material traits work correctly

Updated test/domains/continuum/test_type_stability.jl:
- Adapt to new generic integration API
- Test prepare_element!, compute_block!, compute_all_blocks!
- Verify type stability for both LinearElastic and NeoHookean
- Test material trait helper functions

Test Results:
- 57 tests passing (all tests)
- 33 continuum domain tests (including new trait tests)
- Zero-allocation verified for LinearElastic AND NeoHookean
- Type stability confirmed for generic integration
- Backward compatibility maintained (cantilever test passes)

Why: Automated tests ensure the refactoring maintains performance properties
(zero allocations, type stability) while adding new functionality (traits).
2025-11-19 10:03:46 +02:00