46 #ifndef MUELU_TOGGLEPFACTORY_DEF_HPP
47 #define MUELU_TOGGLEPFACTORY_DEF_HPP
59 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
63 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
66 #undef SET_VALID_ENTRY
68 return validParamList;
71 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
74 for (std::vector<
RCP<const FactoryBase> >::const_iterator it = prolongatorFacts_.begin(); it != prolongatorFacts_.end(); ++it) {
76 coarseLevel.
DeclareInput(
"RfromPfactory", (*it).get(),
this);
77 (*it)->CallDeclareInput(coarseLevel);
79 for (std::vector<
RCP<const FactoryBase> >::const_iterator it = ptentFacts_.begin(); it != ptentFacts_.end(); ++it) {
81 (*it)->CallDeclareInput(coarseLevel);
83 for (std::vector<
RCP<const FactoryBase> >::const_iterator it = nspFacts_.begin(); it != nspFacts_.end(); ++it) {
84 coarseLevel.
DeclareInput(
"Nullspace", (*it).get(),
this);
85 (*it)->CallDeclareInput(coarseLevel);
98 hasDeclaredInput_ =
true;
101 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
104 std::ostringstream levelstr;
111 int nProlongatorFactory = 0;
115 std::string mode = Teuchos::as<std::string>(pL.
get<std::string>(
"toggle: mode"));
116 int semicoarsen_levels = Teuchos::as<int>(pL.
get<
int>(
"semicoarsen: number of levels"));
123 GetOStream(
Runtime1) <<
"Number of layers for semicoarsening: " << NumZDir << std::endl;
127 if (fineLevel.
GetLevelID() >= semicoarsen_levels || NumZDir == 1) {
128 nProlongatorFactory = 1;
130 nProlongatorFactory = 0;
138 GetOStream(
Runtime0) <<
"TogglePFactory: call transfer factory: " << (prolongatorFacts_[nProlongatorFactory])->description() << std::endl;
139 prolongatorFacts_[nProlongatorFactory]->CallBuild(coarseLevel);
140 P = coarseLevel.
Get<
RCP<Matrix> >(
"P", (prolongatorFacts_[nProlongatorFactory]).
get());
142 int Rplaceholder = -1;
146 if (coarseLevel.
IsAvailable(
"RfromPfactory", (prolongatorFacts_[nProlongatorFactory]).get())) {
147 std::string strType = coarseLevel.
GetTypeName(
"RfromPfactory", (prolongatorFacts_[nProlongatorFactory]).
get());
148 if (strType ==
"int")
149 Rplaceholder = nProlongatorFactory;
151 R = coarseLevel.
Get<
RCP<Matrix> >(
"RfromPfactory", (prolongatorFacts_[nProlongatorFactory]).
get());
156 Ptent = coarseLevel.
Get<
RCP<Matrix> >(
"P", (ptentFacts_[nProlongatorFactory]).
get());
157 coarseNullspace = coarseLevel.
Get<
RCP<MultiVector> >(
"Nullspace", (nspFacts_[nProlongatorFactory]).
get());
160 for (
size_t t = 0; t < nspFacts_.size(); ++t) {
161 coarseLevel.
Release(*(prolongatorFacts_[t]));
162 coarseLevel.
Release(*(ptentFacts_[t]));
163 coarseLevel.
Release(*(nspFacts_[t]));
167 Set(coarseLevel,
"P", P);
172 if (R != Teuchos::null)
173 Set(coarseLevel,
"RfromPfactory", R);
174 else if (Rplaceholder != -1)
175 Set(coarseLevel,
"RfromPfactory", Teuchos::as<int>(Rplaceholder));
176 Set(coarseLevel,
"Nullspace", coarseNullspace);
177 Set(coarseLevel,
"Ptent", Ptent);
178 Set(coarseLevel,
"Chosen P", nProlongatorFactory);
181 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
185 "MueLu::TogglePFactory::AddProlongatorFactory: Transfer factory is not derived from TwoLevelFactoryBase. "
186 "This is very strange. (Note: you can remove this exception if there's a good reason for)");
188 prolongatorFacts_.push_back(factory);
191 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
195 "MueLu::TogglePFactory::AddPtentFactory: Transfer factory is not derived from TwoLevelFactoryBase. "
196 "This is very strange. (Note: you can remove this exception if there's a good reason for)");
198 ptentFacts_.push_back(factory);
201 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
205 "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."
206 "This is very strange. (Note: you can remove this exception if there's a good reason for)");
208 nspFacts_.push_back(factory);
213 #endif // MUELU_TOGGLEPFACTORY_DEF_HPP
Exception indicating invalid cast attempted.
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 Release(const FactoryBase &factory)
Decrement the storage counter for all the inputs of a factory.
T & get(const std::string &name, T def_value)
void AddProlongatorFactory(const RCP< const FactoryBase > &factory)
Add a prolongator factory in the end of list of prolongator factories.
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
User data are always kept. This flag is set automatically when Level::Set("data", data) is used...
One-liner description of what is happening.
static const NoFactory * get()
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
std::string GetTypeName(const std::string &ename, const FactoryBase *factory=NoFactory::get())
GetTypeName returns type string of variable stored using ename and factory.
void RemoveKeepFlag(const std::string &ename, const FactoryBase *factory, KeepType keep=MueLu::All)
int GetLevelID() const
Return level number.
Exception throws to report errors in the internal logical of the program.
Description of what is happening (more verbose)
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.
void AddPtentFactory(const RCP< const FactoryBase > &factory)
Add a tentative prolongator factory in the end of list of prolongator factories.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
#define SET_VALID_ENTRY(name)
void AddCoarseNullspaceFactory(const RCP< const FactoryBase > &factory)
Add a coarse nullspace factory in the end of list of coarse nullspace factories.
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.