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_dynamic_cast;
59 using Teuchos::rcpFromRef;
60 using Teuchos::RCP;
61 
62 namespace Teko {
63 
64 /*****************************************************/
65 
66 
67 ProbingPreconditionerFactory::ProbingPreconditionerFactory()
68 {
69  prober = rcp(new Isorropia::Epetra::Prober);
70 }
71 
72 LinearOp ProbingPreconditionerFactory::buildPreconditionerOperator(LinearOp & lo,PreconditionerState & state) const
73 {
74  // make an epetra operator to be probed
75  RCP<Epetra_Operator> epetraLo = rcp(new Teko::Epetra::EpetraOperatorWrapper(lo));
76 
77  // build color scheme
78  prober->color();
79 
80  // probe operator: take me to your leader
81  RCP<Epetra_CrsMatrix> retOp = prober->probe(*epetraLo);
82  Teko::LinearOp probedOp = Thyra::epetraLinearOp(retOp);
83 
84  return Teko::buildInverse(*invFactory_,probedOp);
85 }
86 
87 void ProbingPreconditionerFactory::initializeFromParameterList(const Teuchos::ParameterList & pl)
88 {
89  RCP<const InverseLibrary> invLib = getInverseLibrary();
90 
91  const std::string inverse_type = "Inverse Type";
92  const std::string probing_graph_operator = "Probing Graph Operator";
93  const std::string probing_graph = "Probing Graph";
94  const std::string user_graph = "User Will Set Probing Graph";
95 
96  // get string specifying default inverse
97  std::string invStr ="Amesos";
98  if(pl.isParameter(inverse_type))
99  invStr = pl.get<std::string>(inverse_type);
100 
101  if(pl.isParameter(probing_graph_operator))
102  setGraphOperator(pl.get<Teko::LinearOp>(probing_graph_operator));
103  else if(pl.isParameter(probing_graph))
104  setGraph(pl.get<RCP<const Epetra_CrsGraph> >(probing_graph));
105  else if(pl.isParameter(user_graph) && pl.get<bool>("User Will Set Probing Graph")){
106  //noop
107  }
108  else {
109  Teuchos::RCP<Teko::RequestHandler> rh = getRequestHandler();
110  rh->preRequest<RCP<const Epetra_CrsGraph> >(Teko::RequestMesg("Probing Graph"));
111  setGraph(rh->request<RCP<const Epetra_CrsGraph> >(Teko::RequestMesg("Probing Graph")));
112  }
113 
114  setInverseFactory(invLib->getInverseFactory(invStr));
115 }
116 
117 void ProbingPreconditionerFactory::setGraphOperator(const Teko::LinearOp & graphOp)
118 {
119  RCP<const Epetra_CrsMatrix> crsMatrix = rcp_dynamic_cast<const Epetra_CrsMatrix>(Thyra::get_Epetra_Operator(*graphOp));
120  setGraph(Teuchos::rcpFromRef(crsMatrix->Graph()));
121 }
122 
123 void ProbingPreconditionerFactory::setGraph(const Teuchos::RCP<const Epetra_CrsGraph> & graph)
124 {
125  prober->setGraph(graph);
126 }
127 
128 void ProbingPreconditionerFactory::setProberList(const Teuchos::ParameterList & list)
129 {
130  prober->setList(list);
131 }
132 
133 } // end namespace Teko
134 
135 #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.