10 #ifndef __Teko_HierarchicalGaussSeidelPreconditionerFactory_hpp__
11 #define __Teko_HierarchicalGaussSeidelPreconditionerFactory_hpp__
13 #include "Teuchos_RCP.hpp"
15 #include "Teko_BlockPreconditionerFactory.hpp"
16 #include "Teko_BlockImplicitLinearOp.hpp"
23 class NestedBlockGS :
public BlockImplicitLinearOp {
25 NestedBlockGS(
const std::map<
int, std::vector<int>>& blockToRow_,
26 const std::map<int, LinearOp>& blockToInvOp_, BlockedLinearOp& A_,
27 bool useLowerTriangle_ =
false);
29 VectorSpace range()
const override {
return productRange_; }
30 VectorSpace domain()
const override {
return productDomain_; }
32 void implicitApply(
const BlockedMultiVector& r, BlockedMultiVector& z,
const double alpha = 1.0,
33 const double beta = 0.0)
const override;
36 void upperTriangularImplicitApply(std::vector<BlockedMultiVector>& r,
37 std::vector<BlockedMultiVector>& z,
const double alpha = 1.0,
38 const double beta = 0.0)
const;
40 void lowerTriangularImplicitApply(std::vector<BlockedMultiVector>& r,
41 std::vector<BlockedMultiVector>& z,
const double alpha = 1.0,
42 const double beta = 0.0)
const;
45 std::map<int, std::vector<int>> blockToRow;
46 std::map<int, LinearOp> blockToInvOp;
47 std::vector<LinearOp> invOps;
49 std::vector<BlockedLinearOp> Ab;
50 bool useLowerTriangle =
false;
52 Teuchos::RCP<const Thyra::ProductVectorSpaceBase<double>> productRange_;
53 Teuchos::RCP<const Thyra::ProductVectorSpaceBase<double>>
57 class HierarchicalGaussSeidelPreconditionerFactory :
public BlockPreconditionerFactory {
59 ~HierarchicalGaussSeidelPreconditionerFactory()
override =
default;
60 HierarchicalGaussSeidelPreconditionerFactory();
63 BlockPreconditionerState& state)
const override;
66 void initializeFromParameterList(
const Teuchos::ParameterList& pl)
override;
70 LinearOp buildBlockInverse(
const InverseFactory& invFact,
71 const Teuchos::RCP<InverseFactory>& precFact,
72 const BlockedLinearOp& matrix, BlockPreconditionerState& state,
73 int hierarchicalBlockNum)
const;
74 template <
typename LinearOpType>
75 LinearOp buildInverseImpl(
const InverseFactory& invFact,
76 const Teuchos::RCP<InverseFactory>& precFact,
77 const LinearOpType& matrix, BlockPreconditionerState& state,
78 int hierarchicalBlockNum)
const {
80 ss <<
"hierarchical_block_" << hierarchicalBlockNum;
82 ModifiableLinearOp& invOp = state.getModifiableOp(ss.str());
83 ModifiableLinearOp& precOp = state.getModifiableOp(
"prec_" + ss.str());
85 if (precFact != Teuchos::null) {
86 if (precOp == Teuchos::null) {
87 precOp = precFact->buildInverse(matrix);
88 state.addModifiableOp(
"prec_" + ss.str(), precOp);
94 if (invOp == Teuchos::null)
96 invOp = Teko::buildInverse(invFact, matrix);
100 if (precOp.is_null())
101 Teko::rebuildInverse(invFact, matrix, invOp);
109 std::map<int, std::vector<int>> blockToRow;
110 std::map<int, Teuchos::RCP<InverseFactory>> blockToInverse;
111 std::map<int, Teuchos::RCP<InverseFactory>> blockToPreconditioner;
112 mutable std::map<int, LinearOp> blockToInvOp;
114 bool useLowerTriangle =
false;
void rebuildInverse(const InverseFactory &factory, const LinearOp &A, InverseLinearOp &invA)
virtual LinearOp buildPreconditionerOperator(BlockedLinearOp &blo, BlockPreconditionerState &state) const =0
Function that is called to build the preconditioner for the linear operator that is passed in...
virtual LinearOp buildPreconditionerOperator(LinearOp &blo, PreconditionerState &state) const
Function that is called to build the preconditioner for the linear operator that is passed in...
virtual void implicitApply(const Thyra::EOpTransp M_trans, const BlockedMultiVector &x, BlockedMultiVector &y, const double alpha=1.0, const double beta=0.0) const
Perform a matrix vector multiply with this implicitly defined blocked operator.
InverseLinearOp buildInverse(const InverseFactory &factory, const LinearOp &A)
Build an inverse operator using a factory and a linear operator.