Teko  Version of the Day
 All Classes Files Functions Variables Pages
Teko_ProbingPreconditionerFactory.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_ProbingPreconditionerFactory.hpp"
11 
12 #ifdef Teko_ENABLE_Isorropia
13 
14 #include "Teko_EpetraOperatorWrapper.hpp"
15 
16 #include "Thyra_get_Epetra_Operator.hpp"
17 #include "Thyra_EpetraLinearOp.hpp"
18 #include "Epetra_CrsMatrix.h"
19 
20 using Teuchos::rcp;
21 using Teuchos::RCP;
22 using Teuchos::rcp_dynamic_cast;
23 using Teuchos::rcpFromRef;
24 
25 namespace Teko {
26 
27 /*****************************************************/
28 
29 ProbingPreconditionerFactory::ProbingPreconditionerFactory() {
30  prober = rcp(new Isorropia::Epetra::Prober);
31 }
32 
33 LinearOp ProbingPreconditionerFactory::buildPreconditionerOperator(
34  LinearOp& lo, PreconditionerState& state) const {
35  // make an epetra operator to be probed
36  RCP<Epetra_Operator> epetraLo = rcp(new Teko::Epetra::EpetraOperatorWrapper(lo));
37 
38  // build color scheme
39  prober->color();
40 
41  // probe operator: take me to your leader
42  RCP<Epetra_CrsMatrix> retOp = prober->probe(*epetraLo);
43  Teko::LinearOp probedOp = Thyra::epetraLinearOp(retOp);
44 
45  return Teko::buildInverse(*invFactory_, probedOp);
46 }
47 
48 void ProbingPreconditionerFactory::initializeFromParameterList(const Teuchos::ParameterList& pl) {
49  RCP<const InverseLibrary> invLib = getInverseLibrary();
50 
51  const std::string inverse_type = "Inverse Type";
52  const std::string probing_graph_operator = "Probing Graph Operator";
53  const std::string probing_graph = "Probing Graph";
54  const std::string user_graph = "User Will Set Probing Graph";
55 
56  // get string specifying default inverse
57  std::string invStr = "Amesos";
58  if (pl.isParameter(inverse_type)) invStr = pl.get<std::string>(inverse_type);
59 
60  if (pl.isParameter(probing_graph_operator))
61  setGraphOperator(pl.get<Teko::LinearOp>(probing_graph_operator));
62  else if (pl.isParameter(probing_graph))
63  setGraph(pl.get<RCP<const Epetra_CrsGraph> >(probing_graph));
64  else if (pl.isParameter(user_graph) && pl.get<bool>("User Will Set Probing Graph")) {
65  // noop
66  } else {
67  Teuchos::RCP<Teko::RequestHandler> rh = getRequestHandler();
68  rh->preRequest<RCP<const Epetra_CrsGraph> >(Teko::RequestMesg("Probing Graph"));
69  setGraph(rh->request<RCP<const Epetra_CrsGraph> >(Teko::RequestMesg("Probing Graph")));
70  }
71 
72  setInverseFactory(invLib->getInverseFactory(invStr));
73 }
74 
75 void ProbingPreconditionerFactory::setGraphOperator(const Teko::LinearOp& graphOp) {
76  RCP<const Epetra_CrsMatrix> crsMatrix =
77  rcp_dynamic_cast<const Epetra_CrsMatrix>(Thyra::get_Epetra_Operator(*graphOp));
78  setGraph(Teuchos::rcpFromRef(crsMatrix->Graph()));
79 }
80 
81 void ProbingPreconditionerFactory::setGraph(const Teuchos::RCP<const Epetra_CrsGraph>& graph) {
82  prober->setGraph(graph);
83 }
84 
85 void ProbingPreconditionerFactory::setProberList(const Teuchos::ParameterList& list) {
86  prober->setList(list);
87 }
88 
89 } // end namespace Teko
90 
91 #endif
Implements the Epetra_Operator interface with a Thyra LinearOperator. This enables the use of absrtac...
InverseLinearOp buildInverse(const InverseFactory &factory, const LinearOp &A)
Build an inverse operator using a factory and a linear operator.