| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// MueLu: A package for multigrid based preconditioning |
| 4 |
// |
| 5 |
// Copyright 2012 NTESS and the MueLu contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#ifndef MUELU_BLOCKEDPFACTORY_DECL_HPP_ |
| 11 |
#define MUELU_BLOCKEDPFACTORY_DECL_HPP_ |
| 12 |
|
| 13 |
#include <set> |
| 14 |
#include <Xpetra_MapExtractorFactory_fwd.hpp> |
| 15 |
#include <Xpetra_Matrix_fwd.hpp> |
| 16 |
|
| 17 |
#include "MueLu_ConfigDefs.hpp" |
| 18 |
#include "MueLu_PFactory.hpp" |
| 19 |
#include "MueLu_TentativePFactory_fwd.hpp" |
| 20 |
#include "MueLu_FactoryManagerBase_fwd.hpp" |
| 21 |
|
| 22 |
namespace MueLu { |
| 23 |
|
| 24 |
/*! |
| 25 |
@class BlockedPFactory class. |
| 26 |
@brief Factory for building blocked, segregated prolongation operators. |
| 27 |
|
| 28 |
Factory for building blocked, segregated prolongation operators of the form |
| 29 |
\f$ P=\\operatorname{diag}(P_{11},P_{22},\ldots)\f$, where \f$ P_{ii}\f$ are prolongation operators |
| 30 |
for the corresponding subblocks \f$A_{ii}\f$ in the blocked operator \f$ A \f$. |
| 31 |
|
| 32 |
@param RCP<FactoryBase> AFact = Teuchos::null: factory for generating blocked operator \f$ A\f$. |
| 33 |
|
| 34 |
The blocked operator \f$ A \f$ is needed for accessing the underlaying blocked maps (MapExtractors). |
| 35 |
Use the AddFactoryManager function to define block rows in the blocked operator. For each block row you have to define |
| 36 |
a special factory manager that handles the prolongation and restriction operator for the corresponding blocks. The |
| 37 |
SubBlockAFactory class provides a factory interface for accessing specific blocks in the blocked operator \f$ A \f$. |
| 38 |
|
| 39 |
\code{.cpp} |
| 40 |
// define SubBlockAFactory objects for accessing the diagonal blocks in the blocked operator A |
| 41 |
RCP<SubBlockAFactory> A11Fact = Teuchos::rcp(new SubBlockAFactory(MueLu::NoFactory::getRCP(), 0, 0)); |
| 42 |
RCP<SubBlockAFactory> A22Fact = Teuchos::rcp(new SubBlockAFactory(MueLu::NoFactory::getRCP(), 1, 1)); |
| 43 |
|
| 44 |
// define transfer operators for first block row |
| 45 |
RCP<TentativePFactory> P11Fact = rcp(new TentativePFactory()); |
| 46 |
RCP<TransPFactory> R11Fact = rcp(new TransPFactory(P11Fact)); |
| 47 |
|
| 48 |
// define transfer operators for second block row |
| 49 |
RCP<TentativePFactory> P22TentFact = rcp(new TentativePFactory()); |
| 50 |
RCP<PgPFactory> P22Fact = rcp(new PgPFactory(P22TentFact)); |
| 51 |
RCP<GenericRFactory> R22Fact = rcp(new GenericRFactory(P22Fact)); |
| 52 |
|
| 53 |
// setup facatory managers for first and second block row |
| 54 |
RCP<FactoryManager> M11 = rcp(new FactoryManager()); |
| 55 |
M11->SetFactory("A", A11Fact); |
| 56 |
M11->SetFactory("P", P11Fact); |
| 57 |
M11->SetFactory("R", R11Fact); |
| 58 |
|
| 59 |
RCP<FactoryManager> M22 = rcp(new FactoryManager()); |
| 60 |
M22->SetFactory("A", A22Fact); |
| 61 |
M22->SetFactory("P", P22Fact); |
| 62 |
M22->SetFactory("R", R22Fact); |
| 63 |
|
| 64 |
// setup blocked transfer operator |
| 65 |
// use Teuchos::null as AFactory -> standard "A" variable (in this case the blocked operator A) |
| 66 |
RCP<BlockedPFactory> PFact = rcp(new BlockedPFactory()); |
| 67 |
PFact->SetFactory("A",Teuchos::null); // not necessary (use blocked operator A) |
| 68 |
PFact->AddFactoryManager(M11); // add factory manager for first block row |
| 69 |
PFact->AddFactoryManager(M22); // add factory manager for second block row |
| 70 |
|
| 71 |
// define restriction operator |
| 72 |
// Note: always use GenericRFactory here. |
| 73 |
// The simple TransPFactory class cannot handle blocked operators, yet. |
| 74 |
RCP<GenericRFactory> RFact = rcp(new GenericRFactory(PFact)); |
| 75 |
|
| 76 |
// RAP factory |
| 77 |
RCP<RAPFactory> AcFact = rcp(new RAPFactory(PFact, RFact)); |
| 78 |
\endcode |
| 79 |
|
| 80 |
*/ |
| 81 |
|
| 82 |
template <class Scalar = DefaultScalar, |
| 83 |
class LocalOrdinal = DefaultLocalOrdinal, |
| 84 |
class GlobalOrdinal = DefaultGlobalOrdinal, |
| 85 |
class Node = DefaultNode> |
| 86 |
class BlockedPFactory : public PFactory { |
| 87 |
#undef MUELU_BLOCKEDPFACTORY_SHORT |
| 88 |
#include "MueLu_UseShortNames.hpp" |
| 89 |
public: |
| 90 |
//! @name Constructors/Destructors. |
| 91 |
//@{ |
| 92 |
|
| 93 |
/*! @brief Constructor. |
| 94 |
User can supply a factory for generating the tentative prolongator. |
| 95 |
*/ |
| 96 |
BlockedPFactory(/*RCP<FactoryBase> AFact = Teuchos::null*/) |
| 97 |
: diagonalView_("current") {} |
| 98 |
|
| 99 |
//! Destructor. |
| 100 |
virtual ~BlockedPFactory() {} |
| 101 |
|
| 102 |
RCP<const ParameterList> GetValidParameterList() const; |
| 103 |
|
| 104 |
//@} |
| 105 |
|
| 106 |
//! @name Set methods. |
| 107 |
//@{ |
| 108 |
|
| 109 |
//! Change view of diagonal. |
| 110 |
void SetDiagonalView(std::string const &diagView) { diagonalView_ = diagView; } |
| 111 |
|
| 112 |
//! Add a factory manager |
| 113 |
void AddFactoryManager(RCP<const FactoryManagerBase> FactManager) { FactManager_.push_back(FactManager); } |
| 114 |
|
| 115 |
//@} |
| 116 |
|
| 117 |
//! @name Get methods. |
| 118 |
//@{ |
| 119 |
|
| 120 |
//! Returns current view of diagonal. |
| 121 |
std::string GetDiagonalView() { return diagonalView_; } |
| 122 |
|
| 123 |
//@} |
| 124 |
|
| 125 |
//! Input |
| 126 |
//@{ |
| 127 |
|
| 128 |
void DeclareInput(Level &fineLevel, Level &coarseLevel) const; |
| 129 |
//@} |
| 130 |
|
| 131 |
//! @name Build methods. |
| 132 |
//@{ |
| 133 |
|
| 134 |
/*! |
| 135 |
@brief Build method. |
| 136 |
|
| 137 |
Build segregated blocked prolongator by assembly from prolongators of each subblock in A |
| 138 |
and return it in \c coarseLevel . |
| 139 |
*/ |
| 140 |
void Build(Level &fineLevel, Level &coarseLevel) const; |
| 141 |
|
| 142 |
void BuildP(Level &fineLevel, Level &coarseLevel) const; |
| 143 |
|
| 144 |
//@} |
| 145 |
|
| 146 |
private: |
| 147 |
bool areGidsUnique(const std::vector<GO> &X) const { |
| 148 |
std::set<GO> Y(X.begin(), X.end()); |
| 149 |
return X.size() == Y.size(); |
| 150 |
} |
| 151 |
|
| 152 |
//! Input factories |
| 153 |
std::vector<Teuchos::RCP<const FactoryManagerBase> > FactManager_; |
| 154 |
|
| 155 |
//! Factory parameters |
| 156 |
std::string diagonalView_; |
| 157 |
}; |
| 158 |
|
| 159 |
} // namespace MueLu |
| 160 |
|
| 161 |
#define MUELU_BLOCKEDPFACTORY_SHORT |
| 162 |
#endif /* MUELU_BLOCKEDPFACTORY_DECL_HPP_ */ |