Teko  Version of the Day
 All Classes Files Functions Variables Pages
Teko_ProbingPreconditionerFactory.cpp
1 /*
2 // @HEADER
3 //
4 // ***********************************************************************
5 //
6 // Teko: A package for block and physics based preconditioning
7 // Copyright 2010 Sandia Corporation
8 //
9 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Eric C. Cyr (eccyr@sandia.gov)
40 //
41 // ***********************************************************************
42 //
43 // @HEADER
44 
45 */
46 
47 #include "Teko_ProbingPreconditionerFactory.hpp"
48 
49 #ifdef Teko_ENABLE_Isorropia
50 
51 #include "Teko_EpetraOperatorWrapper.hpp"
52 
53 #include "Thyra_get_Epetra_Operator.hpp"
54 #include "Thyra_EpetraLinearOp.hpp"
55 #include "Epetra_CrsMatrix.h"
56 
57 using Teuchos::rcp;
58 using Teuchos::RCP;
59 using Teuchos::rcp_dynamic_cast;
60 using Teuchos::rcpFromRef;
61 
62 namespace Teko {
63 
64 /*****************************************************/
65 
66 ProbingPreconditionerFactory::ProbingPreconditionerFactory() {
67  prober = rcp(new Isorropia::Epetra::Prober);
68 }
69 
70 LinearOp ProbingPreconditionerFactory::buildPreconditionerOperator(
71  LinearOp& lo, PreconditionerState& state) const {
72  // make an epetra operator to be probed
73  RCP<Epetra_Operator> epetraLo = rcp(new Teko::Epetra::EpetraOperatorWrapper(lo));
74 
75  // build color scheme
76  prober->color();
77 
78  // probe operator: take me to your leader
79  RCP<Epetra_CrsMatrix> retOp = prober->probe(*epetraLo);
80  Teko::LinearOp probedOp = Thyra::epetraLinearOp(retOp);
81 
82  return Teko::buildInverse(*invFactory_, probedOp);
83 }
84 
85 void ProbingPreconditionerFactory::initializeFromParameterList(const Teuchos::ParameterList& pl) {
86  RCP<const InverseLibrary> invLib = getInverseLibrary();
87 
88  const std::string inverse_type = "Inverse Type";
89  const std::string probing_graph_operator = "Probing Graph Operator";
90  const std::string probing_graph = "Probing Graph";
91  const std::string user_graph = "User Will Set Probing Graph";
92 
93  // get string specifying default inverse
94  std::string invStr = "Amesos";
95  if (pl.isParameter(inverse_type)) invStr = pl.get<std::string>(inverse_type);
96 
97  if (pl.isParameter(probing_graph_operator))
98  setGraphOperator(pl.get<Teko::LinearOp>(probing_graph_operator));
99  else if (pl.isParameter(probing_graph))
100  setGraph(pl.get<RCP<const Epetra_CrsGraph> >(probing_graph));
101  else if (pl.isParameter(user_graph) && pl.get<bool>("User Will Set Probing Graph")) {
102  // noop
103  } else {
104  Teuchos::RCP<Teko::RequestHandler> rh = getRequestHandler();
105  rh->preRequest<RCP<const Epetra_CrsGraph> >(Teko::RequestMesg("Probing Graph"));
106  setGraph(rh->request<RCP<const Epetra_CrsGraph> >(Teko::RequestMesg("Probing Graph")));
107  }
108 
109  setInverseFactory(invLib->getInverseFactory(invStr));
110 }
111 
112 void ProbingPreconditionerFactory::setGraphOperator(const Teko::LinearOp& graphOp) {
113  RCP<const Epetra_CrsMatrix> crsMatrix =
114  rcp_dynamic_cast<const Epetra_CrsMatrix>(Thyra::get_Epetra_Operator(*graphOp));
115  setGraph(Teuchos::rcpFromRef(crsMatrix->Graph()));
116 }
117 
118 void ProbingPreconditionerFactory::setGraph(const Teuchos::RCP<const Epetra_CrsGraph>& graph) {
119  prober->setGraph(graph);
120 }
121 
122 void ProbingPreconditionerFactory::setProberList(const Teuchos::ParameterList& list) {
123  prober->setList(list);
124 }
125 
126 } // end namespace Teko
127 
128 #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.