Teko Version of the Day
Loading...
Searching...
No Matches
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
12namespace Teko {
13
14using Teuchos::RCP;
15
17 const RCP<const BlockPreconditionerFactory> &FirstFactory,
18 const RCP<const BlockPreconditionerFactory> &SecondFactory)
19 : FirstFactory_(FirstFactory), SecondFactory_(SecondFactory) {}
20
21AddPreconditionerFactory::AddPreconditionerFactory() {}
22
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)
34LinearOp 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
54void 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
virtual Teuchos::RCP< Teko::PreconditionerState > buildPreconditionerState() const
Build the AddPrecondState object.
AddPreconditionerFactory(const Teuchos::RCP< const Teko::BlockPreconditionerFactory > &FirstFactory, const Teuchos::RCP< const Teko::BlockPreconditionerFactory > &SecondFactory)
Constructor.
virtual void initializeFromParameterList(const Teuchos::ParameterList &pl)
Initialize from a parameter list.
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).
Teuchos::RCP< const InverseLibrary > getInverseLibrary() const
Get the inverse library used by this preconditioner factory.