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"
12 #include "MueLu_GMRESSolver.hpp"
15 #include "MueLu_PatternFactory.hpp"
16 #include "MueLu_PerfUtils.hpp"
18 #include "MueLu_SteepestDescentSolver.hpp"
19 #include "MueLu_TentativePFactory.hpp"
23 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
27 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
34 rcp(
new validatorType(Teuchos::tuple<std::string>(
"cg",
"sd",
"gmres"),
"emin: iterative method")));
36 #undef SET_VALID_ENTRY
38 validParamList->
set<
RCP<const FactoryBase> >(
"A", Teuchos::null,
"Generating factory for the matrix A used during internal iterations");
42 validParamList->
set<
RCP<Matrix> > (
"P0", Teuchos::null,
"Initial guess at P");
43 validParamList->
set<
bool > (
"Keep P0",
false,
"Keep an initial P0 (for reuse)");
45 validParamList->
set<
RCP<Constraint> > (
"Constraint0", Teuchos::null,
"Initial Constraint");
46 validParamList->
set<
bool > (
"Keep Constraint0",
false,
"Keep an initial Constraint (for reuse)");
48 return validParamList;
51 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
53 Input(fineLevel,
"A");
55 static bool isAvailableP0 =
false;
56 static bool isAvailableConstraint0 =
false;
70 isAvailableP0 = coarseLevel.
IsAvailable(
"P0",
this);
71 isAvailableConstraint0 = coarseLevel.
IsAvailable(
"Constraint0",
this);
74 if (isAvailableP0 ==
false)
75 Input(coarseLevel,
"P");
77 if (isAvailableConstraint0 ==
false)
78 Input(coarseLevel,
"Constraint");
81 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
83 BuildP(fineLevel, coarseLevel);
86 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
95 if (restrictionMode_) {
107 numIts = pL.
get<
int>(
"emin: num reuse iterations");
108 GetOStream(
Runtime0) <<
"Reusing P0" << std::endl;
112 P0 = Get< RCP<Matrix> >(coarseLevel,
"P");
113 numIts = pL.
get<
int>(
"emin: num iterations");
121 if (coarseLevel.
IsAvailable(
"Constraint0",
this)) {
124 GetOStream(
Runtime0) <<
"Reusing Constraint0" << std::endl;
128 X = Get< RCP<Constraint> >(coarseLevel,
"Constraint");
130 GetOStream(
Runtime0) <<
"Number of emin iterations = " << numIts << std::endl;
132 std::string solverType = pL.
get<std::string>(
"emin: iterative method");
134 if (solverType ==
"cg")
136 else if (solverType ==
"sd")
138 else if (solverType ==
"gmres")
142 solver->Iterate(*A, *X, *P0, P);
145 if (!P->IsView(
"stridedMaps")) {
146 if (A->IsView(
"stridedMaps") ==
true) {
147 GetOStream(
Runtime1) <<
"Using A to fillComplete P" << std::endl;
153 std::vector<size_t> stridingInfo(1, 1);
156 P->CreateView(
"stridedMaps", A->getRowMap(
"stridedMaps"), dMap);
159 P->CreateView(
"stridedMaps", P->getRangeMap(), P->getDomainMap());
164 if (!restrictionMode_) {
166 Set(coarseLevel,
"P", P);
168 if (pL.
get<
bool>(
"Keep P0")) {
172 coarseLevel.
Keep(
"P0",
this);
173 Set(coarseLevel,
"P0", P);
175 if (pL.
get<
bool>(
"Keep Constraint0")) {
179 coarseLevel.
Keep(
"Constraint0",
this);
180 Set(coarseLevel,
"Constraint0", X);
185 params->
set(
"printLoadBalancingInfo",
true);
186 params->
set(
"printCommInfo",
true);
199 Set(coarseLevel,
"R", R);
203 params->
set(
"printLoadBalancingInfo",
true);
204 params->
set(
"printCommInfo",
true);
212 #endif // MUELU_EMINPFACTORY_DEF_HPP
void Keep(const std::string &ename, const FactoryBase *factory)
Request to keep variable 'ename' generated by 'factory' after the setup phase.
#define SET_VALID_ENTRY(name)
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 Build(Level &fineLevel, Level &coarseLevel) const
Build method.
void setValidator(RCP< const ParameterEntryValidator > const &validator)
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)
Implements conjugate gradient algorithm for energy-minimization.
void BuildP(Level &fineLevel, Level &coarseLevel) const
Abstract Build method.
Timer to be used in factories. Similar to Monitor but with additional timers.
One-liner description of what is happening.
RCP< const CrsGraph > GetPattern() const
Print even more statistics.
RequestMode GetRequestMode() const
Implements conjugate gradient algorithm for energy-minimization.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
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)
static std::string PrintMatrixInfo(const Matrix &A, const std::string &msgTag, RCP< const Teuchos::ParameterList > params=Teuchos::null)
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.
Implements steepest descent algorithm for energy-minimization.
Description of what is happening (more verbose)
ParameterEntry & getEntry(const std::string &name)
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.