1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! KSP/PC context types and factories.
//!
//! Most users configure solvers through [`KspContext`], which owns the solver type,
//! preconditioner choice, operator bindings, and the `setup -> solve` lifecycle.
//! Preconditioner construction helpers live in [`pc_context`].
//!
//! ## Lifecycle (summary)
//! 1. `set_type` / `set_pc_type` / `set_from_options`
//! 2. `set_operators(Amat, Pmat)`
//! 3. `setup()` (idempotent; reuses cached structure/values when possible)
//! 4. `solve(b, x)`
//!
//! ## Example
//! ```rust,no_run
//! use kryst::prelude::*;
//! use std::sync::Arc;
//!
//! struct IdentityOp(usize);
//! impl LinOp for IdentityOp {
//! type S = S;
//!
//! fn dims(&self) -> (usize, usize) {
//! (self.0, self.0)
//! }
//!
//! fn matvec(&self, x: &[S], y: &mut [S]) {
//! y.copy_from_slice(x);
//! }
//!
//! fn as_any(&self) -> &dyn std::any::Any {
//! self
//! }
//! }
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let op: Arc<dyn LinOp<S = S>> = Arc::new(IdentityOp(4));
//! let b = vec![S::from_real(1.0); 4];
//! let mut x = vec![S::zero(); 4];
//!
//! let mut ksp = KspContext::new();
//! ksp.set_type(SolverType::Gmres)?;
//! ksp.set_pc_type(PcType::None, None)?;
//! ksp.set_operators(op, None);
//! let _stats = ksp.solve(&b, &mut x)?;
//! # Ok(()) }
//! ```
pub use ;
pub use ;