From e15a97fcfe403d22ec9bf963b6056f6f191715c3 Mon Sep 17 00:00:00 2001 From: Jukka Aho Date: Sat, 9 May 2026 18:35:23 +0300 Subject: [PATCH] feat(legacy): add sparse LinearSystem assembly container Introduce the legacy augmented-system representation used by `Solver`/`Analysis`. - Track stiffness blocks, constraint matrices, and RHS assembly scratch. --- src/legacy/linear_system.jl | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/legacy/linear_system.jl diff --git a/src/legacy/linear_system.jl b/src/legacy/linear_system.jl new file mode 100644 index 0000000..99f1ef4 --- /dev/null +++ b/src/legacy/linear_system.jl @@ -0,0 +1,53 @@ +# This file is a part of JuliaFEM. +# License is MIT: see https://github.com/JuliaFEM/FEMBase.jl/blob/master/LICENSE + +mutable struct LinearSystem{Tv, Ti<:Integer} + M :: SparseMatrixCSC{Tv, Ti} + K :: SparseMatrixCSC{Tv, Ti} + Kg :: SparseMatrixCSC{Tv, Ti} + C1 :: SparseMatrixCSC{Tv, Ti} + C2 :: SparseMatrixCSC{Tv, Ti} + D :: SparseMatrixCSC{Tv, Ti} + f :: SparseVector{Tv, Ti} + fg :: SparseVector{Tv, Ti} + g :: SparseVector{Tv, Ti} + u :: SparseVector{Tv, Ti} + la :: SparseVector{Tv, Ti} + dim :: Int +end + +function LinearSystem(dim::Int) + return LinearSystem(spzeros(dim, dim), spzeros(dim, dim), + spzeros(dim, dim), spzeros(dim, dim), + spzeros(dim, dim), spzeros(dim, dim), + spzeros(dim), spzeros(dim), spzeros(dim), + spzeros(dim), spzeros(dim), dim) +end + +abstract type AbstractLinearSystemSolver end + +function solve!(::LinearSystem, ::Solver) where Solver<:AbstractLinearSystemSolver + @info("This is a placeholder function for solving linear systems. To solve " * + "linear systems, you must define a function " * + "solve!(system::LinearSystem, solver::$Solver)") +end + +function can_solve(::LinearSystem, ::Solver) where Solver<:AbstractLinearSystemSolver + return (true, "OK") +end + +function solve!(ls::LinearSystem, solvers::Vector{S}) where S<:AbstractLinearSystemSolver + for solver in solvers + Solver = typeof(solver) + cansolve, msg = can_solve(ls, solver) + if !cansolve + @info("Solver $Solver cannot solve linear system: $msg") + continue + end + timeit("solve linear system using solver $Solver") do + solve!(ls, solver) + end + return + end + error("Failed to solve linear system.") +end