10#ifndef MUELU_TOGGLEPFACTORY_DEF_HPP
11#define MUELU_TOGGLEPFACTORY_DEF_HPP
13#include <Xpetra_Matrix.hpp>
23template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
25 RCP<ParameterList> validParamList = rcp(
new ParameterList());
27#define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
32 return validParamList;
35template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
38 for (std::vector<RCP<const FactoryBase> >::const_iterator it = prolongatorFacts_.begin(); it != prolongatorFacts_.end(); ++it) {
40 coarseLevel.
DeclareInput(
"RfromPfactory", (*it).get(),
this);
41 (*it)->CallDeclareInput(coarseLevel);
43 for (std::vector<RCP<const FactoryBase> >::const_iterator it = ptentFacts_.begin(); it != ptentFacts_.end(); ++it) {
45 (*it)->CallDeclareInput(coarseLevel);
47 for (std::vector<RCP<const FactoryBase> >::const_iterator it = nspFacts_.begin(); it != nspFacts_.end(); ++it) {
48 coarseLevel.
DeclareInput(
"Nullspace", (*it).get(),
this);
49 (*it)->CallDeclareInput(coarseLevel);
62 hasDeclaredInput_ =
true;
65template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
68 std::ostringstream levelstr;
71 TEUCHOS_TEST_FOR_EXCEPTION(nspFacts_.size() != prolongatorFacts_.size(),
Exceptions::RuntimeError,
"MueLu::TogglePFactory::Build: The number of provided prolongator factories and coarse nullspace factories must be identical.");
72 TEUCHOS_TEST_FOR_EXCEPTION(nspFacts_.size() != 2,
Exceptions::RuntimeError,
"MueLu::TogglePFactory::Build: TogglePFactory needs two different transfer operator strategies for toggling.");
75 int nProlongatorFactory = 0;
78 const Teuchos::ParameterList& pL = GetParameterList();
79 std::string mode = Teuchos::as<std::string>(pL.get<std::string>(
"toggle: mode"));
80 int semicoarsen_levels = Teuchos::as<int>(pL.get<
int>(
"semicoarsen: number of levels"));
82 TEUCHOS_TEST_FOR_EXCEPTION(mode !=
"semicoarsen",
Exceptions::RuntimeError,
"MueLu::TogglePFactory::Build: The 'toggle: mode' parameter must be set to 'semicoarsen'. No other mode supported, yet.");
87 GetOStream(
Runtime1) <<
"Number of layers for semicoarsening: " << NumZDir << std::endl;
91 if (fineLevel.
GetLevelID() >= semicoarsen_levels || NumZDir == 1) {
92 nProlongatorFactory = 1;
94 nProlongatorFactory = 0;
97 RCP<Matrix> P = Teuchos::null;
98 RCP<Matrix> Ptent = Teuchos::null;
99 RCP<MultiVector> coarseNullspace = Teuchos::null;
102 GetOStream(
Runtime0) <<
"TogglePFactory: call transfer factory: " << (prolongatorFacts_[nProlongatorFactory])->description() << std::endl;
103 prolongatorFacts_[nProlongatorFactory]->CallBuild(coarseLevel);
104 P = coarseLevel.
Get<RCP<Matrix> >(
"P", (prolongatorFacts_[nProlongatorFactory]).get());
105 RCP<Matrix> R = Teuchos::null;
106 int Rplaceholder = -1;
110 if (coarseLevel.
IsAvailable(
"RfromPfactory", (prolongatorFacts_[nProlongatorFactory]).get())) {
111 std::string strType = coarseLevel.
GetTypeName(
"RfromPfactory", (prolongatorFacts_[nProlongatorFactory]).get());
112 if (strType ==
"int")
113 Rplaceholder = nProlongatorFactory;
115 R = coarseLevel.
Get<RCP<Matrix> >(
"RfromPfactory", (prolongatorFacts_[nProlongatorFactory]).get());
120 Ptent = coarseLevel.
Get<RCP<Matrix> >(
"P", (ptentFacts_[nProlongatorFactory]).get());
121 coarseNullspace = coarseLevel.
Get<RCP<MultiVector> >(
"Nullspace", (nspFacts_[nProlongatorFactory]).get());
124 for (
size_t t = 0; t < nspFacts_.size(); ++t) {
125 coarseLevel.
Release(*(prolongatorFacts_[t]));
126 coarseLevel.
Release(*(ptentFacts_[t]));
127 coarseLevel.
Release(*(nspFacts_[t]));
131 Set(coarseLevel,
"P", P);
136 if (R != Teuchos::null)
137 Set(coarseLevel,
"RfromPfactory", R);
138 else if (Rplaceholder != -1)
139 Set(coarseLevel,
"RfromPfactory", Teuchos::as<int>(Rplaceholder));
140 Set(coarseLevel,
"Nullspace", coarseNullspace);
141 Set(coarseLevel,
"Ptent", Ptent);
142 Set(coarseLevel,
"Chosen P", nProlongatorFactory);
145template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
148 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::rcp_dynamic_cast<const TwoLevelFactoryBase>(factory) == Teuchos::null,
Exceptions::BadCast,
149 "MueLu::TogglePFactory::AddProlongatorFactory: Transfer factory is not derived from TwoLevelFactoryBase. "
150 "This is very strange. (Note: you can remove this exception if there's a good reason for)");
151 TEUCHOS_TEST_FOR_EXCEPTION(hasDeclaredInput_,
Exceptions::RuntimeError,
"MueLu::TogglePFactory::AddProlongatorFactory: Factory is being added after we have already declared input");
152 prolongatorFacts_.push_back(factory);
155template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
158 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::rcp_dynamic_cast<const TwoLevelFactoryBase>(factory) == Teuchos::null,
Exceptions::BadCast,
159 "MueLu::TogglePFactory::AddPtentFactory: Transfer factory is not derived from TwoLevelFactoryBase. "
160 "This is very strange. (Note: you can remove this exception if there's a good reason for)");
161 TEUCHOS_TEST_FOR_EXCEPTION(hasDeclaredInput_,
Exceptions::RuntimeError,
"MueLu::TogglePFactory::AddPtentFactory: Factory is being added after we have already declared input");
162 ptentFacts_.push_back(factory);
165template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
168 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::rcp_dynamic_cast<const TwoLevelFactoryBase>(factory) == Teuchos::null,
Exceptions::BadCast,
169 "MueLu::TogglePFactory::AddCoarseNullspaceFactory: Transfer factory is not derived from TwoLevelFactoryBase. Make sure you provide the factory which generates the coarse level nullspace information. Usually this is a prolongator factory."
170 "This is very strange. (Note: you can remove this exception if there's a good reason for)");
171 TEUCHOS_TEST_FOR_EXCEPTION(hasDeclaredInput_,
Exceptions::RuntimeError,
"MueLu::TogglePFactory::AddCoarseNullspaceFactory: Factory is being added after we have already declared input");
172 nspFacts_.push_back(factory);
#define SET_VALID_ENTRY(name)
Exception indicating invalid cast attempted.
Exception throws to report errors in the internal logical of the program.
Timer to be used in factories. Similar to Monitor but with additional timers.
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.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
void Release(const FactoryBase &factory)
Decrement the storage counter for all the inputs of a factory.
void RemoveKeepFlag(const std::string &ename, const FactoryBase *factory, KeepType keep=MueLu::All)
int GetLevelID() const
Return level number.
std::string GetTypeName(const std::string &ename, const FactoryBase *factory=NoFactory::get())
GetTypeName returns type string of variable stored using ename and factory.
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access)....
static const NoFactory * get()
void AddCoarseNullspaceFactory(const RCP< const FactoryBase > &factory)
Add a coarse nullspace factory in the end of list of coarse nullspace factories.
void AddProlongatorFactory(const RCP< const FactoryBase > &factory)
Add a prolongator factory in the end of list of prolongator factories.
void AddPtentFactory(const RCP< const FactoryBase > &factory)
Add a tentative prolongator factory in the end of list of prolongator factories.
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
void Build(Level &fineLevel, Level &coarseLevel) const
Build method.
Namespace for MueLu classes and methods.
@ UserData
User data are always kept. This flag is set automatically when Level::Set("data", data) is used....
@ Runtime0
One-liner description of what is happening.
@ Runtime1
Description of what is happening (more verbose)