10 #ifndef MUELU_SAPFACTORY_DEF_HPP
11 #define MUELU_SAPFACTORY_DEF_HPP
13 #include "Kokkos_ArithTraits.hpp"
23 #include "MueLu_PerfUtils.hpp"
24 #include "MueLu_TentativePFactory.hpp"
25 #include "MueLu_Utilities.hpp"
31 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
34 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
37 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
41 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
54 #undef SET_VALID_ENTRY
56 validParamList->
set<
RCP<const FactoryBase> >(
"A", Teuchos::null,
"Generating factory of the matrix A used during the prolongator smoothing process");
61 norecurse.disableRecursiveValidation();
62 validParamList->
set<
ParameterList>(
"matrixmatrix: kernel params", norecurse,
"MatrixMatrix kernel parameters");
64 return validParamList;
67 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
69 Input(fineLevel,
"A");
74 if (initialPFact == Teuchos::null) {
80 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
82 return BuildP(fineLevel, coarseLevel);
85 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
91 const std::string prefix =
"MueLu::SaPFactory(" + levelIDs +
"): ";
100 if (initialPFact == Teuchos::null) {
111 if (Ptent == Teuchos::null) {
112 finalP = Teuchos::null;
113 Set(coarseLevel,
"P", finalP);
117 if (restrictionMode_) {
126 if (pL.
isSublist(
"matrixmatrix: kernel params"))
130 if (coarseLevel.
IsAvailable(
"AP reuse data",
this)) {
131 GetOStream(static_cast<MsgType>(
Runtime0 |
Test)) <<
"Reusing previous AP data" << std::endl;
139 APparams->
set(
"compute global constants: temporaries", APparams->
get(
"compute global constants: temporaries",
false));
140 APparams->
set(
"compute global constants", APparams->
get(
"compute global constants",
false));
142 const SC dampingFactor = as<SC>(pL.
get<
double>(
"sa: damping factor"));
143 const LO maxEigenIterations = as<LO>(pL.
get<
int>(
"sa: eigenvalue estimate num iterations"));
144 const bool estimateMaxEigen = pL.
get<
bool>(
"sa: calculate eigenvalue estimate");
145 const bool useAbsValueRowSum = pL.
get<
bool>(
"sa: use rowsumabs diagonal scaling");
146 const bool doQRStep = pL.
get<
bool>(
"tentative: calculate qr");
147 const bool enforceConstraints = pL.
get<
bool>(
"sa: enforce constraints");
148 const MT userDefinedMaxEigen = as<MT>(pL.
get<
double>(
"sa: max eigenvalue"));
149 double dTol = pL.
get<
double>(
"sa: rowsumabs diagonal replacement tolerance");
150 const MT diagonalReplacementTolerance = (dTol == as<double>(-1) ?
Teuchos::ScalarTraits<MT>::eps() * 100 : as<MT>(pL.
get<
double>(
"sa: rowsumabs diagonal replacement tolerance")));
151 const SC diagonalReplacementValue = as<SC>(pL.
get<
double>(
"sa: rowsumabs diagonal replacement value"));
152 const bool replaceSingleEntryRowWithZero = pL.
get<
bool>(
"sa: rowsumabs replace single entry row with zero");
153 const bool useAutomaticDiagTol = pL.
get<
bool>(
"sa: rowsumabs use automatic diagonal tolerance");
157 "MueLu::TentativePFactory::MakeTentative: cannot use 'enforce constraints' and 'calculate qr' at the same time");
162 if (userDefinedMaxEigen == -1.) {
164 lambdaMax = A->GetMaxEigenvalueEstimate();
166 GetOStream(
Statistics1) <<
"Calculating max eigenvalue estimate now (max iters = " << maxEigenIterations << ((useAbsValueRowSum) ?
", use rowSumAbs diagonal)" :
", use point diagonal)") << std::endl;
167 Coordinate stopTol = 1e-4;
168 if (useAbsValueRowSum) {
169 const bool returnReciprocal =
true;
171 diagonalReplacementTolerance,
172 diagonalReplacementValue,
173 replaceSingleEntryRowWithZero,
174 useAutomaticDiagTol);
176 "SaPFactory: eigenvalue estimate: diagonal reciprocal is null.");
180 A->SetMaxEigenvalueEstimate(lambdaMax);
182 GetOStream(
Statistics1) <<
"Using cached max eigenvalue estimate" << std::endl;
185 lambdaMax = userDefinedMaxEigen;
186 A->SetMaxEigenvalueEstimate(lambdaMax);
188 GetOStream(
Statistics1) <<
"Prolongator damping factor = " << dampingFactor / lambdaMax <<
" (" << dampingFactor <<
" / " << lambdaMax <<
")" << std::endl;
192 if (!useAbsValueRowSum)
194 else if (invDiag == Teuchos::null) {
195 GetOStream(
Runtime0) <<
"Using rowsumabs diagonal" << std::endl;
196 const bool returnReciprocal =
true;
198 diagonalReplacementTolerance,
199 diagonalReplacementValue,
200 replaceSingleEntryRowWithZero,
201 useAutomaticDiagTol);
205 SC omega = dampingFactor / lambdaMax;
211 finalP =
Xpetra::IteratorOps<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Jacobi(omega, *invDiag, *A, *Ptent, finalP, GetOStream(
Statistics2), std::string(
"MueLu::SaP-") +
toString(coarseLevel.
GetLevelID()), APparams);
212 if (enforceConstraints) {
213 if (!pL.
get<
bool>(
"use kokkos refactor")) {
214 if (A->GetFixedBlockSize() == 1)
215 optimalSatisfyPConstraintsForScalarPDEsNonKokkos(finalP);
217 SatisfyPConstraintsNonKokkos(A, finalP);
222 SatisfyPConstraints(A, finalP);
234 if (!restrictionMode_) {
237 std::ostringstream oss;
239 finalP->setObjectLabel(oss.str());
241 Set(coarseLevel,
"P", finalP);
243 APparams->
set(
"graph", finalP);
244 Set(coarseLevel,
"AP reuse data", APparams);
247 if (Ptent->IsView(
"stridedMaps"))
248 finalP->CreateView(
"stridedMaps", Ptent);
256 std::ostringstream oss;
258 R->setObjectLabel(oss.str());
262 Set(coarseLevel,
"R", R);
265 if (Ptent->IsView(
"stridedMaps"))
266 R->CreateView(
"stridedMaps", Ptent,
true );
271 params->
set(
"printLoadBalancingInfo",
true);
272 params->
set(
"printCommInfo",
true);
294 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
298 LO nPDEs = A->GetFixedBlockSize();
302 for (
size_t k = 0; k < (size_t)nPDEs; k++) ConstraintViolationSum[k] = zero;
303 for (
size_t k = 0; k < (size_t)nPDEs; k++) Rsum[k] = zero;
304 for (
size_t k = 0; k < (size_t)nPDEs; k++) nPositive[k] = 0;
306 for (
size_t i = 0; i < as<size_t>(P->getRowMap()->getLocalNumElements()); i++) {
310 P->getLocalRowView((
LO)i, indices, vals1);
311 size_t nnz = indices.
size();
312 if (nnz == 0)
continue;
316 bool checkRow =
true;
321 for (
LO j = 0; j < indices.
size(); j++) {
322 Rsum[j % nPDEs] += vals[j];
324 ConstraintViolationSum[j % nPDEs] += vals[j];
328 (nPositive[j % nPDEs])++;
331 ConstraintViolationSum[j % nPDEs] += (vals[j] - one);
341 for (
size_t k = 0; k < (size_t)nPDEs; k++) {
343 ConstraintViolationSum[k] += (-Rsum[k]);
345 ConstraintViolationSum[k] += (one - Rsum[k]);
350 for (
size_t k = 0; k < (size_t)nPDEs; k++) {
356 for (
LO j = 0; j < indices.
size(); j++) {
358 vals[j] += (ConstraintViolationSum[j % nPDEs] / (as<Scalar>(nPositive[j % nPDEs])));
361 for (
size_t k = 0; k < (size_t)nPDEs; k++) ConstraintViolationSum[k] = zero;
363 for (
size_t k = 0; k < (size_t)nPDEs; k++) Rsum[k] = zero;
364 for (
size_t k = 0; k < (size_t)nPDEs; k++) nPositive[k] = 0;
369 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
378 for (
size_t i = 0; i < as<size_t>(P->getRowMap()->getLocalNumElements()); i++) {
383 size_t nnz = indices.
size();
387 for (
size_t j = 0; j < nnz; j++) rsumTarget += vals[j];
389 if (nnz > as<size_t>(maxEntriesPerRow)) {
390 maxEntriesPerRow = nnz * 3;
391 scalarData.
resize(3 * maxEntriesPerRow);
393 hasFeasible = constrainRow(vals.
getRawPtr(), as<LocalOrdinal>(nnz), zero, one, rsumTarget, vals.
getRawPtr(), scalarData.
getRawPtr());
396 for (
size_t j = 0; j < nnz; j++) vals[j] = one / as<Scalar>(nnz);
403 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
522 Scalar notFlippedLeftBound, notFlippedRghtBound, aBigNumber, *origSorted;
523 Scalar rowSumDeviation, temp, *fixedSorted, delta;
524 Scalar closestToLeftBoundDist, closestToRghtBoundDist;
529 notFlippedLeftBound = leftBound;
530 notFlippedRghtBound = rghtBound;
534 hasFeasibleSol =
true;
536 hasFeasibleSol =
false;
537 return hasFeasibleSol;
549 origSorted = &scalarData[0];
550 fixedSorted = &(scalarData[nEntries]);
553 for (
LocalOrdinal i = 0; i < nEntries; i++) inds[i] = i;
554 for (
LocalOrdinal i = 0; i < nEntries; i++) origSorted[i] = orig[i];
557 std::sort(inds, inds + nEntries,
560 for (
LocalOrdinal i = 0; i < nEntries; i++) origSorted[i] = orig[inds[i]];
562 closestToLeftBound = 0;
566 closestToRghtBound = closestToLeftBound;
572 closestToLeftBoundDist = origSorted[closestToLeftBound] - leftBound;
573 if (closestToRghtBound == nEntries)
574 closestToRghtBoundDist = aBigNumber;
576 closestToRghtBoundDist = origSorted[closestToRghtBound] - rghtBound;
581 rowSumDeviation = leftBound * as<Scalar>(closestToLeftBound) + as<Scalar>((nEntries - closestToRghtBound)) * rghtBound - rsumTarget;
582 for (
LocalOrdinal i = closestToLeftBound; i < closestToRghtBound; i++) rowSumDeviation += origSorted[i];
590 leftBound = -rghtBound;
595 if ((nEntries % 2) == 1) origSorted[(nEntries / 2)] = -origSorted[(nEntries / 2)];
597 temp = origSorted[i];
598 origSorted[i] = -origSorted[nEntries - 1 - i];
599 origSorted[nEntries - i - 1] = -temp;
605 closestToLeftBound = nEntries - closestToRghtBound;
606 closestToRghtBound = nEntries - itemp;
607 closestToLeftBoundDist = origSorted[closestToLeftBound] - leftBound;
608 if (closestToRghtBound == nEntries)
609 closestToRghtBoundDist = aBigNumber;
611 closestToRghtBoundDist = origSorted[closestToRghtBound] - rghtBound;
613 rowSumDeviation = -rowSumDeviation;
618 for (
LocalOrdinal i = 0; i < closestToLeftBound; i++) fixedSorted[i] = leftBound;
619 for (
LocalOrdinal i = closestToLeftBound; i < closestToRghtBound; i++) fixedSorted[i] = origSorted[i];
620 for (
LocalOrdinal i = closestToRghtBound; i < nEntries; i++) fixedSorted[i] = rghtBound;
623 if (closestToRghtBound != closestToLeftBound)
624 delta = rowSumDeviation / as<Scalar>(closestToRghtBound - closestToLeftBound);
631 for (
LocalOrdinal i = closestToLeftBound; i < closestToRghtBound; i++) fixedSorted[i] = origSorted[i] - delta;
633 rowSumDeviation = rowSumDeviation - closestToLeftBoundDist;
634 fixedSorted[closestToLeftBound] = leftBound;
635 closestToLeftBound++;
636 if (closestToLeftBound < nEntries)
637 closestToLeftBoundDist = origSorted[closestToLeftBound] - leftBound;
639 closestToLeftBoundDist = aBigNumber;
644 for (
LocalOrdinal i = closestToLeftBound; i < closestToRghtBound; i++) fixedSorted[i] = origSorted[i] - delta;
646 rowSumDeviation = rowSumDeviation + closestToRghtBoundDist;
648 fixedSorted[closestToRghtBound] = origSorted[closestToRghtBound];
649 closestToRghtBound++;
651 if (closestToRghtBound >= nEntries)
652 closestToRghtBoundDist = aBigNumber;
654 closestToRghtBoundDist = origSorted[closestToRghtBound] - rghtBound;
662 if ((nEntries % 2) == 1) fixedSorted[(nEntries / 2)] = -fixedSorted[(nEntries / 2)];
664 temp = fixedSorted[i];
665 fixedSorted[i] = -fixedSorted[nEntries - 1 - i];
666 fixedSorted[nEntries - i - 1] = -temp;
669 for (
LocalOrdinal i = 0; i < nEntries; i++) fixedUnsorted[inds[i]] = fixedSorted[i];
673 bool lowerViolation =
false;
674 bool upperViolation =
false;
675 bool sumViolation =
false;
679 if (TST::real(fixedUnsorted[i]) < TST::real(notFlippedLeftBound)) lowerViolation =
true;
680 if (TST::real(fixedUnsorted[i]) > TST::real(notFlippedRghtBound)) upperViolation =
true;
681 temp += fixedUnsorted[i];
683 SC tol = as<Scalar>(std::max(1.0e-8, as<double>(100 * TST::eps())));
684 if (TST::magnitude(temp - rsumTarget) > TST::magnitude(tol * rsumTarget)) sumViolation =
true;
690 return hasFeasibleSol;
693 template <
typename local_matrix_type>
695 using Scalar =
typename local_matrix_type::non_const_value_type;
697 using LO =
typename local_matrix_type::non_const_ordinal_type;
698 using Device =
typename local_matrix_type::device_type;
699 using KAT = Kokkos::ArithTraits<SC>;
705 Kokkos::View<SC**, Device>
Rsum;
712 Rsum = Kokkos::View<SC**, Device>(
"Rsum", localP_.numRows(),
nPDEs);
713 nPositive = Kokkos::View<size_t**, Device>(
"nPositive", localP_.numRows(),
nPDEs);
716 KOKKOS_INLINE_FUNCTION
718 auto rowPtr =
localP.graph.row_map;
719 auto values =
localP.values;
721 bool checkRow =
true;
723 if (rowPtr(rowIdx + 1) == rowPtr(rowIdx)) checkRow =
false;
728 for (
auto entryIdx = rowPtr(rowIdx); entryIdx < rowPtr(rowIdx + 1); entryIdx++) {
729 Rsum(rowIdx, entryIdx %
nPDEs) += values(entryIdx);
730 if (KAT::real(values(entryIdx)) < KAT::real(
zero)) {
732 values(entryIdx) =
zero;
734 if (KAT::real(values(entryIdx)) != KAT::real(
zero))
737 if (KAT::real(values(entryIdx)) > KAT::real(1.00001)) {
739 values(entryIdx) =
one;
748 for (
size_t k = 0; k < (size_t)
nPDEs; k++) {
749 if (KAT::real(
Rsum(rowIdx, k)) < KAT::magnitude(
zero)) {
751 }
else if (KAT::real(
Rsum(rowIdx, k)) > KAT::magnitude(1.00001)) {
757 for (
size_t k = 0; k < (size_t)
nPDEs; k++) {
763 for (
auto entryIdx = rowPtr(rowIdx); entryIdx < rowPtr(rowIdx + 1); entryIdx++) {
764 if (KAT::real(values(entryIdx)) > KAT::real(
zero)) {
765 values(entryIdx) = values(entryIdx) +
771 for (
size_t k = 0; k < (size_t)
nPDEs; k++)
Rsum(rowIdx, k) =
zero;
772 for (
size_t k = 0; k < (size_t)
nPDEs; k++)
nPositive(rowIdx, k) = 0;
777 template <
typename local_matrix_type>
779 using Scalar =
typename local_matrix_type::non_const_value_type;
781 using LO =
typename local_matrix_type::non_const_ordinal_type;
782 using Device =
typename local_matrix_type::device_type;
783 using KAT = Kokkos::ArithTraits<SC>;
790 Kokkos::View<LO**, Device>
inds;
795 origSorted = Kokkos::View<SC**, Device>(
"origSorted", localP_.numRows(), maxRowEntries_);
796 fixedSorted = Kokkos::View<SC**, Device>(
"fixedSorted", localP_.numRows(), maxRowEntries_);
797 inds = Kokkos::View<LO**, Device>(
"inds", localP_.numRows(), maxRowEntries_);
800 KOKKOS_INLINE_FUNCTION
802 auto rowPtr =
localP.graph.row_map;
803 auto values =
localP.values;
805 auto nnz = rowPtr(rowIdx + 1) - rowPtr(rowIdx);
809 for (
auto entryIdx = rowPtr(rowIdx); entryIdx < rowPtr(rowIdx + 1); entryIdx++) rsumTarget += values(entryIdx);
813 SC rowSumDeviation, temp, delta;
814 SC closestToLeftBoundDist, closestToRghtBoundDist;
815 LO closestToLeftBound, closestToRghtBound;
820 if ((KAT::real(rsumTarget) >= KAT::real(leftBound * (static_cast<SC>(nnz)))) &&
821 (KAT::real(rsumTarget) <= KAT::real(rghtBound * (static_cast<SC>(nnz))))) {
826 aBigNumber = KAT::zero();
827 for (
auto entryIdx = rowPtr(rowIdx); entryIdx < rowPtr(rowIdx + 1); entryIdx++) {
828 if (KAT::magnitude(values(entryIdx)) > KAT::magnitude(aBigNumber))
829 aBigNumber = KAT::magnitude(values(entryIdx));
831 aBigNumber = aBigNumber + (KAT::magnitude(leftBound) + KAT::magnitude(rghtBound)) * (100 *
one);
834 for (
auto entryIdx = rowPtr(rowIdx); entryIdx < rowPtr(rowIdx + 1); entryIdx++) {
836 inds(rowIdx, ind) = ind;
840 auto sortVals = Kokkos::subview(
origSorted, rowIdx, Kokkos::ALL());
841 auto sortInds = Kokkos::subview(
inds, rowIdx, Kokkos::make_pair(0, ind));
845 for (
LO i = 1; i < static_cast<LO>(nnz); ++i) {
849 if (KAT::real(sortVals(sortInds(i))) < KAT::real(sortVals(sortInds(0)))) {
850 for (; j > 0; --j) sortInds(j) = sortInds(j - 1);
854 for (; KAT::real(sortVals(ind)) < KAT::real(sortVals(sortInds(j - 1))); --j) sortInds(j) = sortInds(j - 1);
860 for (
LO i = 0; i < static_cast<LO>(nnz); i++)
origSorted(rowIdx, i) = values(rowPtr(rowIdx) +
inds(rowIdx, i));
862 closestToLeftBound = 0;
863 while ((closestToLeftBound < static_cast<LO>(nnz)) && (KAT::real(
origSorted(rowIdx, closestToLeftBound)) <= KAT::real(leftBound))) closestToLeftBound++;
866 closestToRghtBound = closestToLeftBound;
867 while ((closestToRghtBound < static_cast<LO>(nnz)) && (KAT::real(
origSorted(rowIdx, closestToRghtBound)) <= KAT::real(rghtBound))) closestToRghtBound++;
872 closestToLeftBoundDist =
origSorted(rowIdx, closestToLeftBound) - leftBound;
873 if (closestToRghtBound == static_cast<LO>(nnz))
874 closestToRghtBoundDist = aBigNumber;
876 closestToRghtBoundDist =
origSorted(rowIdx, closestToRghtBound) - rghtBound;
881 rowSumDeviation = leftBound * (
static_cast<SC>(closestToLeftBound)) + (
static_cast<SC>(nnz - closestToRghtBound)) * rghtBound - rsumTarget;
882 for (
LO i = closestToLeftBound; i < closestToRghtBound; i++) rowSumDeviation +=
origSorted(rowIdx, i);
887 if (KAT::real(rowSumDeviation) < KAT::real(KAT::zero())) {
890 leftBound = -rghtBound;
897 for (
LO i = 0; i < static_cast<LO>(nnz / 2); i++) {
905 LO itemp = closestToLeftBound;
906 closestToLeftBound = nnz - closestToRghtBound;
907 closestToRghtBound = nnz - itemp;
908 closestToLeftBoundDist =
origSorted(rowIdx, closestToLeftBound) - leftBound;
909 if (closestToRghtBound == static_cast<LO>(nnz))
910 closestToRghtBoundDist = aBigNumber;
912 closestToRghtBoundDist =
origSorted(rowIdx, closestToRghtBound) - rghtBound;
914 rowSumDeviation = -rowSumDeviation;
919 for (
LO i = 0; i < closestToLeftBound; i++)
fixedSorted(rowIdx, i) = leftBound;
921 for (
LO i = closestToRghtBound; i < static_cast<LO>(nnz); i++)
fixedSorted(rowIdx, i) = rghtBound;
923 while ((KAT::magnitude(rowSumDeviation) > KAT::magnitude((
one * 1.e-10) * rsumTarget))) {
924 if (closestToRghtBound != closestToLeftBound)
925 delta = rowSumDeviation /
static_cast<SC>(closestToRghtBound - closestToLeftBound);
929 if (KAT::magnitude(closestToLeftBoundDist) <= KAT::magnitude(closestToRghtBoundDist)) {
930 if (KAT::magnitude(delta) <= KAT::magnitude(closestToLeftBoundDist)) {
931 rowSumDeviation =
zero;
932 for (
LO i = closestToLeftBound; i < closestToRghtBound; i++)
fixedSorted(rowIdx, i) =
origSorted(rowIdx, i) - delta;
934 rowSumDeviation = rowSumDeviation - closestToLeftBoundDist;
935 fixedSorted(rowIdx, closestToLeftBound) = leftBound;
936 closestToLeftBound++;
937 if (closestToLeftBound < static_cast<LO>(nnz))
938 closestToLeftBoundDist =
origSorted(rowIdx, closestToLeftBound) - leftBound;
940 closestToLeftBoundDist = aBigNumber;
943 if (KAT::magnitude(delta) <= KAT::magnitude(closestToRghtBoundDist)) {
945 for (
LO i = closestToLeftBound; i < closestToRghtBound; i++)
fixedSorted(rowIdx, i) =
origSorted(rowIdx, i) - delta;
947 rowSumDeviation = rowSumDeviation + closestToRghtBoundDist;
950 closestToRghtBound++;
952 if (closestToRghtBound >= static_cast<LO>(nnz))
953 closestToRghtBoundDist = aBigNumber;
955 closestToRghtBoundDist =
origSorted(rowIdx, closestToRghtBound) - rghtBound;
960 auto rowStart = rowPtr(rowIdx);
965 for (
LO i = 0; i < static_cast<LO>(nnz / 2); i++) {
972 for (
LO i = 0; i < static_cast<LO>(nnz); i++) values(rowStart +
inds(rowIdx, i)) =
fixedSorted(rowIdx, i);
976 for (
auto entryIdx = rowPtr(rowIdx); entryIdx < rowPtr(rowIdx + 1); entryIdx++) values(entryIdx) =
one / (
static_cast<SC>(nnz));
983 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
985 using Device =
typename Matrix::local_matrix_type::device_type;
986 LO nPDEs = A->GetFixedBlockSize();
988 using local_mat_type =
typename Matrix::local_matrix_type;
990 Kokkos::parallel_for(
"enforce constraint", Kokkos::RangePolicy<typename Device::execution_space>(0, P->getRowMap()->getLocalNumElements()),
995 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
997 using Device =
typename Matrix::local_matrix_type::device_type;
1000 using local_mat_type =
typename Matrix::local_matrix_type;
1002 Kokkos::parallel_for(
"enforce constraint", Kokkos::RangePolicy<typename Device::execution_space>(0, P->getLocalNumRows()),
1009 #endif // MUELU_SAPFACTORY_DEF_HPP
typename local_matrix_type::non_const_value_type Scalar
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.
void optimalSatisfyPConstraintsForScalarPDEs(RCP< Matrix > &P) const
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
typename local_matrix_type::device_type Device
static Scalar PowerMethod(const Matrix &A, bool scaleByDiag=true, LocalOrdinal niters=10, Magnitude tolerance=1e-2, bool verbose=false, unsigned int seed=123)
Power method.
bool constrainRow(Scalar *orig, LocalOrdinal nEntries, Scalar leftBound, Scalar rghtBound, Scalar rsumTarget, Scalar *fixedUnsorted, Scalar *scalarData) const
optimalSatisfyConstraintsForScalarPDEsKernel(LO nPDEs_, LO maxRowEntries_, local_matrix_type localP_)
T & get(const std::string &name, T def_value)
KOKKOS_INLINE_FUNCTION void operator()(const size_t rowIdx) const
SaPFactory()
Constructor. User can supply a factory for generating the tentative prolongator.
Kokkos::View< LO **, Device > inds
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
static magnitudeType real(T a)
typename local_matrix_type::non_const_ordinal_type LO
constraintKernel(LO nPDEs_, local_matrix_type localP_)
One-liner description of what is happening.
void SatisfyPConstraintsNonKokkos(RCP< Matrix > A, RCP< Matrix > &P) const
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Kokkos::View< SC **, Device > fixedSorted
Kokkos::ArithTraits< SC > KAT
Print even more statistics.
Kokkos::View< size_t **, Device > nPositive
void resize(const size_type n, const T &val=T())
bool isParameter(const std::string &name) const
typename local_matrix_type::device_type Device
static RCP< Matrix > Jacobi(SC omega, const Vector &Dinv, const Matrix &A, const Matrix &B, RCP< Matrix > C_in, Teuchos::FancyOStream &fos, const std::string &label, RCP< ParameterList > ¶ms)
virtual ~SaPFactory()
Destructor.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
MueLu::DefaultScalar Scalar
Class that holds all level-specific information.
Kokkos::View< SC **, Device > origSorted
bool isSublist(const std::string &name) const
Timer to be used in factories. Similar to SubMonitor but adds a timer level by level.
void Build(Level &fineLevel, Level &coarseLevel) const
Build method.
Kokkos::View< SC **, Device > ConstraintViolationSum
#define SET_VALID_ENTRY(name)
static RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Transpose(Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, bool optimizeTranspose=false, const std::string &label=std::string(), const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
static std::string PrintMatrixInfo(const Matrix &A, const std::string &msgTag, RCP< const Teuchos::ParameterList > params=Teuchos::null)
void SatisfyPConstraints(RCP< Matrix > A, RCP< Matrix > &P) const
static RCP< Vector > GetMatrixDiagonalInverse(const Matrix &A, Magnitude tol=Teuchos::ScalarTraits< Scalar >::eps()*100, Scalar valReplacement=Teuchos::ScalarTraits< Scalar >::zero(), const bool doLumped=false)
Extract Matrix Diagonal.
Kokkos::ArithTraits< SC > KAT
static magnitudeType magnitude(T a)
void BuildP(Level &fineLevel, Level &coarseLevel) const
Abstract Build method.
typename local_matrix_type::non_const_value_type Scalar
typename local_matrix_type::non_const_ordinal_type LO
Kokkos::View< SC **, Device > Rsum
const RCP< const FactoryManagerBase > GetFactoryManager()
returns the current factory manager
KOKKOS_INLINE_FUNCTION void operator()(const size_t rowIdx) const
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
void optimalSatisfyPConstraintsForScalarPDEsNonKokkos(RCP< Matrix > &P) const
int GetLevelID() const
Return level number.
Exception throws to report errors in the internal logical of the program.
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.
static Teuchos::RCP< Vector > GetLumpedMatrixDiagonal(Matrix const &A, const bool doReciprocal=false, Magnitude tol=Teuchos::ScalarTraits< Scalar >::magnitude(Teuchos::ScalarTraits< Scalar >::zero()), Scalar valReplacement=Teuchos::ScalarTraits< Scalar >::zero(), const bool replaceSingleEntryRowWithZero=false, const bool useAverageAbsDiagVal=false)
Extract Matrix Diagonal of lumped matrix.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.