10 #include "Teko_BlockInvDiagonalStrategy.hpp"
11 #include "Teko_InverseFactory.hpp"
15 InvFactoryDiagStrategy::InvFactoryDiagStrategy(
const Teuchos::RCP<InverseFactory>& factory) {
17 invDiagFact_.resize(1, factory);
18 defaultInvFact_ = factory;
21 InvFactoryDiagStrategy::InvFactoryDiagStrategy(
22 const std::vector<Teuchos::RCP<InverseFactory> >& factories,
23 const Teuchos::RCP<InverseFactory>& defaultFact) {
24 invDiagFact_ = factories;
26 if (defaultFact == Teuchos::null)
27 defaultInvFact_ = invDiagFact_[0];
29 defaultInvFact_ = defaultFact;
32 InvFactoryDiagStrategy::InvFactoryDiagStrategy(
33 const std::vector<Teuchos::RCP<InverseFactory> >& inverseFactories,
34 const std::vector<Teuchos::RCP<InverseFactory> >& preconditionerFactories,
35 const Teuchos::RCP<InverseFactory>& defaultInverseFact,
36 const Teuchos::RCP<InverseFactory>& defaultPreconditionerFact) {
37 invDiagFact_ = inverseFactories;
38 precDiagFact_ = preconditionerFactories;
40 if (defaultInverseFact == Teuchos::null)
41 defaultInvFact_ = invDiagFact_[0];
43 defaultInvFact_ = defaultInverseFact;
44 defaultPrecFact_ = defaultPreconditionerFact;
51 std::vector<LinearOp>& invDiag)
const {
52 Teko_DEBUG_SCOPE(
"InvFactoryDiagStrategy::getInvD", 10);
55 size_t diagCnt = A->productRange()->numBlocks();
57 Teko_DEBUG_MSG(
"# diags = " << diagCnt <<
", # inverses = " << invDiagFact_.size(), 6);
59 const std::string opPrefix =
"JacobiDiagOp";
60 for (
size_t i = 0; i < diagCnt; i++) {
61 auto precFact = ((i < precDiagFact_.size()) && (!precDiagFact_[i].is_null()))
64 auto invFact = (i < invDiagFact_.size()) ? invDiagFact_[i] : defaultInvFact_;
65 invDiag.push_back(
buildInverse(*invFact, precFact, getBlock(i, i, A), state, opPrefix, i));
70 Teuchos::RCP<InverseFactory>& precFact,
71 const LinearOp& matrix,
73 const std::string& opPrefix,
int i)
const {
75 ss << opPrefix <<
"_" << i;
80 if (precFact != Teuchos::null) {
81 if (precOp == Teuchos::null) {
82 precOp = precFact->buildInverse(matrix);
89 if (invOp == Teuchos::null)
void rebuildInverse(const InverseFactory &factory, const LinearOp &A, InverseLinearOp &invA)
Abstract class for building an inverse operator.
virtual void getInvD(const BlockedLinearOp &A, BlockPreconditionerState &state, std::vector< LinearOp > &invDiag) const
An implementation of a state object for block preconditioners.
LinearOp buildInverse(const InverseFactory &invFact, Teuchos::RCP< InverseFactory > &precFact, const LinearOp &matrix, BlockPreconditionerState &state, const std::string &opPrefix, int i) const
Conveinence function for building inverse operators.
virtual void addModifiableOp(const std::string &name, const Teko::ModifiableLinearOp &mlo)
Add a named operator to the state object.
InverseLinearOp buildInverse(const InverseFactory &factory, const LinearOp &A)
Build an inverse operator using a factory and a linear operator.
virtual Teko::ModifiableLinearOp & getModifiableOp(const std::string &name)
Add a named operator to the state object.