46 #ifndef MUELU_SAPFACTORY_DEF_HPP 47 #define MUELU_SAPFACTORY_DEF_HPP 49 #include <Xpetra_Matrix.hpp> 50 #include <Xpetra_IteratorOps.hpp> 59 #include "MueLu_PerfUtils.hpp" 61 #include "MueLu_TentativePFactory.hpp" 62 #include "MueLu_Utilities.hpp" 66 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
68 RCP<ParameterList> validParamList = rcp(
new ParameterList());
70 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name)) 74 #undef SET_VALID_ENTRY 76 validParamList->set< RCP<const FactoryBase> >(
"A", Teuchos::null,
"Generating factory of the matrix A used during the prolongator smoothing process");
77 validParamList->set< RCP<const FactoryBase> >(
"P", Teuchos::null,
"Tentative prolongator factory");
79 return validParamList;
82 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
84 Input(fineLevel,
"A");
88 RCP<const FactoryBase> initialPFact = GetFactory(
"P");
89 if (initialPFact == Teuchos::null) { initialPFact = coarseLevel.
GetFactoryManager()->GetFactory(
"Ptent"); }
93 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
95 return BuildP(fineLevel, coarseLevel);
98 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
101 std::ostringstream levelstr;
104 typedef typename Teuchos::ScalarTraits<SC>::magnitudeType Magnitude;
109 RCP<const FactoryBase> initialPFact = GetFactory(
"P");
110 if (initialPFact == Teuchos::null) { initialPFact = coarseLevel.
GetFactoryManager()->GetFactory(
"Ptent"); }
113 RCP<Matrix> A = Get< RCP<Matrix> >(fineLevel,
"A");
114 RCP<Matrix> Ptent = coarseLevel.
Get< RCP<Matrix> >(
"P", initialPFact.get());
116 if(restrictionMode_) {
124 const ParameterList & pL = GetParameterList();
125 Scalar dampingFactor = as<Scalar>(pL.get<
double>(
"sa: damping factor"));
126 LO maxEigenIterations = as<LO>(pL.get<
int>(
"sa: eigenvalue estimate num iterations"));
127 bool estimateMaxEigen = pL.get<
bool>(
"sa: calculate eigenvalue estimate");
128 if (dampingFactor != Teuchos::ScalarTraits<Scalar>::zero()) {
133 lambdaMax = A->GetMaxEigenvalueEstimate();
134 if (lambdaMax == -Teuchos::ScalarTraits<SC>::one() || estimateMaxEigen) {
135 GetOStream(
Statistics1) <<
"Calculating max eigenvalue estimate now (max iters = "<< maxEigenIterations <<
")" << std::endl;
136 Magnitude stopTol = 1e-4;
138 A->SetMaxEigenvalueEstimate(lambdaMax);
140 GetOStream(
Statistics1) <<
"Using cached max eigenvalue estimate" << std::endl;
142 GetOStream(
Statistics0) <<
"Prolongator damping factor = " << dampingFactor/lambdaMax <<
" (" << dampingFactor <<
" / " << lambdaMax <<
")" << std::endl;
149 SC omega = dampingFactor / lambdaMax;
152 finalP = Xpetra::IteratorOps<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Jacobi(omega, *invDiag, *A, *Ptent, finalP, GetOStream(
Statistics2),std::string(
"MueLu::SaP-")+levelstr.str());
160 if (!restrictionMode_) {
162 Set(coarseLevel,
"P", finalP);
165 if (Ptent->IsView(
"stridedMaps"))
166 finalP->CreateView(
"stridedMaps", Ptent);
171 Set(coarseLevel,
"R", R);
174 if (Ptent->IsView(
"stridedMaps"))
175 R->CreateView(
"stridedMaps", Ptent,
true);
179 RCP<ParameterList> params = rcp(
new ParameterList());
180 params->set(
"printLoadBalancingInfo",
true);
181 params->set(
"printCommInfo",
true);
189 #endif // MUELU_SAPFACTORY_DEF_HPP 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.
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())
Timer to be used in factories. Similar to Monitor but with additional timers.
Namespace for MueLu classes and methods.
static RCP< Xpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > GetMatrixDiagonalInverse(const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, Magnitude tol=Teuchos::ScalarTraits< Scalar >::eps()*100)
Print even more statistics.
Print statistics that do not involve significant additional computation.
Class that holds all level-specific information.
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.
#define SET_VALID_ENTRY(name)
static std::string PrintMatrixInfo(const Matrix &A, const std::string &msgTag, RCP< const Teuchos::ParameterList > params=Teuchos::null)
void BuildP(Level &fineLevel, Level &coarseLevel) const
Abstract Build method.
const RCP< const FactoryManagerBase > GetFactoryManager()
returns the current factory manager
int GetLevelID() const
Return level number.
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.
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.
static Scalar PowerMethod(const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, bool scaleByDiag=true, LocalOrdinal niters=10, Magnitude tolerance=1e-2, bool verbose=false, unsigned int seed=123)