10 #ifndef MUELU_COMBINEPFACTORY_DEF_HPP
11 #define MUELU_COMBINEPFACTORY_DEF_HPP
21 #include <Xpetra_CrsMatrixWrap.hpp>
24 #include <Xpetra_MapFactory.hpp>
25 #include <Xpetra_MultiVectorFactory.hpp>
38 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
44 return validParamList;
47 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
53 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
55 Level& coarseLevel)
const {
56 return BuildP(fineLevel, coarseLevel);
59 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
61 Level& coarseLevel)
const {
65 const LO nBlks = as<LO>(pL.
get<
int>(
"combine: numBlks"));
74 size_t nComboRowMap = 0, nnzCombo = 0, nComboColMap = 0, nComboDomMap = 0;
76 LO nTotalNumberLocalColMapEntries = 0;
83 for (
int j = 0; j < nBlks; j++) {
87 nComboRowMap += Teuchos::as<size_t>((arrayOfMatrices[j])->getRowMap()->getLocalNumElements());
88 DomMapSizePerBlk[j] = Teuchos::as<size_t>((arrayOfMatrices[j])->getDomainMap()->getLocalNumElements());
89 ColMapSizePerBlk[j] = Teuchos::as<size_t>((arrayOfMatrices[j])->getColMap()->getLocalNumElements());
90 nComboDomMap += DomMapSizePerBlk[j];
91 nComboColMap += ColMapSizePerBlk[j];
92 nnzCombo += Teuchos::as<size_t>((arrayOfMatrices[j])->getLocalNumEntries());
97 for (
int i = 0; i < (int)DomMapSizePerBlk[j]; i++) {
99 if ((arrayOfMatrices[j])->getDomainMap()->getGlobalElement(i) == (arrayOfMatrices[j])->getColMap()->getGlobalElement(tempii)) tempii++;
101 nTotalNumberLocalColMapEntries += tempii;
102 ColMapLocalSizePerBlk[j] = tempii;
103 ColMapRemoteSizePerBlk[j] = ColMapSizePerBlk[j] - ColMapLocalSizePerBlk[j];
105 arrayOfMatrices[j] = Teuchos::null;
106 ColMapLocalSizePerBlk[j] = 0;
107 ColMapRemoteSizePerBlk[j] = 0;
109 ColMapLocalCumulativePerBlk[j + 1] = ColMapLocalSizePerBlk[j] + ColMapLocalCumulativePerBlk[j];
110 ColMapRemoteCumulativePerBlk[j + 1] = ColMapRemoteSizePerBlk[j] + ColMapRemoteCumulativePerBlk[j];
119 size_t nnzCnt = 0, nrowCntFromPrevBlks = 0, ncolCntFromPrevBlks = 0;
121 for (
int j = 0; j < nBlks; j++) {
123 if (arrayOfMatrices[j] != Teuchos::null) {
127 if ((
int)(arrayOfMatrices[j])->getLocalMaxNumRowEntries() > maxNzPerRow) maxNzPerRow = (int)(arrayOfMatrices[j])->getLocalMaxNumRowEntries();
130 subblockcrs->getAllValues(subblockRowPtr, subblockCols, subblockVals);
134 for (decltype(subblockRowPtr.
size()) i = 0; i < subblockRowPtr.
size() - 1; i++) {
135 size_t rowLength = subblockRowPtr[i + 1] - subblockRowPtr[i];
136 comboPRowPtr[nrowCntFromPrevBlks + i] = nnzCnt;
137 for (
size_t k = 0; k < rowLength; k++) {
138 if ((
int)subblockCols[k + subblockRowPtr[i]] < (int)ColMapLocalSizePerBlk[j]) {
139 comboPCols[nnzCnt] = subblockCols[k + subblockRowPtr[i]] + ColMapLocalCumulativePerBlk[j];
140 if ((
int)comboPCols[nnzCnt] >= (int)ColMapLocalCumulativePerBlk[nBlks]) {
148 comboPCols[nnzCnt] = subblockCols[k + subblockRowPtr[i]] - ColMapLocalSizePerBlk[j] + ColMapLocalCumulativePerBlk[nBlks] + ColMapRemoteCumulativePerBlk[j];
149 if ((
int)comboPCols[nnzCnt] >= (
int)(ColMapLocalCumulativePerBlk[nBlks] + ColMapRemoteCumulativePerBlk[nBlks])) {
154 comboPVals[nnzCnt++] = subblockVals[k + subblockRowPtr[i]];
158 nrowCntFromPrevBlks += Teuchos::as<size_t>((arrayOfMatrices[j])->getRowMap()->getLocalNumElements());
159 ncolCntFromPrevBlks += DomMapSizePerBlk[j];
162 comboPRowPtr[nComboRowMap] = nnzCnt;
171 LO nTotalNumberRemoteColMapEntries = 0;
173 size_t domainMapIndex = 0;
174 int nComboColIndex = 0;
175 for (
int j = 0; j < nBlks; j++) {
176 int nThisBlkColIndex = 0;
179 if (arrayOfMatrices[j] != Teuchos::null) tempMax = (arrayOfMatrices[j])->getDomainMap()->getMaxGlobalIndex();
180 Teuchos::reduceAll(*(A->getDomainMap()->getComm()),
Teuchos::REDUCE_MAX, tempMax, Teuchos::ptr(&maxGID));
182 if (arrayOfMatrices[j] != Teuchos::null) {
186 for (
size_t c = 0; c < DomMapSizePerBlk[j]; ++c) {
189 priorDomGID = (arrayOfMatrices[j])->getDomainMap()->getGlobalElement(c);
190 comboDomainMapGIDs[domainMapIndex++] = offset + priorDomGID;
191 if (priorDomGID == (arrayOfMatrices[j])->getColMap()->getGlobalElement(nThisBlkColIndex)) {
192 comboColMapGIDs[nComboColIndex++] = offset + priorDomGID;
197 for (
size_t cc = nThisBlkColIndex; cc < ColMapSizePerBlk[j]; ++cc) {
198 comboColMapGIDs[nTotalNumberLocalColMapEntries + nTotalNumberRemoteColMapEntries++] = offset + (arrayOfMatrices[j])->getColMap()->getGlobalElement(cc);
201 offset += maxGID + 1;
219 for (
size_t i = 0; i < nComboRowMap; i++) {
220 comboPCrs->insertLocalValues(i, comboPCols.
view(comboPRowPtr[i], comboPRowPtr[i + 1] - comboPRowPtr[i]),
221 comboPVals.
view(comboPRowPtr[i], comboPRowPtr[i + 1] - comboPRowPtr[i]));
223 comboPCrs->fillComplete(coarseDomainMap, A->getRowMap());
227 Set(coarseLevel,
"P", comboP);
232 #define MUELU_COMBINEPFACTORY_SHORT
233 #endif // MUELU_COMBINEPFACTORY_DEF_HPP
ParameterList & setEntry(const std::string &name, U &&entry)
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)
static const NoFactory * get()
void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Class that holds all level-specific information.
static Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int >> &comm, LocalGlobal lg=Xpetra::GloballyDistributed)
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
Exception throws to report errors in the internal logical of the program.
void BuildP(Level &fineLevel, Level &coarseLevel) const
Abstract Build method.
std::string toString(const T &t)
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.
ArrayView< T > view(size_type lowerOffset, size_type size) const