Teko Version of the Day
Loading...
Searching...
No Matches
Teko_DiagonalPreconditionerFactory.cpp
1// @HEADER
2// *****************************************************************************
3// Teko: A package for block and physics based preconditioning
4//
5// Copyright 2010 NTESS and the Teko contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#include "Teko_DiagonalPreconditionerFactory.hpp"
11#include "Teko_DiagonalPreconditionerOp.hpp"
12
13#include "Teko_TpetraHelpers.hpp"
14#include "Thyra_TpetraLinearOp.hpp"
15#include "TpetraExt_PointToBlockDiagPermute_decl.hpp"
16
17using Teuchos::rcp;
18using Teuchos::RCP;
19
20namespace Teko {
21
22DiagonalPrecondState::DiagonalPrecondState() {}
23
24/*****************************************************/
25
26DiagonalPreconditionerFactory::DiagonalPreconditionerFactory() {}
27
29 return Teuchos::rcp(new DiagonalPrecondState());
30}
31
33 LinearOp& lo, PreconditionerState& state) const {
34 if (diagonalType_ == BlkDiag) {
35 DiagonalPrecondState& MyState = Teuchos::dyn_cast<DiagonalPrecondState>(state);
36
37 if (TpetraHelpers::isTpetraLinearOp(lo)) {
38 RCP<const Thyra::TpetraLinearOp<ST, LO, GO, NT> > tlo =
39 Teuchos::rcp_dynamic_cast<const Thyra::TpetraLinearOp<ST, LO, GO, NT> >(lo, true);
40 RCP<const Tpetra::Operator<ST, LO, GO, NT> > top = tlo->getConstTpetraOperator();
41 RCP<const Tpetra::CrsMatrix<ST, LO, GO, NT> > MAT =
42 Teuchos::rcp_dynamic_cast<const Tpetra::CrsMatrix<ST, LO, GO, NT> >(top, true);
43
44 RCP<Tpetra::Ext::PointToBlockDiagPermute<ST, LO, GO, NT> > BDP;
45 if (MyState.BDP_ == Teuchos::null) {
46 BDP = Teuchos::rcp(new Tpetra::Ext::PointToBlockDiagPermute<ST, LO, GO, NT>(*MAT));
47 BDP->setParameters(List_);
48 BDP->compute();
49 MyState.BDP_ = BDP;
50 } else {
51 BDP = MyState.BDP_;
52 }
53
54 RCP<Tpetra::CrsMatrix<ST, LO, GO, NT> > Hcrs = BDP->createCrsMatrix();
55 return Thyra::tpetraLinearOp<ST, LO, GO, NT>(
56 Thyra::tpetraVectorSpace<ST, LO, GO, NT>(Hcrs->getRangeMap()),
57 Thyra::tpetraVectorSpace<ST, LO, GO, NT>(Hcrs->getDomainMap()), Hcrs);
58 }
59
60 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error,
61 "DiagonalPreconditionerFactory::buildPreconditionerOperator: "
62 "BlkDiag requested, but operator is not Tpetra-supported.");
63 }
64
65 return getInvDiagonalOp(lo, diagonalType_);
66}
67
68void DiagonalPreconditionerFactory::initializeFromParameterList(const Teuchos::ParameterList& pl) {
69 List_ = pl;
70
71 diagonalType_ = BlkDiag;
72 if (pl.isParameter("Diagonal Type")) {
73 diagonalType_ = getDiagonalType(pl.get<std::string>("Diagonal Type"));
74 TEUCHOS_TEST_FOR_EXCEPT(diagonalType_ == NotDiag);
75 }
76
77 if (diagonalType_ == BlkDiag) {
78 // Reset default to invert mode if the user hasn't specified something else
79 Teuchos::ParameterList& SubList = List_.sublist("blockdiagmatrix: list");
80 SubList.set("apply mode", SubList.get("apply mode", "invert"));
81 }
82}
83
84} // end namespace Teko
@ BlkDiag
Specifies that a block diagonal approximation is to be used.
@ NotDiag
For user convenience, if Teko recieves this value, exceptions will be thrown.
virtual void initializeFromParameterList(const Teuchos::ParameterList &pl)
Initialize from a parameter list.
Teuchos::RCP< PreconditionerState > buildPreconditionerState() const
Builds a preconditioner state object.
LinearOp buildPreconditionerOperator(LinearOp &lo, PreconditionerState &state) const
An implementation of a state object preconditioners.