6565__issquare (assump:: OperatorAssumptions ) = assump. issq
6666__conditioning (assump:: OperatorAssumptions ) = assump. condition
6767
68+ """
69+ LinearCache{TA, Tb, Tu, Tp, Talg, Tc, Tl, Tr, Ttol, issq, S}
70+
71+ The core cache structure used by LinearSolve for storing and managing the state of linear
72+ solver computations. This mutable struct acts as the primary interface for iterative
73+ solving and caching of factorizations and intermediate results.
74+
75+ ## Fields
76+
77+ - `A::TA`: The matrix operator of the linear system.
78+ - `b::Tb`: The right-hand side vector of the linear system.
79+ - `u::Tu`: The solution vector (preallocated storage for the result).
80+ - `p::Tp`: Parameters passed to the linear solver algorithm.
81+ - `alg::Talg`: The linear solver algorithm instance.
82+ - `cacheval::Tc`: Algorithm-specific cache storage for factorizations and intermediate computations.
83+ - `isfresh::Bool`: Cache validity flag for the matrix `A`. `false` means `cacheval` is up-to-date
84+ with respect to `A`, `true` means `cacheval` needs to be updated.
85+ - `precsisfresh::Bool`: Cache validity flag for preconditioners. `false` means `Pl` and `Pr`
86+ are up-to-date with respect to `A`, `true` means they need to be updated.
87+ - `Pl::Tl`: Left preconditioner operator.
88+ - `Pr::Tr`: Right preconditioner operator.
89+ - `abstol::Ttol`: Absolute tolerance for iterative solvers.
90+ - `reltol::Ttol`: Relative tolerance for iterative solvers.
91+ - `maxiters::Int`: Maximum number of iterations for iterative solvers.
92+ - `verbose::Bool`: Whether to print verbose output during solving.
93+ - `assumptions::OperatorAssumptions{issq}`: Assumptions about the operator properties.
94+ - `sensealg::S`: Sensitivity analysis algorithm for automatic differentiation.
95+
96+ ## Usage
97+
98+ The `LinearCache` is typically created via `init(::LinearProblem, ::SciMLLinearSolveAlgorithm)`
99+ and then used with `solve!(cache)` for efficient repeated solves with the same matrix structure
100+ but potentially different right-hand sides or parameter values.
101+
102+ ## Cache Management
103+
104+ The cache automatically tracks when matrix `A` or parameters `p` change by setting the
105+ appropriate freshness flags. When `solve!` is called, stale cache entries are automatically
106+ recomputed as needed.
107+ """
68108mutable struct LinearCache{TA, Tb, Tu, Tp, Talg, Tc, Tl, Tr, Ttol, issq, S}
69109 A:: TA
70110 b:: Tb
@@ -106,19 +146,81 @@ function update_cacheval!(cache::LinearCache, name::Symbol, x)
106146end
107147update_cacheval! (cache, cacheval, name:: Symbol , x) = cacheval
108148
149+ """
150+ init_cacheval(alg::SciMLLinearSolveAlgorithm, args...)
151+
152+ Initialize algorithm-specific cache values for the given linear solver algorithm.
153+ This function returns `nothing` by default and is intended to be overloaded by
154+ specific algorithm implementations that need to store intermediate computations
155+ or factorizations.
156+
157+ ## Arguments
158+ - `alg`: The linear solver algorithm instance
159+ - `args...`: Additional arguments passed to the cache initialization
160+
161+ ## Returns
162+ Algorithm-specific cache value or `nothing` for algorithms that don't require caching.
163+ """
109164init_cacheval (alg:: SciMLLinearSolveAlgorithm , args... ) = nothing
110165
111166function SciMLBase. init (prob:: LinearProblem , args... ; kwargs... )
112167 SciMLBase. init (prob, nothing , args... ; kwargs... )
113168end
114169
170+ """
171+ default_tol(T)
172+
173+ Compute the default tolerance for iterative linear solvers based on the element type.
174+ The tolerance is typically set as the square root of the machine epsilon for the
175+ given floating point type, ensuring numerical accuracy appropriate for that precision.
176+
177+ ## Arguments
178+ - `T`: The element type of the linear system
179+
180+ ## Returns
181+ - For floating point types: `√(eps(T))`
182+ - For exact types (Rational, Integer): `0` (exact arithmetic)
183+ - For Any type: `0` (conservative default)
184+ """
115185default_tol (:: Type{T} ) where {T} = √ (eps (T))
116186default_tol (:: Type{Complex{T}} ) where {T} = √ (eps (T))
117187default_tol (:: Type{<:Rational} ) = 0
118188default_tol (:: Type{<:Integer} ) = 0
119189default_tol (:: Type{Any} ) = 0
120190
191+ """
192+ default_alias_A(alg, A, b) -> Bool
193+
194+ Determine the default aliasing behavior for the matrix `A` given the algorithm type.
195+ Aliasing allows the algorithm to modify the original matrix in-place for efficiency,
196+ but this may not be desirable or safe for all algorithm types.
197+
198+ ## Arguments
199+ - `alg`: The linear solver algorithm
200+ - `A`: The matrix operator
201+ - `b`: The right-hand side vector
202+
203+ ## Returns
204+ - `false`: Safe default, algorithm will not modify the original matrix `A`
205+ - `true`: Algorithm may modify `A` in-place for efficiency
206+
207+ ## Algorithm-Specific Behavior
208+ - Dense factorizations: `false` (destructive, need to preserve original)
209+ - Krylov methods: `true` (non-destructive, safe to alias)
210+ - Sparse factorizations: `true` (typically preserve sparsity structure)
211+ """
121212default_alias_A (:: Any , :: Any , :: Any ) = false
213+
214+ """
215+ default_alias_b(alg, A, b) -> Bool
216+
217+ Determine the default aliasing behavior for the right-hand side vector `b` given the
218+ algorithm type. Similar to `default_alias_A` but for the RHS vector.
219+
220+ ## Returns
221+ - `false`: Safe default, algorithm will not modify the original vector `b`
222+ - `true`: Algorithm may modify `b` in-place for efficiency
223+ """
122224default_alias_b (:: Any , :: Any , :: Any ) = false
123225
124226# Non-destructive algorithms default to true
@@ -130,6 +232,24 @@ default_alias_b(::AbstractSparseFactorization, ::Any, ::Any) = true
130232
131233DEFAULT_PRECS (A, p) = IdentityOperator (size (A)[1 ]), IdentityOperator (size (A)[2 ])
132234
235+ """
236+ __init_u0_from_Ab(A, b)
237+
238+ Initialize the solution vector `u0` with appropriate size and type based on the
239+ matrix `A` and right-hand side `b`. The solution vector is allocated with the
240+ same element type as `b` and sized to match the number of columns in `A`.
241+
242+ ## Arguments
243+ - `A`: The matrix operator (determines solution vector size)
244+ - `b`: The right-hand side vector (determines element type)
245+
246+ ## Returns
247+ A zero-initialized vector of size `(size(A, 2),)` with element type matching `b`.
248+
249+ ## Specializations
250+ - For static matrices (`SMatrix`): Returns a static vector (`SVector`)
251+ - For regular matrices: Returns a similar vector to `b` with appropriate size
252+ """
133253function __init_u0_from_Ab (A, b)
134254 u0 = similar (b, size (A, 2 ))
135255 fill! (u0, false )
0 commit comments