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))
68 #undef SET_VALID_ENTRY
70 return validParamList;
73 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
76 for (std::vector<RCP<const FactoryBase> >::const_iterator it = prolongatorFacts_.begin(); it != prolongatorFacts_.end(); ++it) {
78 (*it)->CallDeclareInput(coarseLevel);
80 for (std::vector<RCP<const FactoryBase> >::const_iterator it = ptentFacts_.begin(); it != ptentFacts_.end(); ++it) {
82 (*it)->CallDeclareInput(coarseLevel);
84 for (std::vector<RCP<const FactoryBase> >::const_iterator it = nspFacts_.begin(); it != nspFacts_.end(); ++it) {
85 coarseLevel.
DeclareInput(
"Nullspace", (*it).get(),
this);
86 (*it)->CallDeclareInput(coarseLevel);
99 hasDeclaredInput_ =
true;
102 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
105 std::ostringstream levelstr;
108 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.");
109 TEUCHOS_TEST_FOR_EXCEPTION(nspFacts_.size() != 2,
Exceptions::RuntimeError,
"MueLu::TogglePFactory::Build: TogglePFactory needs two different transfer operator strategies for toggling.");
112 int nProlongatorFactory = 0;
115 const Teuchos::ParameterList & pL = GetParameterList();
116 std::string mode = Teuchos::as<std::string>(pL.get<std::string>(
"toggle: mode"));
117 int semicoarsen_levels = Teuchos::as<int>(pL.get<
int>(
"semicoarsen: number of levels"));
119 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.");
124 GetOStream(
Runtime1) <<
"Number of layers for semicoarsening: " << NumZDir << std::endl;
128 if(fineLevel.
GetLevelID() >= semicoarsen_levels || NumZDir == 1) {
129 nProlongatorFactory = 1;
131 nProlongatorFactory = 0;
134 RCP<Matrix> P = Teuchos::null;
135 RCP<Matrix> Ptent = Teuchos::null;
136 RCP<MultiVector> coarseNullspace = Teuchos::null;
139 GetOStream(
Runtime0) <<
"TogglePFactory: call transfer factory: " << (prolongatorFacts_[nProlongatorFactory])->description() << std::endl;
140 prolongatorFacts_[nProlongatorFactory]->CallBuild(coarseLevel);
141 P = coarseLevel.
Get< RCP<Matrix> >(
"P", (prolongatorFacts_[nProlongatorFactory]).get());
144 Ptent = coarseLevel.
Get< RCP<Matrix> >(
"P", (ptentFacts_[nProlongatorFactory]).get());
145 coarseNullspace = coarseLevel.
Get< RCP<MultiVector> >(
"Nullspace", (nspFacts_[nProlongatorFactory]).get());
148 for(
size_t t=0; t<nspFacts_.size(); ++t) {
149 coarseLevel.
Release(*(prolongatorFacts_[t]));
150 coarseLevel.
Release(*(ptentFacts_[t]));
151 coarseLevel.
Release(*(nspFacts_[t]));
155 Set(coarseLevel,
"P", P);
156 Set(coarseLevel,
"Nullspace", coarseNullspace);
157 Set(coarseLevel,
"Ptent", Ptent);
158 Set(coarseLevel,
"Chosen P", nProlongatorFactory);
161 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
164 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::rcp_dynamic_cast<const TwoLevelFactoryBase>(factory) == Teuchos::null,
Exceptions::BadCast,
165 "MueLu::TogglePFactory::AddProlongatorFactory: Transfer factory is not derived from TwoLevelFactoryBase. "
166 "This is very strange. (Note: you can remove this exception if there's a good reason for)");
167 TEUCHOS_TEST_FOR_EXCEPTION(hasDeclaredInput_,
Exceptions::RuntimeError,
"MueLu::TogglePFactory::AddProlongatorFactory: Factory is being added after we have already declared input");
168 prolongatorFacts_.push_back(factory);
171 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
174 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::rcp_dynamic_cast<const TwoLevelFactoryBase>(factory) == Teuchos::null,
Exceptions::BadCast,
175 "MueLu::TogglePFactory::AddPtentFactory: Transfer factory is not derived from TwoLevelFactoryBase. "
176 "This is very strange. (Note: you can remove this exception if there's a good reason for)");
177 TEUCHOS_TEST_FOR_EXCEPTION(hasDeclaredInput_,
Exceptions::RuntimeError,
"MueLu::TogglePFactory::AddPtentFactory: Factory is being added after we have already declared input");
178 ptentFacts_.push_back(factory);
181 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
184 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::rcp_dynamic_cast<const TwoLevelFactoryBase>(factory) == Teuchos::null,
Exceptions::BadCast,
185 "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."
186 "This is very strange. (Note: you can remove this exception if there's a good reason for)");
187 TEUCHOS_TEST_FOR_EXCEPTION(hasDeclaredInput_,
Exceptions::RuntimeError,
"MueLu::TogglePFactory::AddCoarseNullspaceFactory: Factory is being added after we have already declared input");
188 nspFacts_.push_back(factory);
194 #endif // MUELU_TOGGLEPFACTORY_DEF_HPP