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>
45 return validParamList;
48 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
54 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
56 Level& coarseLevel)
const {
57 return BuildP(fineLevel, coarseLevel);
61 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
66 using row_map_type =
typename local_matrix_type::row_map_type::non_const_type;
67 using entries_type =
typename local_graph_type::entries_type::non_const_type;
68 using values_type =
typename local_matrix_type::values_type;
69 using local_scalar_type =
typename values_type::value_type;
72 row_map_type rowptr(
"rowptr", numLocal + 1);
73 entries_type colind(
"colind", numLocal);
74 values_type values(
"values", numLocal);
77 "Setup CRS values for identity prolongator",
78 Kokkos::RangePolicy<LocalOrdinal, typename Node::execution_space>(0, numLocal),
80 rowptr(index) = index;
81 colind(index) = index;
82 values(index) = local_scalar_type{1.0};
83 if (index == (numLocal - 1)) {
84 rowptr(numLocal) = numLocal;
89 eye->setAllValues(rowptr, colind, values);
90 eye->expertStaticFillComplete(map, map);
91 return Teuchos::make_rcp<Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>>(eye);
95 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
97 Level& coarseLevel)
const {
101 const LO nBlks = as<LO>(pL.
get<
int>(
"combine: numBlks"));
102 const bool useMaxLevels = pL.
get<
bool>(
"combine: useMaxLevels");
111 size_t nComboRowMap = 0, nnzCombo = 0, nComboColMap = 0, nComboDomMap = 0;
113 LO nTotalNumberLocalColMapEntries = 0;
121 bool anyCoarseGridsRemaining =
false;
124 for (
int j = 0; j < nBlks; j++) {
129 int localAnyCoarseGridsRemaining = anyCoarseGridsRemaining;
130 int globalAnyCoarseGridsRemaining = localAnyCoarseGridsRemaining;
131 Teuchos::reduceAll(*A->getDomainMap()->getComm(),
Teuchos::REDUCE_MAX, localAnyCoarseGridsRemaining, Teuchos::ptr(&globalAnyCoarseGridsRemaining));
133 anyCoarseGridsRemaining |= globalAnyCoarseGridsRemaining > 0;
136 auto setSubblockProlongator = [&](
RCP<Matrix> Psubblock,
int j) {
137 arrayOfMatrices[j] = Psubblock;
138 nComboRowMap += Teuchos::as<size_t>((arrayOfMatrices[j])->getRowMap()->getLocalNumElements());
139 DomMapSizePerBlk[j] = Teuchos::as<size_t>((arrayOfMatrices[j])->getDomainMap()->getLocalNumElements());
140 ColMapSizePerBlk[j] = Teuchos::as<size_t>((arrayOfMatrices[j])->getColMap()->getLocalNumElements());
141 nComboDomMap += DomMapSizePerBlk[j];
142 nComboColMap += ColMapSizePerBlk[j];
143 nnzCombo += Teuchos::as<size_t>((arrayOfMatrices[j])->getLocalNumEntries());
148 for (
int i = 0; i < (int)DomMapSizePerBlk[j]; i++) {
149 if ((arrayOfMatrices[j])->getDomainMap()->getGlobalElement(i) == (arrayOfMatrices[j])->getColMap()->getGlobalElement(tempii)) tempii++;
151 nTotalNumberLocalColMapEntries += tempii;
152 ColMapLocalSizePerBlk[j] = tempii;
153 ColMapRemoteSizePerBlk[j] = ColMapSizePerBlk[j] - ColMapLocalSizePerBlk[j];
156 for (
int j = 0; j < nBlks; j++) {
162 bool hasOperator =
false;
165 hasOperator = A_blk != Teuchos::null;
168 if (useMaxLevels && anyCoarseGridsRemaining && hasOperator) {
170 auto P_id = constructIdentityProlongator<Scalar, LocalOrdinal, GlobalOrdinal, Node>(coarseLevel.
Get<
RCP<Operator>>(subblockOpName)->getDomainMap());
171 setSubblockProlongator(P_id, j);
173 arrayOfMatrices[j] = Teuchos::null;
174 ColMapLocalSizePerBlk[j] = 0;
175 ColMapRemoteSizePerBlk[j] = 0;
178 ColMapLocalCumulativePerBlk[j + 1] = ColMapLocalSizePerBlk[j] + ColMapLocalCumulativePerBlk[j];
179 ColMapRemoteCumulativePerBlk[j + 1] = ColMapRemoteSizePerBlk[j] + ColMapRemoteCumulativePerBlk[j];
189 size_t nnzCnt = 0, nrowCntFromPrevBlks = 0, ncolCntFromPrevBlks = 0;
191 for (
int j = 0; j < nBlks; j++) {
193 if (arrayOfMatrices[j] != Teuchos::null) {
197 if ((
int)(arrayOfMatrices[j])->getLocalMaxNumRowEntries() > maxNzPerRow) maxNzPerRow = (int)(arrayOfMatrices[j])->getLocalMaxNumRowEntries();
200 subblockcrs->getAllValues(subblockRowPtr, subblockCols, subblockVals);
204 for (decltype(subblockRowPtr.
size()) i = 0; i < subblockRowPtr.
size() - 1; i++) {
205 size_t rowLength = subblockRowPtr[i + 1] - subblockRowPtr[i];
206 comboPRowPtr[nrowCntFromPrevBlks + i] = nnzCnt;
207 for (
size_t k = 0; k < rowLength; k++) {
208 if ((
int)subblockCols[k + subblockRowPtr[i]] < (int)ColMapLocalSizePerBlk[j]) {
209 comboPCols[nnzCnt] = subblockCols[k + subblockRowPtr[i]] + ColMapLocalCumulativePerBlk[j];
210 if ((
int)comboPCols[nnzCnt] >= (int)ColMapLocalCumulativePerBlk[nBlks]) {
218 comboPCols[nnzCnt] = subblockCols[k + subblockRowPtr[i]] - ColMapLocalSizePerBlk[j] + ColMapLocalCumulativePerBlk[nBlks] + ColMapRemoteCumulativePerBlk[j];
219 if ((
int)comboPCols[nnzCnt] >= (
int)(ColMapLocalCumulativePerBlk[nBlks] + ColMapRemoteCumulativePerBlk[nBlks])) {
224 comboPVals[nnzCnt++] = subblockVals[k + subblockRowPtr[i]];
228 nrowCntFromPrevBlks += Teuchos::as<size_t>((arrayOfMatrices[j])->getRowMap()->getLocalNumElements());
229 ncolCntFromPrevBlks += DomMapSizePerBlk[j];
232 comboPRowPtr[nComboRowMap] = nnzCnt;
241 LO nTotalNumberRemoteColMapEntries = 0;
243 size_t domainMapIndex = 0;
244 int nComboColIndex = 0;
245 for (
int j = 0; j < nBlks; j++) {
246 int nThisBlkColIndex = 0;
249 if (arrayOfMatrices[j] != Teuchos::null) tempMax = (arrayOfMatrices[j])->getDomainMap()->getMaxGlobalIndex();
250 Teuchos::reduceAll(*(A->getDomainMap()->getComm()),
Teuchos::REDUCE_MAX, tempMax, Teuchos::ptr(&maxGID));
252 if (arrayOfMatrices[j] != Teuchos::null) {
256 for (
size_t c = 0; c < DomMapSizePerBlk[j]; ++c) {
259 priorDomGID = (arrayOfMatrices[j])->getDomainMap()->getGlobalElement(c);
260 comboDomainMapGIDs[domainMapIndex++] = offset + priorDomGID;
261 if (priorDomGID == (arrayOfMatrices[j])->getColMap()->getGlobalElement(nThisBlkColIndex)) {
262 comboColMapGIDs[nComboColIndex++] = offset + priorDomGID;
267 for (
size_t cc = nThisBlkColIndex; cc < ColMapSizePerBlk[j]; ++cc) {
268 comboColMapGIDs[nTotalNumberLocalColMapEntries + nTotalNumberRemoteColMapEntries++] = offset + (arrayOfMatrices[j])->getColMap()->getGlobalElement(cc);
271 offset += maxGID + 1;
289 for (
size_t i = 0; i < nComboRowMap; i++) {
290 comboPCrs->insertLocalValues(i, comboPCols.
view(comboPRowPtr[i], comboPRowPtr[i + 1] - comboPRowPtr[i]),
291 comboPVals.
view(comboPRowPtr[i], comboPRowPtr[i + 1] - comboPRowPtr[i]));
293 comboPCrs->fillComplete(coarseDomainMap, A->getRowMap());
297 Set(coarseLevel,
"P", comboP);
302 #define MUELU_COMBINEPFACTORY_SHORT
303 #endif // MUELU_COMBINEPFACTORY_DEF_HPP
ParameterList & setEntry(const std::string &name, U &&entry)
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.
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)
static RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, Xpetra::ProfileType pftype=Xpetra::DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
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