46 #ifndef MUELU_RAPFACTORY_DEF_HPP 47 #define MUELU_RAPFACTORY_DEF_HPP 52 #include <Xpetra_Matrix.hpp> 53 #include <Xpetra_MatrixFactory.hpp> 54 #include <Xpetra_MatrixMatrix.hpp> 55 #include <Xpetra_Vector.hpp> 56 #include <Xpetra_VectorFactory.hpp> 62 #include "MueLu_PerfUtils.hpp" 68 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
70 : hasDeclaredInput_(false) { }
72 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
74 RCP<ParameterList> validParamList = rcp(
new ParameterList());
76 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name)) 79 #undef SET_VALID_ENTRY 80 validParamList->set< RCP<const FactoryBase> >(
"A", null,
"Generating factory of the matrix A used during the prolongator smoothing process");
81 validParamList->set< RCP<const FactoryBase> >(
"P", null,
"Prolongator factory");
82 validParamList->set< RCP<const FactoryBase> >(
"R", null,
"Restrictor factory");
84 validParamList->set<
bool > (
"CheckMainDiagonal",
false,
"Check main diagonal for zeros");
85 validParamList->set<
bool > (
"RepairMainDiagonal",
false,
"Repair zeros on main diagonal");
88 ParameterList norecurse;
89 norecurse.disableRecursiveValidation();
90 validParamList->set<ParameterList> (
"matrixmatrix: kernel params", norecurse,
"MatrixMatrix kernel parameters");
92 return validParamList;
95 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
98 if (pL.get<
bool>(
"transpose: use implicit") ==
false)
99 Input(coarseLevel,
"R");
101 Input(fineLevel,
"A");
102 Input(coarseLevel,
"P");
106 (*it)->CallDeclareInput(coarseLevel);
111 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
113 const bool doTranspose =
true;
114 const bool doFillComplete =
true;
115 const bool doOptimizeStorage =
true;
118 std::ostringstream levelstr;
122 "MueLu::RAPFactory::Build(): CallDeclareInput has not been called before Build!");
125 RCP<Matrix> A = Get< RCP<Matrix> >(fineLevel,
"A");
126 RCP<Matrix> P = Get< RCP<Matrix> >(coarseLevel,
"P"), AP, Ac;
129 RCP<ParameterList> APparams;
130 if(pL.isSublist(
"matrixmatrix: kernel params"))
131 APparams=rcp(
new ParameterList(pL.sublist(
"matrixmatrix: kernel params")));
133 APparams= rcp(
new ParameterList);
136 APparams->set(
"compute global constants: temporaries",APparams->get(
"compute global constants: temporaries",
false));
137 APparams->set(
"compute global constants",APparams->get(
"compute global constants",
false));
139 if (coarseLevel.IsAvailable(
"AP reuse data",
this)) {
142 APparams = coarseLevel.Get< RCP<ParameterList> >(
"AP reuse data",
this);
144 if (APparams->isParameter(
"graph"))
145 AP = APparams->get< RCP<Matrix> >(
"graph");
152 doFillComplete, doOptimizeStorage, std::string(
"MueLu::A*P-")+levelstr.str(), APparams);
156 RCP<ParameterList> RAPparams;
157 if(pL.isSublist(
"matrixmatrix: kernel params")) RAPparams=rcp(
new ParameterList(pL.sublist(
"matrixmatrix: kernel params")));
158 else RAPparams= rcp(
new ParameterList);
160 if (coarseLevel.IsAvailable(
"RAP reuse data",
this)) {
163 RAPparams = coarseLevel.Get< RCP<ParameterList> >(
"RAP reuse data",
this);
165 if (RAPparams->isParameter(
"graph"))
166 Ac = RAPparams->get< RCP<Matrix> >(
"graph");
170 Ac->SetMaxEigenvalueEstimate(-Teuchos::ScalarTraits<SC>::one());
174 RAPparams->set(
"compute global constants: temporaries",RAPparams->get(
"compute global constants: temporaries",
false));
175 RAPparams->set(
"compute global constants",
true);
181 if (pL.get<
bool>(
"transpose: use implicit") ==
true) {
185 doFillComplete, doOptimizeStorage, std::string(
"MueLu::R*(AP)-implicit-")+levelstr.str(), RAPparams);
188 RCP<Matrix> R = Get< RCP<Matrix> >(coarseLevel,
"R");
193 doFillComplete, doOptimizeStorage, std::string(
"MueLu::R*(AP)-explicit-")+levelstr.str(), RAPparams);
199 RCP<ParameterList> params = rcp(
new ParameterList());;
200 params->set(
"printLoadBalancingInfo",
true);
201 params->set(
"printCommInfo",
true);
205 Set(coarseLevel,
"A", Ac);
207 APparams->set(
"graph", AP);
208 Set(coarseLevel,
"AP reuse data", APparams);
209 RAPparams->set(
"graph", Ac);
210 Set(coarseLevel,
"RAP reuse data", RAPparams);
218 RCP<const FactoryBase> fac = *it;
219 GetOStream(
Runtime0) <<
"RAPFactory: call transfer factory: " << fac->description() << std::endl;
220 fac->CallBuild(coarseLevel);
256 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
259 bool repairZeroDiagonals = pL.get<
bool>(
"RepairMainDiagonal") || pL.get<
bool>(
"rap: fix zero diagonals");
260 bool checkAc = pL.get<
bool>(
"CheckMainDiagonal")|| pL.get<
bool>(
"rap: fix zero diagonals"); ;
262 if (!checkAc && !repairZeroDiagonals)
265 SC zero = Teuchos::ScalarTraits<SC>::zero(), one = Teuchos::ScalarTraits<SC>::one();
267 Teuchos::RCP<Teuchos::ParameterList> p = Teuchos::rcp(
new Teuchos::ParameterList());
268 p->set(
"DoOptimizeStorage",
true);
270 RCP<const Map> rowMap = Ac->getRowMap();
271 RCP<Vector> diagVec = VectorFactory::Build(rowMap);
272 Ac->getLocalDiagCopy(*diagVec);
275 Teuchos::ArrayRCP< Scalar > diagVal = diagVec->getDataNonConst(0);
277 for (
size_t i = 0; i < rowMap->getNodeNumElements(); i++) {
278 if (diagVal[i] == zero) {
283 MueLu_sumAll(rowMap->getComm(), Teuchos::as<GO>(lZeroDiags), gZeroDiags);
285 if (repairZeroDiagonals && gZeroDiags > 0) {
300 RCP<Matrix> fixDiagMatrix = MatrixFactory::Build(rowMap, 1);
301 for (
size_t r = 0; r < rowMap->getNodeNumElements(); r++) {
302 if (diagVal[r] == zero) {
303 GO grid = rowMap->getGlobalElement(r);
304 Teuchos::ArrayRCP<GO> indout(1,grid);
305 Teuchos::ArrayRCP<SC> valout(1, one);
306 fixDiagMatrix->insertGlobalValues(grid,indout.view(0, 1), valout.view(0, 1));
310 Teuchos::TimeMonitor m1(*Teuchos::TimeMonitor::getNewTimer(
"CheckRepairMainDiagonal: fillComplete1"));
311 if(rowMap->lib() == Xpetra::UseTpetra) Ac->resumeFill();
314 MatrixMatrix::TwoMatrixAdd(*Ac,
false, 1.0, *fixDiagMatrix, 1.0);
315 if (Ac->IsView(
"stridedMaps"))
316 fixDiagMatrix->CreateView(
"stridedMaps", Ac);
324 Teuchos::TimeMonitor m1(*Teuchos::TimeMonitor::getNewTimer(
"CheckRepairMainDiagonal: fillComplete2"));
325 if(rowMap->lib() == Xpetra::UseTpetra) Ac->resumeFill();
334 GetOStream(
Warnings0) <<
"RAPFactory (WARNING): " << (repairZeroDiagonals ?
"repaired " :
"found ")
335 << gZeroDiags <<
" zeros on main diagonal of Ac." << std::endl;
337 #ifdef HAVE_MUELU_DEBUG // only for debugging 339 Ac->getLocalDiagCopy(*diagVec);
340 Teuchos::ArrayRCP< Scalar > diagVal2 = diagVec->getDataNonConst(0);
341 for (
size_t r = 0; r < Ac->getRowMap()->getNodeNumElements(); r++) {
342 if (diagVal2[r] == zero) {
343 GetOStream(
Errors,-1) <<
"Error: there are zeros left on diagonal after repair..." << std::endl;
350 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
353 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::rcp_dynamic_cast<const TwoLevelFactoryBase>(factory) == Teuchos::null,
Exceptions::BadCast,
354 "MueLu::RAPFactory::AddTransferFactory: Transfer factory is not derived from TwoLevelFactoryBase. " 355 "This is very strange. (Note: you can remove this exception if there's a good reason for)");
362 #define MUELU_RAPFACTORY_SHORT 363 #endif // MUELU_RAPFACTORY_DEF_HPP Important warning messages (one line)
#define SET_VALID_ENTRY(name)
Exception indicating invalid cast attempted.
#define MueLu_sumAll(rcpComm, in, out)
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
std::vector< RCP< const FactoryBase > > transferFacts_
list of user-defined transfer Factories
void Release(const FactoryBase &factory)
Decrement the storage counter for all the inputs of a factory.
Timer to be used in factories. Similar to Monitor but with additional timers.
One-liner description of what is happening.
void AddTransferFactory(const RCP< const FactoryBase > &factory)
Add transfer factory in the end of list of transfer factories in RepartitionAcFactory.
Namespace for MueLu classes and methods.
void CheckRepairMainDiagonal(RCP< Matrix > &Ac) const
bool IsPrint(MsgType type, int thisProcRankOnly=-1) const
Find out whether we need to print out information for a specific message type.
Print skeleton for the run, i.e. factory calls and used parameters.
Print even more statistics.
int GetLevelID() const
Return level number.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
Class that holds all level-specific information.
Timer to be used in factories. Similar to SubMonitor but adds a timer level by level.
static std::string PrintMatrixInfo(const Matrix &A, const std::string &msgTag, RCP< const Teuchos::ParameterList > params=Teuchos::null)
virtual const Teuchos::ParameterList & GetParameterList() const
void Input(Level &level, const std::string &varName) const
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.
Exception throws to report errors in the internal logical of the program.
void Set(Level &level, const std::string &varName, const T &data) const
void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.