1#ifndef MUELU_EMINPFACTORY_DEF_HPP
2#define MUELU_EMINPFACTORY_DEF_HPP
4#include <Xpetra_Matrix.hpp>
5#include <Xpetra_StridedMapFactory.hpp>
9#include "MueLu_CGSolver.hpp"
10#include "MueLu_Constraint.hpp"
11#include "MueLu_GMRESSolver.hpp"
14#include "MueLu_PerfUtils.hpp"
16#include "MueLu_SteepestDescentSolver.hpp"
20 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
22 RCP<ParameterList> validParamList = rcp(
new ParameterList());
24#define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
29 typedef Teuchos::StringToIntegralParameterEntryValidator<int> validatorType;
30 validParamList->getEntry(
"emin: iterative method").setValidator(
31 rcp(
new validatorType(Teuchos::tuple<std::string>(
"cg",
"sd",
"gmres"),
"emin: iterative method")));
35 validParamList->set< RCP<const FactoryBase> >(
"A", Teuchos::null,
"Generating factory for the matrix A used during internal iterations");
36 validParamList->set< RCP<const FactoryBase> >(
"P", Teuchos::null,
"Generating factory for the initial guess");
37 validParamList->set< RCP<const FactoryBase> >(
"Constraint", Teuchos::null,
"Generating factory for constraints");
39 validParamList->set< RCP<Matrix> > (
"P0", Teuchos::null,
"Initial guess at P");
40 validParamList->set<
bool > (
"Keep P0",
false,
"Keep an initial P0 (for reuse)");
42 validParamList->set< RCP<Constraint> > (
"Constraint0", Teuchos::null,
"Initial Constraint");
43 validParamList->set<
bool > (
"Keep Constraint0",
false,
"Keep an initial Constraint (for reuse)");
45 return validParamList;
48 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
50 Input(fineLevel,
"A");
52 static bool isAvailableP0 =
false;
53 static bool isAvailableConstraint0 =
false;
67 isAvailableP0 = coarseLevel.
IsAvailable(
"P0",
this);
68 isAvailableConstraint0 = coarseLevel.
IsAvailable(
"Constraint0",
this);
71 if (isAvailableP0 ==
false)
72 Input(coarseLevel,
"P");
74 if (isAvailableConstraint0 ==
false)
75 Input(coarseLevel,
"Constraint");
78 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
80 BuildP(fineLevel, coarseLevel);
83 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
103 P0 = coarseLevel.
Get<RCP<Matrix> >(
"P0",
this);
104 numIts = pL.get<
int>(
"emin: num reuse iterations");
110 numIts = pL.get<
int>(
"emin: num iterations");
118 if (coarseLevel.
IsAvailable(
"Constraint0",
this)) {
120 X = coarseLevel.
Get<RCP<Constraint> >(
"Constraint0",
this);
129 std::string solverType = pL.get<std::string>(
"emin: iterative method");
130 RCP<SolverBase> solver;
131 if (solverType ==
"cg")
133 else if (solverType ==
"sd")
135 else if (solverType ==
"gmres")
139 solver->Iterate(*A, *X, *P0, P);
142 if (!P->IsView(
"stridedMaps")) {
143 if (A->IsView(
"stridedMaps") ==
true) {
150 std::vector<size_t> stridingInfo(1, 1);
151 RCP<const StridedMap> dMap = StridedMapFactory::Build(X->GetPattern()->getDomainMap(), stridingInfo);
153 P->CreateView(
"stridedMaps", A->getRowMap(
"stridedMaps"), dMap);
156 P->CreateView(
"stridedMaps", P->getRangeMap(), P->getDomainMap());
163 Set(coarseLevel,
"P", P);
165 if (pL.get<
bool>(
"Keep P0")) {
169 coarseLevel.
Keep(
"P0",
this);
170 Set(coarseLevel,
"P0", P);
172 if (pL.get<
bool>(
"Keep Constraint0")) {
176 coarseLevel.
Keep(
"Constraint0",
this);
177 Set(coarseLevel,
"Constraint0", X);
181 RCP<ParameterList> params = rcp(
new ParameterList());
182 params->set(
"printLoadBalancingInfo",
true);
183 params->set(
"printCommInfo",
true);
196 Set(coarseLevel,
"R", R);
199 RCP<ParameterList> params = rcp(
new ParameterList());
200 params->set(
"printLoadBalancingInfo",
true);
201 params->set(
"printCommInfo",
true);
#define SET_VALID_ENTRY(name)
void Build(Level &fineLevel, Level &coarseLevel) const
Build method.
void BuildP(Level &fineLevel, Level &coarseLevel) const
Abstract Build method.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
MueLu::SteepestDescentSolver< Scalar, LocalOrdinal, GlobalOrdinal, Node > SteepestDescentSolver
MueLu::GMRESSolver< Scalar, LocalOrdinal, GlobalOrdinal, Node > GMRESSolver
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.
MueLu::CGSolver< Scalar, LocalOrdinal, GlobalOrdinal, Node > CGSolver
Timer to be used in factories. Similar to Monitor but with additional timers.
void Input(Level &level, const std::string &varName) const
T Get(Level &level, const std::string &varName) const
void Set(Level &level, const std::string &varName, const T &data) const
Class that holds all level-specific information.
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access)....
RequestMode GetRequestMode() const
void Keep(const std::string &ename, const FactoryBase *factory)
Request to keep variable 'ename' generated by 'factory' after the setup phase.
virtual const Teuchos::ParameterList & GetParameterList() const
static std::string PrintMatrixInfo(const Matrix &A, const std::string &msgTag, RCP< const Teuchos::ParameterList > params=Teuchos::null)
Timer to be used in factories. Similar to SubMonitor but adds a timer level by level.
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)
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
bool IsPrint(MsgType type, int thisProcRankOnly=-1) const
Find out whether we need to print out information for a specific message type.
Namespace for MueLu classes and methods.
@ Statistics2
Print even more statistics.
@ Runtime0
One-liner description of what is happening.
@ Runtime1
Description of what is happening (more verbose).