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" 14 #include "MueLu_PatternFactory.hpp" 15 #include "MueLu_PerfUtils.hpp" 17 #include "MueLu_SteepestDescentSolver.hpp" 18 #include "MueLu_TentativePFactory.hpp" 22 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
24 RCP<ParameterList> validParamList = rcp(
new ParameterList());
26 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name)) 31 typedef Teuchos::StringToIntegralParameterEntryValidator<int> validatorType;
32 validParamList->getEntry(
"emin: iterative method").setValidator(
33 rcp(
new validatorType(Teuchos::tuple<std::string>(
"cg",
"sd"),
"emin: iterative method")));
35 #undef SET_VALID_ENTRY 37 validParamList->set< RCP<const FactoryBase> >(
"A", Teuchos::null,
"Generating factory for the matrix A used during internal iterations");
38 validParamList->set< RCP<const FactoryBase> >(
"P", Teuchos::null,
"Generating factory for the initial guess");
39 validParamList->set< RCP<const FactoryBase> >(
"Constraint", Teuchos::null,
"Generating factory for constraints");
41 validParamList->set< RCP<Matrix> > (
"P0", Teuchos::null,
"Initial guess at P");
42 validParamList->set<
bool > (
"Keep P0",
false,
"Keep an initial P0 (for reuse)");
44 validParamList->set< RCP<Constraint> > (
"Constraint0", Teuchos::null,
"Initial Constraint");
45 validParamList->set<
bool > (
"Keep Constraint0",
false,
"Keep an initial Constraint (for reuse)");
47 return validParamList;
50 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
52 Input(fineLevel,
"A");
54 static bool isAvailableP0 =
false;
55 static bool isAvailableConstraint0 =
false;
69 isAvailableP0 = coarseLevel.
IsAvailable(
"P0",
this);
70 isAvailableConstraint0 = coarseLevel.
IsAvailable(
"Constraint0",
this);
73 if (isAvailableP0 ==
false)
74 Input(coarseLevel,
"P");
76 if (isAvailableConstraint0 ==
false)
77 Input(coarseLevel,
"Constraint");
80 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
82 BuildP(fineLevel, coarseLevel);
85 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
89 const ParameterList& pL = GetParameterList();
92 RCP<Matrix> A = Get< RCP<Matrix> >(fineLevel,
"A");
99 P0 = coarseLevel.
Get<RCP<Matrix> >(
"P0",
this);
100 numIts = pL.get<
int>(
"emin: num reuse iterations");
101 GetOStream(
Runtime0) <<
"Reusing P0" << std::endl;
105 P0 = Get< RCP<Matrix> >(coarseLevel,
"P");
106 numIts = pL.get<
int>(
"emin: num iterations");
114 if (coarseLevel.
IsAvailable(
"Constraint0",
this)) {
116 X = coarseLevel.
Get<RCP<Constraint> >(
"Constraint0",
this);
117 GetOStream(
Runtime0) <<
"Reusing Constraint0" << std::endl;
121 X = Get< RCP<Constraint> >(coarseLevel,
"Constraint");
123 GetOStream(
Runtime0) <<
"Number of emin iterations = " << numIts << std::endl;
126 std::string solverType = pL.get<std::string>(
"emin: iterative method");
127 RCP<SolverBase> solver;
128 if (solverType ==
"cg")
130 else if (solverType ==
"sd")
134 solver->Iterate(*A, *X, *P0, P);
137 if (!P->IsView(
"stridedMaps")) {
138 if (A->IsView(
"stridedMaps") ==
true) {
139 GetOStream(
Runtime1) <<
"Using A to fillComplete P" << std::endl;
145 std::vector<size_t> stridingInfo(1, 1);
146 RCP<const StridedMap> dMap = StridedMapFactory::Build(X->GetPattern()->getDomainMap(), stridingInfo);
148 P->CreateView(
"stridedMaps", A->getRowMap(
"stridedMaps"), dMap);
151 P->CreateView(
"stridedMaps", P->getRangeMap(), P->getDomainMap());
155 Set(coarseLevel,
"P", P);
156 if (pL.get<
bool>(
"Keep P0")) {
160 coarseLevel.
Keep(
"P0",
this);
161 Set(coarseLevel,
"P0", P);
163 if (pL.get<
bool>(
"Keep Constraint0")) {
167 coarseLevel.
Keep(
"Constraint0",
this);
168 Set(coarseLevel,
"Constraint0", X);
172 RCP<ParameterList> params = rcp(
new ParameterList());
173 params->set(
"printLoadBalancingInfo",
true);
174 params->set(
"printCommInfo",
true);
181 #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.
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.
Namespace for MueLu classes and methods.
RequestMode GetRequestMode() const
Class that holds all level-specific information.
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)
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.