53 #ifndef MUELU_SUBBLOCKAFACTORY_DEF_HPP_ 54 #define MUELU_SUBBLOCKAFACTORY_DEF_HPP_ 59 #include <Xpetra_BlockedCrsMatrix.hpp> 60 #include <Xpetra_CrsMatrix.hpp> 61 #include <Xpetra_CrsMatrixWrap.hpp> 62 #include <Xpetra_MapExtractor.hpp> 63 #include <Xpetra_Matrix.hpp> 64 #include <Xpetra_StridedMapFactory.hpp> 71 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
73 RCP<ParameterList> validParamList = rcp(
new ParameterList());
76 validParamList->set<
int > (
"block row", 0,
"Block row of subblock matrix A");
77 validParamList->set<
int > (
"block col", 0,
"Block column of subblock matrix A");
79 return validParamList;
82 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
84 Input(currentLevel,
"A");
87 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
89 const ParameterList& pL = GetParameterList();
90 size_t row = Teuchos::as<size_t>(pL.get<
int>(
"block row"));
91 size_t col = Teuchos::as<size_t>(pL.get<
int>(
"block col"));
93 RCP<Matrix> Ain = Get<RCP<Matrix> >(currentLevel,
"A");
94 RCP<BlockedCrsMatrix> A = rcp_dynamic_cast<BlockedCrsMatrix>(Ain);
96 TEUCHOS_TEST_FOR_EXCEPTION(A.is_null(),
Exceptions::BadCast,
"Input matrix A is not a BlockedCrsMatrix.");
97 TEUCHOS_TEST_FOR_EXCEPTION(row > A->Rows(),
Exceptions::RuntimeError,
"row [" << row <<
"] > A.Rows() [" << A->Rows() <<
"].");
98 TEUCHOS_TEST_FOR_EXCEPTION(col > A->Cols(),
Exceptions::RuntimeError,
"col [" << col <<
"] > A.Cols() [" << A->Cols() <<
"].");
100 RCP<CrsMatrixWrap> Op = Teuchos::rcp(
new CrsMatrixWrap(A->getMatrix(row, col)));
105 RCP<const MapExtractor> rangeMapExtractor = A->getRangeMapExtractor();
106 RCP<const MapExtractor> domainMapExtractor = A->getDomainMapExtractor();
108 RCP<const Map> rangeMap = rangeMapExtractor ->getMap(row);
109 RCP<const Map> domainMap = domainMapExtractor->getMap(col);
111 RCP<const StridedMap> srangeMap = rcp_dynamic_cast<
const StridedMap>(rangeMap);
112 RCP<const StridedMap> sdomainMap = rcp_dynamic_cast<
const StridedMap>(domainMap);
114 if (srangeMap.is_null()) {
115 RCP<const Map> fullRangeMap = rangeMapExtractor->getFullMap();
116 RCP<const StridedMap> sFullRangeMap = rcp_dynamic_cast<
const StridedMap>(fullRangeMap);
117 TEUCHOS_TEST_FOR_EXCEPTION(sFullRangeMap.is_null(),
Exceptions::BadCast,
"Full rangeMap is not a strided map.");
119 std::vector<size_t> stridedData = sFullRangeMap->getStridingData();
120 if (stridedData.size() == 1 && row > 0) {
122 srangeMap = StridedMapFactory::Build(rangeMap, stridedData, 0, sFullRangeMap->getOffset());
126 srangeMap = StridedMapFactory::Build(rangeMap, stridedData, row, sFullRangeMap->getOffset());
130 if (sdomainMap.is_null()) {
131 RCP<const Map> fullDomainMap = domainMapExtractor->getFullMap();
132 RCP<const StridedMap> sFullDomainMap = rcp_dynamic_cast<
const StridedMap>(fullDomainMap);
133 TEUCHOS_TEST_FOR_EXCEPTION(sFullDomainMap.is_null(),
Exceptions::BadCast,
"Full domainMap is not a strided map");
135 std::vector<size_t> stridedData = sFullDomainMap->getStridingData();
136 if (stridedData.size() == 1 && col > 0) {
138 sdomainMap = StridedMapFactory::Build(domainMap, stridedData, 0, sFullDomainMap->getOffset());
142 sdomainMap = StridedMapFactory::Build(domainMap, stridedData, col, sFullDomainMap->getOffset());
146 TEUCHOS_TEST_FOR_EXCEPTION(srangeMap.is_null(),
Exceptions::BadCast,
"rangeMap " << row <<
" is not a strided map.");
147 TEUCHOS_TEST_FOR_EXCEPTION(sdomainMap.is_null(),
Exceptions::BadCast,
"domainMap " << col <<
" is not a strided map.");
149 GetOStream(
Statistics1) <<
"A(" << row <<
"," << col <<
") has strided maps:" 150 <<
"\n range map fixed block size = " << srangeMap ->getFixedBlockSize() <<
", strided block id = " << srangeMap ->getStridedBlockId()
151 <<
"\n domain map fixed block size = " << sdomainMap->getFixedBlockSize() <<
", strided block id = " << sdomainMap->getStridedBlockId() << std::endl;
153 if (Op->IsView(
"stridedMaps") ==
true)
154 Op->RemoveView(
"stridedMaps");
155 Op->CreateView(
"stridedMaps", srangeMap, sdomainMap);
157 TEUCHOS_TEST_FOR_EXCEPTION(Op->IsView(
"stridedMaps") ==
false,
Exceptions::RuntimeError,
"Failed to set \"stridedMaps\" view.");
161 currentLevel.Set(
"A", rcp_dynamic_cast<Matrix>(Op),
this);
Exception indicating invalid cast attempted.
Namespace for MueLu classes and methods.
void DeclareInput(Level ¤tLevel) const
Specifies the data that this class needs, and the factories that generate that data.
void Build(Level ¤tLevel) const
Build an object with this factory.
Class that holds all level-specific information.
RCP< const ParameterList > GetValidParameterList() const
Input.
Exception throws to report errors in the internal logical of the program.
static const RCP< const NoFactory > getRCP()
Static Get() functions.