From 875773f4ce7b4aff3e082e1dc194184a19f2aa18 Mon Sep 17 00:00:00 2001 From: Jukka Aho Date: Thu, 20 Nov 2025 16:56:41 +0200 Subject: [PATCH] test(continuum): Add tests for DOF mapping functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- test/domains/continuum/test_dof_mapping.jl | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/domains/continuum/test_dof_mapping.jl diff --git a/test/domains/continuum/test_dof_mapping.jl b/test/domains/continuum/test_dof_mapping.jl new file mode 100644 index 0000000..5752b23 --- /dev/null +++ b/test/domains/continuum/test_dof_mapping.jl @@ -0,0 +1,23 @@ +# Test get_dof_mapping! function + +@testset "get_dof_mapping!" begin + kernel = create_test_kernel() + mesh = create_test_mesh() + + # Allocate DOF buffer (8 nodes * 3 DOFs = 24) + dofs = zeros(Int, 24) + + # Test DOF mapping for element 1 + get_dof_mapping!(dofs, kernel, 1, mesh) + + # Verify correct DOF indices (1-indexed) + # For element 1 with nodes [1,2,3,4,5,6,7,8]: + # Node 1: DOFs [1,2,3], Node 2: DOFs [4,5,6], etc. + expected_dofs = collect(1:24) + @test dofs == expected_dofs + + # Test zero allocations (warm-up call first) + get_dof_mapping!(dofs, kernel, 1, mesh) + allocs = @allocated get_dof_mapping!(dofs, kernel, 1, mesh) + @test allocs == 0 +end