| 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_SUBBLOCKAFACTORY_DECL_HPP_ |
| 11 |
#define MUELU_SUBBLOCKAFACTORY_DECL_HPP_ |
| 12 |
|
| 13 |
#include <Xpetra_Map_fwd.hpp> |
| 14 |
#include <Xpetra_MapExtractor_fwd.hpp> |
| 15 |
#include <Xpetra_StridedMap_fwd.hpp> |
| 16 |
#include <Xpetra_StridedMapFactory_fwd.hpp> |
| 17 |
|
| 18 |
#include "MueLu_ConfigDefs.hpp" |
| 19 |
#include "MueLu_SingleLevelFactoryBase.hpp" |
| 20 |
#include "MueLu_SubBlockAFactory_fwd.hpp" |
| 21 |
|
| 22 |
namespace MueLu { |
| 23 |
|
| 24 |
/*! |
| 25 |
@class SubBlockAFactory class. |
| 26 |
@brief Factory for building a thresholded operator. |
| 27 |
|
| 28 |
This is a very simple class to access a single matrix block in a blocked operator A. |
| 29 |
|
| 30 |
Example |
| 31 |
\code{.cpp} |
| 32 |
Teuchos::RCP<Xpetra::BlockedCrsMatrix<Scalar,LO,GO,Node> > bOp = Teuchos::rcp(new Xpetra::BlockedCrsMatrix<Scalar,LO,GO>(mapExtractor,mapExtractor,10)); |
| 33 |
// ... let bOp be a 2x2 blocked operator ... |
| 34 |
bOp->fillComplete(); |
| 35 |
|
| 36 |
// define factory for accessing block (0,0) in blocked operator A (assuming that the blocked operator is stored in Level class with NoFactory as generating factory) |
| 37 |
RCP<SubBlockAFactory> A11Fact = Teuchos::rcp(new SubBlockAFactory()); |
| 38 |
A11Fact->SetFactory("A", MueLu::NoFactory::getRCP()); |
| 39 |
A11Fact->SetParameter("block row", 0); |
| 40 |
A11Fact->SetParameter("block col", 0); |
| 41 |
|
| 42 |
// define factory for accessing block (1,1) in blocked operator A |
| 43 |
RCP<SubBlockAFactory> A22Fact = Teuchos::rcp(new SubBlockAFactory()); |
| 44 |
A22Fact->SetFactory("A", MueLu::NoFactory::getRCP()); |
| 45 |
A22Fact->SetParameter("block row", 1); |
| 46 |
A22Fact->SetParameter("block col", 1); |
| 47 |
|
| 48 |
RCP<Matrix> A11 = level.Get<RCP<Matrix> >("A", A11Fact); // extract (0,0) block from blocked operator A |
| 49 |
RCP<Matrix> A22 = level.Get<RCP<Matrix> >("A", A22Fact); // extract (1,1) block from blocked operator A |
| 50 |
\endcode |
| 51 |
*/ |
| 52 |
|
| 53 |
template <class Scalar = DefaultScalar, |
| 54 |
class LocalOrdinal = DefaultLocalOrdinal, |
| 55 |
class GlobalOrdinal = DefaultGlobalOrdinal, |
| 56 |
class Node = DefaultNode> |
| 57 |
class SubBlockAFactory : public SingleLevelFactoryBase { |
| 58 |
#undef MUELU_SUBBLOCKAFACTORY_SHORT |
| 59 |
#include "MueLu_UseShortNames.hpp" |
| 60 |
|
| 61 |
public: |
| 62 |
//! @name Constructors/Destructors. |
| 63 |
//@{ |
| 64 |
|
| 65 |
//! Constructor. |
| 66 |
SubBlockAFactory() = default; |
| 67 |
|
| 68 |
//! Destructor. |
| 69 |
virtual ~SubBlockAFactory() = default; |
| 70 |
//@} |
| 71 |
|
| 72 |
//! Input |
| 73 |
//@{ |
| 74 |
|
| 75 |
RCP<const ParameterList> GetValidParameterList() const override; |
| 76 |
|
| 77 |
void DeclareInput(Level& currentLevel) const override; |
| 78 |
|
| 79 |
//@} |
| 80 |
|
| 81 |
//@{ |
| 82 |
//! @name Build methods. |
| 83 |
|
| 84 |
/*! @brief Build an object with this factory. |
| 85 |
* |
| 86 |
* Extract sub block matrix from a given blocked crs operator. |
| 87 |
* Strided or block information is extracted in the following way: |
| 88 |
* 1) first check whether the corresponding sub maps are strided |
| 89 |
* If yes, use the fixed block size and strided block id |
| 90 |
* 2) If no, get the full map of the map extractors. |
| 91 |
* Check whether the full map is strided. |
| 92 |
* If yes, use the strided information of the full map and build |
| 93 |
* partial (strided) maps with it |
| 94 |
* If no, throw an exception |
| 95 |
* |
| 96 |
* For blocked operators with block maps one should use the striding |
| 97 |
* information from the sub maps. For strided operators, the striding |
| 98 |
* information of the full map is the best choice. |
| 99 |
*/ |
| 100 |
void Build(Level& currentLevel) const override; |
| 101 |
|
| 102 |
//@} |
| 103 |
|
| 104 |
private: |
| 105 |
bool CheckForUserSpecifiedBlockInfo(bool bRange, std::vector<size_t>& stridingInfo, LocalOrdinal& stridedBlockId) const; |
| 106 |
|
| 107 |
}; // class SubBlockAFactory |
| 108 |
|
| 109 |
} // namespace MueLu |
| 110 |
|
| 111 |
#define MUELU_SUBBLOCKAFACTORY_SHORT |
| 112 |
#endif /* MUELU_SUBBLOCKAFACTORY_DECL_HPP_ */ |