10 #ifndef MUELU_BLOCKEDPFACTORY_DEF_HPP_
11 #define MUELU_BLOCKEDPFACTORY_DEF_HPP_
13 #include <Xpetra_MultiVectorFactory.hpp>
17 #include <Xpetra_CrsMatrixWrap.hpp>
20 #include <Xpetra_Map.hpp>
21 #include <Xpetra_MapFactory.hpp>
22 #include <Xpetra_MapExtractor.hpp>
27 #include "MueLu_FactoryManager.hpp"
29 #include "MueLu_HierarchyUtils.hpp"
33 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
38 validParamList->
set<
bool>(
"backwards",
false,
"Forward/backward order");
40 return validParamList;
43 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
45 Input(fineLevel,
"A");
48 const bool backwards = pL.
get<
bool>(
"backwards");
50 const int numFactManagers = FactManager_.size();
51 for (
int k = 0; k < numFactManagers; k++) {
52 int i = (backwards ? numFactManagers - 1 - k : k);
58 if (!restrictionMode_)
65 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
68 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
72 RCP<Matrix> Ain = Get<RCP<Matrix> >(fineLevel,
"A");
77 const int numFactManagers = FactManager_.size();
81 "Number of block rows [" << A->Rows() <<
"] does not match the number of SubFactorManagers [" << numFactManagers <<
"]");
83 "Number of block cols [" << A->Cols() <<
"] does not match the number of SubFactorManagers [" << numFactManagers <<
"]");
86 std::vector<RCP<Matrix> > subBlockP(numFactManagers);
87 std::vector<RCP<const Map> > subBlockPRangeMaps(numFactManagers);
88 std::vector<RCP<const Map> > subBlockPDomainMaps(numFactManagers);
90 std::vector<GO> fullRangeMapVector;
91 std::vector<GO> fullDomainMapVector;
97 const bool backwards = pL.
get<
bool>(
"backwards");
102 for (
int k = 0; k < numFactManagers; k++) {
103 int i = (backwards ? numFactManagers - 1 - k : k);
104 if (restrictionMode_)
105 GetOStream(
Runtime1) <<
"Generating R for block " << k <<
"/" << numFactManagers << std::endl;
107 GetOStream(
Runtime1) <<
"Generating P for block " << k <<
"/" << numFactManagers << std::endl;
114 if (!restrictionMode_)
121 "subBlock P operator [" << i <<
"] has no strided map information.");
126 RCP<const StridedMap> strPartialMap = Teuchos::rcp_dynamic_cast<
const StridedMap>(subBlockP[i]->getRowMap(
"stridedMaps"));
127 std::vector<size_t> stridedRgData = strPartialMap->getStridingData();
128 subBlockPRangeMaps[i] = StridedMapFactory::Build(
129 subBlockP[i]->getRangeMap(),
131 strPartialMap->getStridedBlockId(),
132 strPartialMap->getOffset());
137 fullRangeMapVector.insert(fullRangeMapVector.end(), nodeRangeMap.begin(), nodeRangeMap.end());
140 RCP<const StridedMap> strPartialMap2 = Teuchos::rcp_dynamic_cast<
const StridedMap>(subBlockP[i]->getColMap(
"stridedMaps"));
141 std::vector<size_t> stridedRgData2 = strPartialMap2->getStridingData();
142 subBlockPDomainMaps[i] = StridedMapFactory::Build(
143 subBlockP[i]->getDomainMap(),
145 strPartialMap2->getStridedBlockId(),
146 strPartialMap2->getOffset());
151 fullDomainMapVector.insert(fullDomainMapVector.end(), nodeDomainMap.begin(), nodeDomainMap.end());
161 bool bDoSortRangeGIDs = rangeAMapExtractor->getThyraMode() ?
false :
true;
162 bool bDoSortDomainGIDs = domainAMapExtractor->getThyraMode() ?
false :
true;
164 if (bDoSortRangeGIDs) {
165 sort(fullRangeMapVector.begin(), fullRangeMapVector.end());
166 fullRangeMapVector.erase(std::unique(fullRangeMapVector.begin(), fullRangeMapVector.end()), fullRangeMapVector.end());
168 if (bDoSortDomainGIDs) {
169 sort(fullDomainMapVector.begin(), fullDomainMapVector.end());
170 fullDomainMapVector.erase(std::unique(fullDomainMapVector.begin(), fullDomainMapVector.end()), fullDomainMapVector.end());
174 GO rangeIndexBase = 0;
175 GO domainIndexBase = 0;
176 if (!restrictionMode_) {
178 rangeIndexBase = A->getRangeMap()->getIndexBase();
179 domainIndexBase = A->getDomainMap()->getIndexBase();
183 rangeIndexBase = A->getDomainMap()->getIndexBase();
184 domainIndexBase = A->getRangeMap()->getIndexBase();
190 RCP<const StridedMap> stridedRgFullMap = rcp_dynamic_cast<
const StridedMap>(rangeAMapExtractor->getFullMap());
193 ArrayView<GO> fullRangeMapGIDs(fullRangeMapVector.size() ? &fullRangeMapVector[0] : 0, fullRangeMapVector.size());
194 if (stridedRgFullMap != Teuchos::null) {
195 std::vector<size_t> stridedData = stridedRgFullMap->getStridingData();
196 fullRangeMap = StridedMapFactory::Build(
197 A->getRangeMap()->lib(),
202 A->getRangeMap()->getComm(),
204 stridedRgFullMap->getOffset());
206 fullRangeMap = MapFactory::Build(
207 A->getRangeMap()->lib(),
211 A->getRangeMap()->getComm());
214 ArrayView<GO> fullDomainMapGIDs(fullDomainMapVector.size() ? &fullDomainMapVector[0] : 0, fullDomainMapVector.size());
215 RCP<const StridedMap> stridedDoFullMap = rcp_dynamic_cast<
const StridedMap>(domainAMapExtractor->getFullMap());
217 if (stridedDoFullMap != null) {
219 "MueLu::BlockedPFactory::Build: full map in domain map extractor has no striding information!");
221 std::vector<size_t> stridedData2 = stridedDoFullMap->getStridingData();
222 fullDomainMap = StridedMapFactory::Build(
223 A->getDomainMap()->lib(),
228 A->getDomainMap()->getComm(),
230 stridedDoFullMap->getOffset());
232 fullDomainMap = MapFactory::Build(
233 A->getDomainMap()->lib(),
237 A->getDomainMap()->getComm());
241 RCP<const MapExtractor> rangeMapExtractor = MapExtractorFactory::Build(fullRangeMap, subBlockPRangeMaps, rangeAMapExtractor->getThyraMode());
242 RCP<const MapExtractor> domainMapExtractor = MapExtractorFactory::Build(fullDomainMap, subBlockPDomainMaps, domainAMapExtractor->getThyraMode());
245 for (
size_t i = 0; i < subBlockPRangeMaps.size(); i++)
246 for (
size_t j = 0; j < subBlockPRangeMaps.size(); j++)
250 "Block [" << i <<
"," << j <<
"] must be of type CrsMatrixWrap.");
251 P->setMatrix(i, i, crsOpii);
253 P->setMatrix(i, j, Teuchos::null);
259 if (!restrictionMode_) {
261 coarseLevel.
Set(
"P", rcp_dynamic_cast<Matrix>(P),
this);
263 coarseLevel.
Set(
"CoarseMap", P->getBlockedDomainMap(),
this);
268 coarseLevel.
Set(
"R", Teuchos::rcp_dynamic_cast<Matrix>(P),
this);
Exception indicating invalid cast attempted.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
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.
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)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
void sort(View &view, const size_t &size)
virtual const RCP< const FactoryBase > GetFactory(const std::string &varName) const =0
Get.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
void Set(const std::string &ename, const T &entry, const FactoryBase *factory=NoFactory::get())
void BuildP(Level &fineLevel, Level &coarseLevel) const
Abstract Build method.
Exception throws to report errors in the internal logical of the program.
An exception safe way to call the method 'Level::SetFactoryManager()'.
Description of what is happening (more verbose)
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.
void Build(Level &fineLevel, Level &coarseLevel) const
Build method.