46 #ifndef MUELU_RAPFACTORY_DEF_HPP
47 #define MUELU_RAPFACTORY_DEF_HPP
64 #include "MueLu_PerfUtils.hpp"
70 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
72 : hasDeclaredInput_(false) { }
74 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
78 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
82 #undef SET_VALID_ENTRY
83 validParamList->
set<
RCP<const FactoryBase> >(
"A", null,
"Generating factory of the matrix A used during the prolongator smoothing process");
87 validParamList->
set<
bool > (
"CheckMainDiagonal",
false,
"Check main diagonal for zeros");
88 validParamList->
set<
bool > (
"RepairMainDiagonal",
false,
"Repair zeros on main diagonal");
93 validParamList->
set<
ParameterList> (
"matrixmatrix: kernel params", norecurse,
"MatrixMatrix kernel parameters");
95 return validParamList;
98 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
101 if (pL.
get<
bool>(
"transpose: use implicit") ==
false)
102 Input(coarseLevel,
"R");
104 Input(fineLevel,
"A");
105 Input(coarseLevel,
"P");
108 for (std::vector<
RCP<const FactoryBase> >::const_iterator it = transferFacts_.begin(); it != transferFacts_.end(); ++it)
109 (*it)->CallDeclareInput(coarseLevel);
111 hasDeclaredInput_ =
true;
114 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
116 const bool doTranspose =
true;
117 const bool doFillComplete =
true;
118 const bool doOptimizeStorage =
true;
121 std::ostringstream levelstr;
126 "MueLu::RAPFactory::Build(): CallDeclareInput has not been called before Build!");
129 RCP<Matrix> A = Get< RCP<Matrix> >(fineLevel,
"A");
130 RCP<Matrix> P = Get< RCP<Matrix> >(coarseLevel,
"P"), AP, Ac;
133 if (pL.
get<
bool>(
"rap: triple product") ==
false) {
136 if(pL.
isSublist(
"matrixmatrix: kernel params"))
137 APparams->
sublist(
"matrixmatrix: kernel params") = pL.
sublist(
"matrixmatrix: kernel params");
140 APparams->
set(
"compute global constants: temporaries",APparams->
get(
"compute global constants: temporaries",
false));
141 APparams->
set(
"compute global constants",APparams->
get(
"compute global constants",
false));
143 if (coarseLevel.IsAvailable(
"AP reuse data",
this)) {
144 GetOStream(static_cast<MsgType>(
Runtime0 |
Test)) <<
"Reusing previous AP data" << std::endl;
155 AP = MatrixMatrix::Multiply(*A, !doTranspose, *P, !doTranspose, AP, GetOStream(
Statistics2),
156 doFillComplete, doOptimizeStorage, labelstr+std::string(
"MueLu::A*P-")+levelstr.str(), APparams);
161 if(pL.
isSublist(
"matrixmatrix: kernel params"))
162 RAPparams->
sublist(
"matrixmatrix: kernel params") = pL.
sublist(
"matrixmatrix: kernel params");
164 if (coarseLevel.IsAvailable(
"RAP reuse data",
this)) {
165 GetOStream(static_cast<MsgType>(
Runtime0 |
Test)) <<
"Reusing previous RAP data" << std::endl;
178 RAPparams->
set(
"compute global constants: temporaries",RAPparams->
get(
"compute global constants: temporaries",
false));
179 RAPparams->
set(
"compute global constants",
true);
185 if (pL.
get<
bool>(
"transpose: use implicit") ==
true) {
188 Ac = MatrixMatrix::Multiply(*P, doTranspose, *AP, !doTranspose, Ac, GetOStream(
Statistics2),
189 doFillComplete, doOptimizeStorage, labelstr+std::string(
"MueLu::R*(AP)-implicit-")+levelstr.str(), RAPparams);
192 RCP<Matrix> R = Get< RCP<Matrix> >(coarseLevel,
"R");
196 Ac = MatrixMatrix::Multiply(*R, !doTranspose, *AP, !doTranspose, Ac, GetOStream(
Statistics2),
197 doFillComplete, doOptimizeStorage, labelstr+std::string(
"MueLu::R*(AP)-explicit-")+levelstr.str(), RAPparams);
199 bool repairZeroDiagonals = pL.
get<
bool>(
"RepairMainDiagonal") || pL.
get<
bool>(
"rap: fix zero diagonals");
200 bool checkAc = pL.
get<
bool>(
"CheckMainDiagonal")|| pL.
get<
bool>(
"rap: fix zero diagonals"); ;
201 if (checkAc || repairZeroDiagonals)
206 params->
set(
"printLoadBalancingInfo",
true);
207 params->
set(
"printCommInfo",
true);
211 if(!Ac.is_null()) {std::ostringstream oss; oss <<
"A_" << coarseLevel.GetLevelID(); Ac->setObjectLabel(oss.str());}
212 Set(coarseLevel,
"A", Ac);
214 APparams->
set(
"graph", AP);
215 Set(coarseLevel,
"AP reuse data", APparams);
216 RAPparams->
set(
"graph", Ac);
217 Set(coarseLevel,
"RAP reuse data", RAPparams);
220 if(pL.
isSublist(
"matrixmatrix: kernel params"))
221 RAPparams->
sublist(
"matrixmatrix: kernel params") = pL.
sublist(
"matrixmatrix: kernel params");
224 RAPparams->
set(
"compute global constants: temporaries",RAPparams->
get(
"compute global constants: temporaries",
false));
225 RAPparams->
set(
"compute global constants",
true);
227 if (pL.
get<
bool>(
"transpose: use implicit") ==
true) {
229 Ac = MatrixFactory::Build(P->getDomainMap(), Teuchos::as<LO>(0));
234 MultiplyRAP(*P, doTranspose, *A, !doTranspose, *P, !doTranspose, *Ac, doFillComplete,
235 doOptimizeStorage, labelstr+std::string(
"MueLu::R*A*P-implicit-")+levelstr.str(),
239 RCP<Matrix> R = Get< RCP<Matrix> >(coarseLevel,
"R");
240 Ac = MatrixFactory::Build(R->getRowMap(), Teuchos::as<LO>(0));
245 MultiplyRAP(*R, !doTranspose, *A, !doTranspose, *P, !doTranspose, *Ac, doFillComplete,
246 doOptimizeStorage, labelstr+std::string(
"MueLu::R*A*P-explicit-")+levelstr.str(),
249 bool repairZeroDiagonals = pL.
get<
bool>(
"RepairMainDiagonal") || pL.
get<
bool>(
"rap: fix zero diagonals");
250 bool checkAc = pL.
get<
bool>(
"CheckMainDiagonal")|| pL.
get<
bool>(
"rap: fix zero diagonals"); ;
251 if (checkAc || repairZeroDiagonals)
256 params->
set(
"printLoadBalancingInfo",
true);
257 params->
set(
"printCommInfo",
true);
261 if(!Ac.is_null()) {std::ostringstream oss; oss <<
"A_" << coarseLevel.GetLevelID(); Ac->setObjectLabel(oss.str());}
262 Set(coarseLevel,
"A", Ac);
271 if (transferFacts_.begin() != transferFacts_.end()) {
275 for (std::vector<
RCP<const FactoryBase> >::const_iterator it = transferFacts_.begin(); it != transferFacts_.end(); ++it) {
277 GetOStream(
Runtime0) <<
"RAPFactory: call transfer factory: " << fac->
description() << std::endl;
313 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
317 "MueLu::RAPFactory::AddTransferFactory: Transfer factory is not derived from TwoLevelFactoryBase. "
318 "This is very strange. (Note: you can remove this exception if there's a good reason for)");
320 transferFacts_.push_back(factory);
325 #define MUELU_RAPFACTORY_SHORT
326 #endif // MUELU_RAPFACTORY_DEF_HPP
#define SET_VALID_ENTRY(name)
Exception indicating invalid cast attempted.
virtual std::string getObjectLabel() const
virtual void CallBuild(Level &requestedLevel) const =0
ParameterList & disableRecursiveValidation()
void Release(const FactoryBase &factory)
Decrement the storage counter for all the inputs of a factory.
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
static void MultiplyRAP(const Matrix &R, bool transposeR, const Matrix &A, bool transposeA, const Matrix &P, bool transposeP, Matrix &Ac, bool call_FillComplete_on_result=true, bool doOptimizeStorage=true, const std::string &label=std::string(), const RCP< ParameterList > ¶ms=null)
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
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.
static void CheckRepairMainDiagonal(RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> &Ac, bool const &repairZeroDiagonals, Teuchos::FancyOStream &fos, const typename Teuchos::ScalarTraits< Scalar >::magnitudeType threshold=Teuchos::ScalarTraits< typename Teuchos::ScalarTraits< Scalar >::magnitudeType >::zero())
Print even more statistics.
bool isParameter(const std::string &name) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
bool isSublist(const std::string &name) const
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)
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
int GetLevelID() const
Return level number.
Exception throws to report errors in the internal logical of the program.
virtual std::string description() const
Return a simple one-line description of this object.
void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.