10 #ifndef MUELU_SUBBLOCKAFACTORY_DEF_HPP_
11 #define MUELU_SUBBLOCKAFACTORY_DEF_HPP_
16 #include <Xpetra_MapExtractor.hpp>
18 #include <Xpetra_StridedMapFactory.hpp>
25 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
31 validParamList->
set<
int>(
"block row", 0,
"Block row of subblock matrix A");
32 validParamList->
set<
int>(
"block col", 0,
"Block column of subblock matrix A");
34 validParamList->
set<std::string>(
"Range map: Striding info",
"{}",
"Striding information for range map");
35 validParamList->
set<
LocalOrdinal>(
"Range map: Strided block id", -1,
"Strided block id for range map");
36 validParamList->
set<std::string>(
"Domain map: Striding info",
"{}",
"Striding information for domain map");
37 validParamList->
set<
LocalOrdinal>(
"Domain map: Strided block id", -1,
"Strided block id for domain map");
39 return validParamList;
42 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
44 Input(currentLevel,
"A");
47 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
52 size_t row = Teuchos::as<size_t>(pL.
get<
int>(
"block row"));
53 size_t col = Teuchos::as<size_t>(pL.
get<
int>(
"block col"));
71 if (bOp != Teuchos::null) {
73 if (bOp->Rows() == 1 && bOp->Cols() == 1) {
75 Op = bOp->getCrsMatrix();
77 "SubBlockAFactory::Build: sub block A[" << row <<
"," << col <<
"] must be a single block CrsMatrixWrap object!");
82 GetOStream(
Statistics1) <<
"A(" << row <<
"," << col <<
") is a " << bOp->Rows() <<
"x" << bOp->Cols() <<
" block matrix" << std::endl;
83 GetOStream(
Statistics2) <<
"with altogether " << bOp->getGlobalNumRows() <<
"x" << bOp->getGlobalNumCols() <<
" rows and columns." << std::endl;
84 currentLevel.
Set(
"A", Op,
this);
101 "SubBlockAFactory::Build: sub block A[" << row <<
"," << col <<
"] is NOT a BlockedCrsMatrix, but also NOT a CrsMatrixWrap object. This cannot be.");
108 std::vector<size_t> rangeStridingInfo;
109 std::vector<size_t> domainStridingInfo;
112 bool bRangeUserSpecified = CheckForUserSpecifiedBlockInfo(
true, rangeStridingInfo, rangeStridedBlockId);
113 bool bDomainUserSpecified = CheckForUserSpecifiedBlockInfo(
false, domainStridingInfo, domainStridedBlockId);
115 "MueLu::SubBlockAFactory[" << row <<
"," << col <<
"]: the user has to specify either both domain and range map or none.");
121 bool thyraMode = rangeMapExtractor->getThyraMode();
123 RCP<const Map> rangeMap = rangeMapExtractor->getMap(row, thyraMode);
124 RCP<const Map> domainMap = domainMapExtractor->getMap(col, thyraMode);
127 if (bRangeUserSpecified)
128 stridedRangeMap =
rcp(
new StridedMap(rangeMap, rangeStridingInfo, rangeMap->getIndexBase(), rangeStridedBlockId, 0));
130 stridedRangeMap = rcp_dynamic_cast<
const StridedMap>(rangeMap);
132 if (bDomainUserSpecified)
133 stridedDomainMap =
rcp(
new StridedMap(domainMap, domainStridingInfo, domainMap->getIndexBase(), domainStridedBlockId, 0));
135 stridedDomainMap = rcp_dynamic_cast<
const StridedMap>(domainMap);
140 if (stridedRangeMap.
is_null()) {
145 std::vector<size_t> stridedData = stridedFullRangeMap->getStridingData();
146 if (stridedData.size() == 1 && row > 0) {
148 stridedRangeMap = StridedMapFactory::Build(rangeMap, stridedData, 0, stridedFullRangeMap->getOffset());
152 stridedRangeMap = StridedMapFactory::Build(rangeMap, stridedData, row, stridedFullRangeMap->getOffset());
156 if (stridedDomainMap.
is_null()) {
161 std::vector<size_t> stridedData = stridedFullDomainMap->getStridingData();
162 if (stridedData.size() == 1 && col > 0) {
164 stridedDomainMap = StridedMapFactory::Build(domainMap, stridedData, 0, stridedFullDomainMap->getOffset());
168 stridedDomainMap = StridedMapFactory::Build(domainMap, stridedData, col, stridedFullDomainMap->getOffset());
175 GetOStream(
Statistics1) <<
"A(" << row <<
"," << col <<
") is a single block and has strided maps:"
176 <<
"\n range map fixed block size = " << stridedRangeMap->getFixedBlockSize() <<
", strided block id = " << stridedRangeMap->getStridedBlockId()
177 <<
"\n domain map fixed block size = " << stridedDomainMap->getFixedBlockSize() <<
", strided block id = " << stridedDomainMap->getStridedBlockId() << std::endl;
178 GetOStream(
Statistics2) <<
"A(" << row <<
"," << col <<
") has " << Op->getGlobalNumRows() <<
"x" << Op->getGlobalNumCols() <<
" rows and columns." << std::endl;
181 if (Op->IsView(
"stridedMaps") ==
true)
182 Op->RemoveView(
"stridedMaps");
183 Op->CreateView(
"stridedMaps", stridedRangeMap, stridedDomainMap);
187 currentLevel.
Set(
"A", Op,
this);
190 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
204 str = std::string(
"Range map: Striding info");
206 str = std::string(
"Domain map: Striding info");
209 std::string strStridingInfo = pL.
get<std::string>(str);
210 if (strStridingInfo.empty() ==
false) {
211 Array<size_t> arrayVal = Teuchos::fromStringToArray<size_t>(strStridingInfo);
212 stridingInfo = Teuchos::createVector(arrayVal);
216 if (stridingInfo.size() > 0)
return true;
Exception indicating invalid cast attempted.
MueLu::DefaultLocalOrdinal LocalOrdinal
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access). Usage: Level->Get< RCP<Matrix> >("A", factory) if factory == NULL => use default factory.
RCP< const ParameterList > GetValidParameterList() const override
Input.
T & get(const std::string &name, T def_value)
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void Build(Level ¤tLevel) const override
Build an object with this factory.
bool CheckForUserSpecifiedBlockInfo(bool bRange, std::vector< size_t > &stridingInfo, LocalOrdinal &stridedBlockId) const
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Print even more statistics.
bool isParameter(const std::string &name) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
static const RCP< const NoFactory > getRCP()
Static Get() functions.
void Set(const std::string &ename, const T &entry, const FactoryBase *factory=NoFactory::get())
Exception throws to report errors in the internal logical of the program.
void DeclareInput(Level ¤tLevel) const override
Specifies the data that this class needs, and the factories that generate that data.