46#ifndef MUELU_TOGGLEPFACTORY_DEF_HPP
47#define MUELU_TOGGLEPFACTORY_DEF_HPP
49#include <Xpetra_Matrix.hpp>
61 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
63 RCP<ParameterList> validParamList = rcp(
new ParameterList());
65#define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
70 return validParamList;
73 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
78 coarseLevel.
DeclareInput(
"RfromPfactory", (*it).get(),
this);
79 (*it)->CallDeclareInput(coarseLevel);
81 for (std::vector<RCP<const FactoryBase> >::const_iterator it =
ptentFacts_.begin(); it !=
ptentFacts_.end(); ++it) {
83 (*it)->CallDeclareInput(coarseLevel);
85 for (std::vector<RCP<const FactoryBase> >::const_iterator it =
nspFacts_.begin(); it !=
nspFacts_.end(); ++it) {
86 coarseLevel.
DeclareInput(
"Nullspace", (*it).get(),
this);
87 (*it)->CallDeclareInput(coarseLevel);
103 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
106 std::ostringstream levelstr;
110 TEUCHOS_TEST_FOR_EXCEPTION(
nspFacts_.size() != 2,
Exceptions::RuntimeError,
"MueLu::TogglePFactory::Build: TogglePFactory needs two different transfer operator strategies for toggling.");
113 int nProlongatorFactory = 0;
117 std::string mode = Teuchos::as<std::string>(pL.get<std::string>(
"toggle: mode"));
118 int semicoarsen_levels = Teuchos::as<int>(pL.get<
int>(
"semicoarsen: number of levels"));
120 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.");
125 GetOStream(
Runtime1) <<
"Number of layers for semicoarsening: " << NumZDir << std::endl;
129 if(fineLevel.
GetLevelID() >= semicoarsen_levels || NumZDir == 1) {
130 nProlongatorFactory = 1;
132 nProlongatorFactory = 0;
135 RCP<Matrix> P = Teuchos::null;
136 RCP<Matrix> Ptent = Teuchos::null;
137 RCP<MultiVector> coarseNullspace = Teuchos::null;
143 RCP<Matrix> R = Teuchos::null;
144 int Rplaceholder = -1;
150 if (strType ==
"int") Rplaceholder = nProlongatorFactory;
151 else 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) {
167 Set(coarseLevel,
"P", P);
172 if (R != Teuchos::null)
Set(coarseLevel,
"RfromPfactory", R);
173 else if (Rplaceholder != -1)
Set(coarseLevel,
"RfromPfactory", Teuchos::as<int>(Rplaceholder));
174 Set(coarseLevel,
"Nullspace", coarseNullspace);
175 Set(coarseLevel,
"Ptent", Ptent);
176 Set(coarseLevel,
"Chosen P", nProlongatorFactory);
179 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
182 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::rcp_dynamic_cast<const TwoLevelFactoryBase>(factory) == Teuchos::null,
Exceptions::BadCast,
183 "MueLu::TogglePFactory::AddProlongatorFactory: Transfer factory is not derived from TwoLevelFactoryBase. "
184 "This is very strange. (Note: you can remove this exception if there's a good reason for)");
189 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
192 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::rcp_dynamic_cast<const TwoLevelFactoryBase>(factory) == Teuchos::null,
Exceptions::BadCast,
193 "MueLu::TogglePFactory::AddPtentFactory: Transfer factory is not derived from TwoLevelFactoryBase. "
194 "This is very strange. (Note: you can remove this exception if there's a good reason for)");
199 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
202 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::rcp_dynamic_cast<const TwoLevelFactoryBase>(factory) == Teuchos::null,
Exceptions::BadCast,
203 "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."
204 "This is very strange. (Note: you can remove this exception if there's a good reason for)");
#define SET_VALID_ENTRY(name)
virtual std::string description() const
Return a simple one-line description of this object.
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.
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.
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()
virtual const Teuchos::ParameterList & GetParameterList() const
std::vector< RCP< const FactoryBase > > ptentFacts_
list of user-defined tentative prolongation operator factories
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.
std::vector< RCP< const FactoryBase > > prolongatorFacts_
list of user-defined prolongation operator factories
std::vector< RCP< const FactoryBase > > nspFacts_
list of user-defined nullspace factories (i.e. the prolongator factories which also generate the coar...
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.
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
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)