Teko  Version of the Day
 All Classes Files Functions Variables Pages
Teko_AddPreconditionerFactory.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_AddPreconditionerFactory.hpp"
11 
12 namespace Teko {
13 
14 using Teuchos::RCP;
15 
16 AddPreconditionerFactory::AddPreconditionerFactory(
17  const RCP<const BlockPreconditionerFactory> &FirstFactory,
18  const RCP<const BlockPreconditionerFactory> &SecondFactory)
19  : FirstFactory_(FirstFactory), SecondFactory_(SecondFactory) {}
20 
21 AddPreconditionerFactory::AddPreconditionerFactory() {}
22 
24 RCP<PreconditionerState> AddPreconditionerFactory::buildPreconditionerState() const {
25  AddPrecondState *mystate = new AddPrecondState();
26  mystate->StateOne_ = Teuchos::rcp_dynamic_cast<BlockPreconditionerState>(
27  FirstFactory_->buildPreconditionerState());
28  mystate->StateTwo_ = Teuchos::rcp_dynamic_cast<BlockPreconditionerState>(
29  SecondFactory_->buildPreconditionerState());
30  return rcp(mystate);
31 }
32 
33 // Use the factory to build the preconditioner (this is where the work goes)
34 LinearOp AddPreconditionerFactory ::buildPreconditionerOperator(
35  BlockedLinearOp &blockOp, BlockPreconditionerState &state) const {
36  // The main tricky thing here is that we have to take the 'state' object
37  // associated with AddPreconditionerFactory(), pull out the states for
38  // the individual preconditioners, and pass these on to
39  // buildPreconditionerOperator() for each subpreconditioner.
40 
41  AddPrecondState *MyState = dynamic_cast<AddPrecondState *>(&state);
42  TEUCHOS_ASSERT(MyState != 0);
43 
44  LinearOp M1 = FirstFactory_->buildPreconditionerOperator(blockOp, *MyState->StateOne_);
45  LinearOp M2 = SecondFactory_->buildPreconditionerOperator(blockOp, *MyState->StateTwo_);
46 
47  LinearOp invA = add(M1, M2);
48 
49  // return fully constructed preconditioner
50  return invA;
51 }
52 
54 void AddPreconditionerFactory::initializeFromParameterList(const Teuchos::ParameterList &pl) {
55  RCP<const InverseLibrary> invLib = getInverseLibrary();
56 
57  // get string specifying inverse
58  std::string aStr = "", bStr = "";
59 
60  // "parse" the parameter list
61  aStr = pl.get<std::string>("Preconditioner A");
62  bStr = pl.get<std::string>("Preconditioner B");
63 
64  RCP<const Teuchos::ParameterList> aSettings = invLib->getParameterList(aStr);
65  RCP<const Teuchos::ParameterList> bSettings = invLib->getParameterList(bStr);
66 
67  // build preconditioner from the parameters
68  std::string aType = aSettings->get<std::string>("Preconditioner Type");
69  RCP<Teko::PreconditionerFactory> precA = Teko::PreconditionerFactory::buildPreconditionerFactory(
70  aType, aSettings->sublist("Preconditioner Settings"), invLib);
71 
72  // build preconditioner from the parameters
73  std::string bType = bSettings->get<std::string>("Preconditioner Type");
74  RCP<Teko::PreconditionerFactory> precB = Teko::PreconditionerFactory::buildPreconditionerFactory(
75  bType, bSettings->sublist("Preconditioner Settings"), invLib);
76 
77  // set preconditioners
78  FirstFactory_ = Teuchos::rcp_dynamic_cast<const Teko::BlockPreconditionerFactory>(precA);
79  SecondFactory_ = Teuchos::rcp_dynamic_cast<const Teko::BlockPreconditionerFactory>(precB);
80 }
81 
82 } // end namespace Teko
Abstract class which block preconditioner factories in Teko should be based on.
An implementation of a state object for block preconditioners.
static Teuchos::RCP< PreconditionerFactory > buildPreconditionerFactory(const std::string &name, const Teuchos::ParameterList &settings, const Teuchos::RCP< const InverseLibrary > &invLib=Teuchos::null)
Builder function for creating preconditioner factories (yes this is a factory factory).