Skip to main content

test_sparse_lu/
test_sparse_lu.rs

1use section_properties::fea::SparseMatrix;
2use section_properties::fea::solvers::SparseLu;
3
4fn main() {
5    // Test 1: Simple 2x2 matrix
6    println!("Test 1: 2x2 matrix [[0, 1], [1, 0]]");
7    let mut a = SparseMatrix::new(2);
8    a.add(0, 1, 1.0);
9    a.add(1, 0, 1.0);
10    a.compress();
11    let lu = SparseLu::factor(&a).unwrap();
12    let b = vec![1.0, 2.0];
13    let x = lu.solve(&b);
14    println!("  Solution: {:?}", x);
15    println!("  Expected: [2, 1]");
16
17    // Test 2: Diagonally dominant
18    println!("\nTest 2: Diagonally dominant");
19    let mut a2 = SparseMatrix::new(3);
20    a2.add(0, 0, 4.0);
21    a2.add(0, 1, 1.0);
22    a2.add(1, 0, 1.0);
23    a2.add(1, 1, 4.0);
24    a2.add(1, 2, 1.0);
25    a2.add(2, 1, 1.0);
26    a2.add(2, 2, 4.0);
27    a2.compress();
28    let lu2 = SparseLu::factor(&a2).unwrap();
29    let b2 = vec![1.0, 2.0, 3.0];
30    let x2 = lu2.solve(&b2);
31    println!("  Solution: {:?}", x2);
32
33    // Verify
34    let mut a2_dense = vec![vec![0.0; 3]; 3];
35    for i in 0..3 {
36        for j in 0..3 {
37            // Reconstruct from factors
38        }
39    }
40}