|
Teko Version of the Day
|
This page introduces the core objects and walks through the minimal path to a working block preconditioner: assemble a blocked operator → choose a strategy → build the inverse → apply it. It follows examples/BuildPreconditioner/example-driver-belos.cpp (the full, runnable version).
Teko is layered on top of Thyra. Its central operator and vector types are Teuchos::RCP handles around Thyra abstractions:
| Teko type | Underlying Thyra object held by the RCP | Role |
|---|---|---|
Teko::LinearOp | const Thyra::LinearOpBase<double> | Any linear operator — a single block or a whole blocked system. |
Teko::BlockedLinearOp | Thyra::PhysicallyBlockedLinearOpBase<double> | A block operator you assemble block-by-block. |
Teko::MultiVector | Thyra::MultiVectorBase<double> | Solution/right-hand-side vectors, possibly blocked. |
Teko::BlockedMultiVector | Thyra::ProductMultiVectorBase<double> | A product multi-vector with one component per block. |
Teko::VectorSpace | const Thyra::VectorSpaceBase<double> | Domain/range space metadata for operators and vectors. |
Teko::InverseFactory | — | Produces an operator approximating the inverse of a LinearOp. |
Teko::InverseLibrary | — | A registry of named InverseFactory objects, built from a parameter list. |
Because Teko works on the Thyra layer, you wrap your native Tpetra matrices with Thyra::tpetraLinearOp once, then work exclusively with Teko::LinearOp.
Two factory patterns are central to Teko. A BlockPreconditionerFactory knows how to build a block preconditioner for a particular blocked operator, but it is reusable: the same factory can be applied to different operators with the same mathematical structure. An InverseFactory plays the same role for sub-solves. Block methods such as Jacobi, Gauss-Seidel, SIMPLE, and LSC ask inverse factories to approximate the inverse of diagonal blocks or Schur-complement operators without hard-coding whether that inverse is a direct solve, Krylov solve, single-level preconditioner, or multigrid preconditioner.
Wrap your native Tpetra matrices as Thyra operators, then assemble them into a block operator. The simplest constructor is Thyra::block2x2:
For an arbitrary grid of blocks, use Teko::zeroBlockedOp / Teko::setBlock / Teko::endBlockFill (see Advanced Topics). If instead you start from a single monolithic matrix, let Teko split it for you: use strided blocking for regular interleaved fields, or BlockedTpetraOperator for arbitrary field-to-GID maps (see below and Examples).
An InverseLibrary maps names to inverse factories. Build it from a parameter list:
Each sublist name ("Jacobi", "Gauss-Seidel") is a label you choose. The mandatory "Type" key selects the backend. Here "Ifpack2" refers to a Stratimikos preconditioner; because the library is built with a Stratimikos builder, all Stratimikos solvers and preconditioners are available by name automatically. The full rules are on The Inverse Library page.
Teko::buildInverse turns the factory + the blocked operator into a single Teko::LinearOp that approximates 
That prec is an ordinary Thyra operator. There is no separate "apply" ceremony — applying prec is applying the preconditioner.
Because prec and A are Thyra operators, they drop straight into Belos:
If you would rather keep your solver in Tpetra land, Teko provides operator wrappers that build and apply the preconditioner without exposing Thyra:
This is the pattern in examples/BuildPreconditioner/example-driver.cpp.
Use StridedTpetraOperator when a fixed per-node stride describes the fields. If your monolithic matrix uses another ordering — for example, application-owned GIDs for velocity, pressure, temperature, or material fields are not regularly interleaved — use Teko::TpetraHelpers::BlockedTpetraOperator instead. Its constructor takes a std::vector<std::vector<GO>>: the outer vector is the Teko block number, and each inner vector lists the monolithic global IDs owned by this MPI rank that belong to that block.
Across all MPI ranks, the inner vectors should partition the monolithic domain/range map for ordinary non-overlapping field splits. BlockedTpetraOperator assumes a square operator with matching domain and range maps. The GIDs in an inner vector do not need to be contiguous or strided; Teko builds contiguous block-local maps internally for each block. The wrapper remains a Tpetra::Operator, so it can be passed to TpetraBlockPreconditioner::buildPreconditioner and then to Belos in the same way as the strided wrapper. Useful diagnostics include blockedA->GetBlock(i,j), blockedA->WriteBlocks(prefix), blockedA->testAgainstFullOperator(count,tol), blockedA->Reorder(manager), and blockedA->RebuildOps() after matrix values change with the same block structure.
"Inverse Type" naming and how it reaches Ifpack2/MueLu/Amesos2/Belos, read The Inverse Library.