|
1 | 1 | using Ferrite, Test, SparseArrays, Random |
2 | 2 | using SparseMatricesCSR: SparseMatrixCSR |
| 3 | +using LinearAlgebra |
3 | 4 |
|
4 | 5 | # Minimal implementation of a custom sparsity pattern |
5 | 6 | struct TestPattern <: Ferrite.AbstractSparsityPattern |
@@ -334,15 +335,18 @@ end |
334 | 335 | end |
335 | 336 |
|
336 | 337 | @testset "FastSparsityPattern" begin |
337 | | - # Internal fast-path for supported cases |
338 | | - for CT in (Line, Quadrilateral, Tetrahedron) |
| 338 | + function fsp_test_create_dh(CT) |
339 | 339 | RS = getrefshape(CT) |
340 | 340 | dim = Ferrite.getrefdim(RS) |
341 | 341 | grid = generate_grid(CT, ntuple(_ -> 5, dim)) |
342 | 342 | dh = DofHandler(grid) |
343 | 343 | add!(dh, :a, Lagrange{RS, 1}()) |
344 | 344 | add!(dh, :b, Lagrange{RS, 2}()^dim) |
345 | | - close!(dh) |
| 345 | + return close!(dh) |
| 346 | + end |
| 347 | + # Internal fast-path for supported cases |
| 348 | + for CT in (Line, Quadrilateral, Tetrahedron) |
| 349 | + dh = fsp_test_create_dh(CT) |
346 | 350 | sp = add_sparsity_entries!(init_sparsity_pattern(dh), dh) |
347 | 351 | fsp = Ferrite.FastSparsityPattern(dh) |
348 | 352 | K1 = allocate_matrix(sp) |
|
357 | 361 | K2_csr.nzval .= 1:length(K2_csr.nzval) |
358 | 362 | @test K1_csr == K2_csr |
359 | 363 | end |
| 364 | + # Test different number types (Int32, Float32) |
| 365 | + for Tv in (Float32, Float64) |
| 366 | + for Ti in (Int32, Int64) |
| 367 | + dh = fsp_test_create_dh(Quadrilateral) |
| 368 | + MatrixType = SparseMatrixCSC{Float64, Ti} |
| 369 | + K1 = allocate_matrix(MatrixType, dh) |
| 370 | + @test isa(K1, MatrixType) |
| 371 | + compare_matrices(K1, allocate_matrix(dh)) |
| 372 | + |
| 373 | + MatrixTypeCSR = SparseMatrixCSR{1, Tv, Ti} |
| 374 | + K1_csr = allocate_matrix(MatrixTypeCSR, dh) |
| 375 | + @test isa(K1_csr, MatrixTypeCSR) |
| 376 | + end |
| 377 | + end |
| 378 | + |
| 379 | + # Test logic for Symmetric matrices works (will use SparsityPattern) |
| 380 | + dh = fsp_test_create_dh(Triangle) |
| 381 | + for MatrixType in ( |
| 382 | + Symmetric{Float64, SparseMatrixCSC{Float64, Int}}, |
| 383 | + # Symmetric{Float64, SparseMatrixCSR{1, Float64, Int}} # Does not work, see #1311 |
| 384 | + ) |
| 385 | + K1 = allocate_matrix(MatrixType, dh) |
| 386 | + @test isa(K1, MatrixType) |
| 387 | + end |
360 | 388 | end |
0 commit comments